Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set fallback
# Lint GitHub Actions workflows.
check:
python3 {{ source_directory() }}/scripts/install-formula.test.py
{{ source_directory() }}/scripts/release.test.sh
@if command -v nfpm >/dev/null 2>&1 && command -v envsubst >/dev/null 2>&1 && command -v dpkg-deb >/dev/null 2>&1 && command -v rpm >/dev/null 2>&1; then python3 {{ source_directory() }}/../rs/scripts/package-rename.test.py; fi
@if command -v actionlint >/dev/null 2>&1; then actionlint; fi
{{ source_directory() }}/scripts/alert.sh check-coverage
Expand Down
146 changes: 30 additions & 116 deletions .github/scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# release.sh read-version <pyproject.toml> — read `version = "x.y.z"` from a manifest
# release.sh pypi-exists <dist> <version> — check whether <dist>==<version> is already on PyPI
# release.sh maven-exists <group> <artifact> <version>
# release.sh maven-version-in-range <group> <artifact> <range>
# release.sh ffi-unreleased <version>
#
# Environment:
# GITHUB_REF — set by GitHub Actions (e.g. refs/tags/moq-relay-v1.2.3)
Expand Down Expand Up @@ -207,39 +207,17 @@ pypi_exists() {
echo "PyPI ${dist}==${version}: exists=${exists}"
}

maven_path() {
local group="$1"
local artifact="$2"
echo "${group//.//}/${artifact}"
}

maven_status() {
local url="$1"
local output="${2:-/dev/null}"

curl -s -o "$output" -w '%{http_code}' --max-time 10 --retry 3 --retry-connrefused "$url" 2>/dev/null || true
}

maven_emit_exists() {
local exists="$1"
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "exists=${exists}" >>"$GITHUB_OUTPUT"
fi
}

# Check whether a Maven Central artifact version exists. Writes
# exists=true|false to $GITHUB_OUTPUT. A 404 means unpublished; any other
# non-200 status is fatal so an outage does not look like a fresh version.
maven_exists() {
local group="$1"
local artifact="$2"
local version="$3"
local path
path=$(maven_path "$group" "$artifact")
local url="https://repo1.maven.org/maven2/${path}/${version}/${artifact}-${version}.pom"
local url="https://repo1.maven.org/maven2/${group//.//}/${artifact}/${version}/${artifact}-${version}.pom"

local code
code=$(maven_status "$url")
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 --retry 3 --retry-connrefused "$url" 2>/dev/null || true)

local exists
case "$code" in
Expand All @@ -251,102 +229,38 @@ maven_exists() {
;;
esac

maven_emit_exists "$exists"
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "exists=${exists}" >>"$GITHUB_OUTPUT"
fi
echo "Maven ${group}:${artifact}:${version}: exists=${exists}"
}

semver_key() {
local version="${1%%[-+]*}"
local major minor patch
IFS=. read -r major minor patch <<<"$version"
printf '%06d%06d%06d\n' "${major:-0}" "${minor:-0}" "${patch:-0}"
}

semver_ge() {
[[ "$(semver_key "$1")" > "$(semver_key "$2")" || "$(semver_key "$1")" == "$(semver_key "$2")" ]]
}

semver_gt() {
[[ "$(semver_key "$1")" > "$(semver_key "$2")" ]]
}

semver_le() {
[[ "$(semver_key "$1")" < "$(semver_key "$2")" || "$(semver_key "$1")" == "$(semver_key "$2")" ]]
}

semver_lt() {
[[ "$(semver_key "$1")" < "$(semver_key "$2")" ]]
}

version_in_range() {
# Check whether rs/moq-ffi changed since its moq-ffi-v<version> tag. The
# wrappers build against bindings generated from this checkout but depend on
# the published moq-ffi, so releasing one while this is true can ship calls to
# FFI API that no published moq-ffi has. Callers defer instead: release-plz
# bumps and tags moq-ffi, and each language's FFI release re-triggers its
# wrapper release via workflow_run. A tag missing from the checkout (which
# needs fetch-depth: 0) means that release is mid-flight, so it counts too.
# Writes unreleased=true|false to $GITHUB_OUTPUT.
ffi_unreleased() {
local version="$1"
local range="$2"

if [[ ! "$range" =~ ^([\[\(])([^,]+),([^\]\)]+)([\]\)])$ ]]; then
echo "Unsupported Maven version range: $range" >&2
exit 1
local tag="moq-ffi-v${version}"

local unreleased=false
if ! git rev-parse --verify --quiet "refs/tags/${tag}" >/dev/null; then
echo "::warning::${tag} is not tagged yet; deferring the wrapper release to the FFI release chain."
unreleased=true
elif ! git diff --quiet "$tag" HEAD -- rs/moq-ffi; then
echo "::warning::rs/moq-ffi changed since ${tag}; deferring the wrapper release to the FFI release chain."
git diff --stat "$tag" HEAD -- rs/moq-ffi
unreleased=true
fi

local lower_bound="${BASH_REMATCH[1]}"
local lower="${BASH_REMATCH[2]}"
local upper="${BASH_REMATCH[3]}"
local upper_bound="${BASH_REMATCH[4]}"

if [[ "$lower_bound" == "[" ]]; then
semver_ge "$version" "$lower" || return 1
else
semver_gt "$version" "$lower" || return 1
fi

if [[ "$upper_bound" == "]" ]]; then
semver_le "$version" "$upper" || return 1
else
semver_lt "$version" "$upper" || return 1
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "unreleased=${unreleased}" >>"$GITHUB_OUTPUT"
fi
}

# Check whether Maven Central metadata contains any version in a Gradle-style
# half-open range such as [0.3,0.4). Writes exists=true|false to $GITHUB_OUTPUT.
maven_version_in_range() {
local group="$1"
local artifact="$2"
local range="$3"
local path
path=$(maven_path "$group" "$artifact")
local url="https://repo1.maven.org/maven2/${path}/maven-metadata.xml"

local body
body=$(mktemp)

local code
code=$(maven_status "$url" "$body")

case "$code" in
200) ;;
404)
maven_emit_exists false
echo "Maven ${group}:${artifact} has version in ${range}: exists=false"
rm -f "$body"
return
;;
*)
echo "Unexpected status $code querying $url" >&2
exit 1
;;
esac

local exists=false
local version
while IFS= read -r version; do
if version_in_range "$version" "$range"; then
exists=true
break
fi
done < <(grep -oE '<version>[^<]+</version>' "$body" | sed 's#</\?version>##g')

rm -f "$body"
maven_emit_exists "$exists"
echo "Maven ${group}:${artifact} has version in ${range}: exists=${exists}"
echo "moq-ffi ${version}: unreleased=${unreleased}"
}

# Dispatch subcommands
Expand All @@ -358,9 +272,9 @@ case "${1:-}" in
read-version) read_version "$2" ;;
pypi-exists) pypi_exists "$2" "$3" ;;
maven-exists) maven_exists "$2" "$3" "$4" ;;
maven-version-in-range) maven_version_in_range "$2" "$3" "$4" ;;
ffi-unreleased) ffi_unreleased "$2" ;;
*)
echo "Usage: $0 {parse-version|prev-tag|create|git-tag-exists|read-version|pypi-exists|maven-exists|maven-version-in-range} <args>" >&2
echo "Usage: $0 {parse-version|prev-tag|create|git-tag-exists|read-version|pypi-exists|maven-exists|ffi-unreleased} <args>" >&2
exit 1
;;
esac
52 changes: 52 additions & 0 deletions .github/scripts/release.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
# Tests `release.sh ffi-unreleased`, the gate that keeps wrapper releases from
# shipping calls to FFI API that no published moq-ffi has.
set -euo pipefail

release="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/release.sh"

tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
cd "$tmp"

git init -q
git config user.email test@example.com
git config user.name test
git config commit.gpgsign false
git config tag.gpgsign false

mkdir -p rs/moq-ffi py
echo a >rs/moq-ffi/lib.rs
git add . && git commit -qm init
git tag moq-ffi-v0.1.0

expect() {
local want="$1"
local version="$2"
local out="$tmp/output"
: >"$out"
GITHUB_OUTPUT="$out" "$release" ffi-unreleased "$version" >/dev/null
local got
got=$(cat "$out")
if [[ "$got" != "unreleased=$want" ]]; then
echo "ffi-unreleased $version: want unreleased=$want, got '$got'" >&2
exit 1
fi
}

expect false 0.1.0

# Changes outside rs/moq-ffi don't affect the published bindings.
echo b >py/wrapper.py
git add . && git commit -qm wrapper
expect false 0.1.0

# A version bumped but not yet tagged means its release is mid-flight.
expect true 0.2.0

# FFI changes merged after the tag, before the next release.
echo b >rs/moq-ffi/lib.rs
git add . && git commit -qm ffi
expect true 0.1.0

echo "release.sh ffi-unreleased: ok"
27 changes: 22 additions & 5 deletions .github/workflows/release-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ name: Release Go
# * push to main — a wrapper API or VERSION change. The ffi require is
# pinned to the current crate version, whose mirror tag
# already exists in steady state. If it's missing (a
# release is mid-flight), the job skips: the
# workflow_run below republishes once the ffi lands.
# release is mid-flight) or rs/moq-ffi changed since
# its tag, the job skips: the workflow_run below
# republishes once the ffi lands.
# * Release Go FFI done — a new ffi just published to the moq-go-ffi mirror.
# Re-cut the wrapper so `moq.dev/moq@latest` floats to
# the newest native core (Go MVS won't float on its own).
Expand Down Expand Up @@ -61,6 +62,8 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Tags, for the unreleased ffi check.
fetch-depth: 0
persist-credentials: false

- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
Expand Down Expand Up @@ -95,9 +98,17 @@ jobs:
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

# On a main push the wrapper pins the current crate's ffi, whose mirror tag
# already exists in steady state. If it's missing, a release is mid-flight
# (release-plz merged but Release Go FFI hasn't published yet): skip, since
# On a main push the wrapper pins the current crate's ffi version, but it
# may call API added to rs/moq-ffi since that version was tagged.
- name: Check for unreleased ffi changes (push only)
id: ffi-diff
if: github.event_name == 'push'
env:
FFI_VERSION: ${{ steps.ffi.outputs.version }}
run: .github/scripts/release.sh ffi-unreleased "$FFI_VERSION"

# Skip on unreleased ffi changes, and when the pinned ffi's mirror tag is
# missing (release-plz merged but Release Go FFI hasn't published yet):
# the workflow_run trigger republishes once the ffi lands. One existence
# check, no polling. workflow_run runs are chained after that publish, so
# the tag is guaranteed present and this gate doesn't run for them.
Expand All @@ -106,7 +117,13 @@ jobs:
if: github.event_name == 'push'
env:
FFI_VERSION: ${{ steps.ffi.outputs.version }}
FFI_UNRELEASED: ${{ steps.ffi-diff.outputs.unreleased }}
run: |
if [[ "$FFI_UNRELEASED" == "true" ]]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi

# Distinguish "tag absent" from a lookup failure: a network error must
# fail loudly, not masquerade as "defer" (nothing retries a wrapper-only
# push, so a silent skip would drop the release).
Expand Down
Loading
Loading