diff --git a/.github/ci/test_release_binaries.py b/.github/ci/test_release_binaries.py new file mode 100644 index 0000000000..2f3362f68f --- /dev/null +++ b/.github/ci/test_release_binaries.py @@ -0,0 +1,148 @@ +"""Tests for the release backfill scripts in .github/scripts, run against a stub gh on PATH. + +The stub serves a release whose assets are described by RELEASE_ASSETS (a JSON object of name to +content) and fails every download when GH_DOWNLOAD_FAILS is set, so a test can tell a release with +nothing attached from one whose assets could not be fetched. A stub cosign accepts every bundle +unless COSIGN_REJECTS is set, and logs its arguments. +""" +import hashlib +import json +import os +import pathlib +import subprocess +import tempfile +import textwrap +import unittest + +SCRIPTS = pathlib.Path(__file__).resolve().parents[1] / 'scripts' +EXISTING = SCRIPTS / 'release-binaries-existing.sh' +SUMS = SCRIPTS / 'release-binaries-sums.sh' + +STUB_GH = textwrap.dedent('''\ + #!/usr/bin/env python3 + import json, os, pathlib, sys + assets = json.loads(os.environ.get('RELEASE_ASSETS', '{}')) + args = sys.argv[1:] + with open(os.environ['GH_CALLS'], 'a') as log: + log.write(' '.join(args) + '\\n') + if args[:2] == ['release', 'view']: + print('\\n'.join(assets)) + sys.exit(0) + if args[:2] == ['release', 'download']: + if os.environ.get('GH_DOWNLOAD_FAILS'): + print('HTTP 502: Bad Gateway', file=sys.stderr) + sys.exit(1) + target = pathlib.Path(args[args.index('-D') + 1]) + target.mkdir(parents=True, exist_ok=True) + name = args[args.index('-p') + 1] + if name not in assets: + print('no assets match the file pattern', file=sys.stderr) + sys.exit(1) + (target / name).write_text(assets[name]) + sys.exit(0) + sys.exit(2) + ''') + +STUB_COSIGN = textwrap.dedent('''\ + #!/usr/bin/env python3 + import os, sys + with open(os.environ['COSIGN_CALLS'], 'a') as log: + log.write(' '.join(sys.argv[1:]) + '\\n') + sys.exit(1 if os.environ.get('COSIGN_REJECTS') else 0) + ''') + + +def sha256(text): + return hashlib.sha256(text.encode()).hexdigest() + + +class ReleaseScriptsTest(unittest.TestCase): + + def setUp(self): + self.tmp = pathlib.Path(tempfile.mkdtemp()) + bin_dir = self.tmp / 'bin' + bin_dir.mkdir() + gh = bin_dir / 'gh' + gh.write_text(STUB_GH) + gh.chmod(0o755) + cosign = bin_dir / 'cosign' + cosign.write_text(STUB_COSIGN) + cosign.chmod(0o755) + self.calls = self.tmp / 'calls.log' + self.calls.touch() + self.cosign_calls = self.tmp / 'cosign.log' + self.cosign_calls.touch() + self.env = dict(os.environ, PATH=f'{bin_dir}:{os.environ["PATH"]}', GH_CALLS=str(self.calls), + COSIGN_CALLS=str(self.cosign_calls)) + + def existing(self, assets, download_fails=False): + env = dict(self.env, RELEASE_ASSETS=json.dumps(assets)) + if download_fails: + env['GH_DOWNLOAD_FAILS'] = '1' + target = self.tmp / 'existing' + result = subprocess.run([str(EXISTING), '2.5.0', str(target)], env=env, capture_output=True, text=True) + return result, target + + def test_a_failed_download_stops_the_backfill(self): + result, _ = self.existing({'floci-aws-linux-amd64': 'bin', 'sha256sums.txt': 'sums'}, download_fails=True) + self.assertNotEqual(0, result.returncode, result.stdout + result.stderr) + + def test_a_release_with_nothing_attached_downloads_nothing(self): + result, target = self.existing({}) + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual([], sorted(p.name for p in target.iterdir())) + self.assertNotIn('release download', self.calls.read_text()) + + def test_every_attached_binary_the_sums_file_and_its_bundle_are_downloaded_but_not_binary_bundles(self): + assets = {'floci-aws-linux-amd64': 'a', 'floci-aws-linux-amd64.sigstore.json': 'bundle', + 'sha256sums.txt': 'sums', 'sha256sums.txt.sigstore.json': 'bundle', 'notes.txt': 'x'} + result, target = self.existing(assets) + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual(['floci-aws-linux-amd64', 'sha256sums.txt', 'sha256sums.txt.sigstore.json'], + sorted(p.name for p in target.iterdir())) + + def sums(self, existing, dist, cosign_rejects=False): + existing_dir, dist_dir = self.tmp / 'e', self.tmp / 'd' + for directory, files in ((existing_dir, existing), (dist_dir, dist)): + directory.mkdir() + for name, content in files.items(): + (directory / name).write_text(content) + env = dict(self.env, COSIGN_REJECTS='1') if cosign_rejects else self.env + result = subprocess.run([str(SUMS), str(existing_dir), str(dist_dir)], env=env, capture_output=True, + text=True) + return result, dist_dir / 'sha256sums.txt' + + def test_the_sums_keep_the_lines_of_attached_binaries_and_add_the_new_ones(self): + listed = f'{sha256("old")} floci-aws-linux-amd64\n' + result, out = self.sums({'floci-aws-linux-amd64': 'old', 'sha256sums.txt': listed, + 'sha256sums.txt.sigstore.json': 'bundle'}, + {'floci-aws-darwin-amd64': 'new'}) + self.assertEqual(0, result.returncode, result.stderr) + self.assertIn("--certificate-identity-regexp ^https://github.com/floci-io/floci/.github/workflows/release.yml@", + self.cosign_calls.read_text()) + self.assertEqual(f'{sha256("new")} floci-aws-darwin-amd64\n{sha256("old")} floci-aws-linux-amd64\n', + out.read_text()) + + def test_an_attached_binary_that_does_not_match_its_line_stops_the_publish(self): + listed = f'{sha256("old")} floci-aws-linux-amd64\n' + result, _ = self.sums({'floci-aws-linux-amd64': 'tampered', 'sha256sums.txt': listed, + 'sha256sums.txt.sigstore.json': 'bundle'}, + {'floci-aws-darwin-amd64': 'new'}) + self.assertNotEqual(0, result.returncode) + + def test_sums_whose_signature_does_not_verify_stop_the_publish(self): + listed = f'{sha256("old")} floci-aws-linux-amd64\n' + result, _ = self.sums({'floci-aws-linux-amd64': 'old', 'sha256sums.txt': listed, + 'sha256sums.txt.sigstore.json': 'bundle'}, + {'floci-aws-darwin-amd64': 'new'}, cosign_rejects=True) + self.assertNotEqual(0, result.returncode) + + def test_sums_without_their_bundle_stop_the_publish(self): + listed = f'{sha256("old")} floci-aws-linux-amd64\n' + result, _ = self.sums({'floci-aws-linux-amd64': 'old', 'sha256sums.txt': listed}, + {'floci-aws-darwin-amd64': 'new'}) + self.assertNotEqual(0, result.returncode) + + +if __name__ == '__main__': + unittest.main() diff --git a/.github/scripts/release-binaries-existing.sh b/.github/scripts/release-binaries-existing.sh new file mode 100755 index 0000000000..54b5c310b2 --- /dev/null +++ b/.github/scripts/release-binaries-existing.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Downloads into the standalone binaries a release already carries, and its sha256sums.txt, +# for release-binaries-sums.sh to check and extend. +# +# release-binaries-existing.sh +# +# The names come from the release's asset list, and each one is downloaded by its exact name, so +# a release with nothing attached downloads nothing, while a download that fails stops the +# backfill: carrying on with a partial would rewrite sha256sums.txt without the lines of the +# binaries it missed. Of the cosign bundles only sha256sums.txt's is kept, which +# release-binaries-sums.sh verifies before trusting the file; the backfill signs what it publishes. +set -euo pipefail + +TAG=${1:?usage: release-binaries-existing.sh } +DIR=${2:?usage: release-binaries-existing.sh } +mkdir -p "$DIR" + +names=$(gh release view "$TAG" --json assets --jq '.assets[].name') +while IFS= read -r name; do + case "$name" in + sha256sums.txt|sha256sums.txt.sigstore.json) gh release download "$TAG" -D "$DIR" -p "$name" ;; + *.sigstore.json) continue ;; + floci-aws-*) gh release download "$TAG" -D "$DIR" -p "$name" ;; + esac +done <<< "$names" diff --git a/.github/scripts/release-binaries-plan.sh b/.github/scripts/release-binaries-plan.sh new file mode 100755 index 0000000000..048256f84e --- /dev/null +++ b/.github/scripts/release-binaries-plan.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash +# Decides which standalone binaries a Release run builds and publishes. +# +# EVENT=push release-binaries-plan.sh # a tag push: everything +# EVENT=workflow_dispatch TAG=2.5.0 PLATFORMS=missing [REPLACE=false] [REF=refs/heads/main] \ +# GH_REPO=floci-io/floci release-binaries-plan.sh # a backfill +# +# PLATFORMS is `missing` (the binaries the release does not have yet), `all`, or a comma list of +# linux-amd64, linux-arm64, linux-arm64-baseline, darwin-amd64, windows-amd64. A named platform the +# release already carries is refused unless REPLACE=true; `missing` never replaces anything. +# +# Writes key=value lines to $GITHUB_OUTPUT (stdout when unset, so it doubles as a dry run): +# linux_amd64, linux_arm64, linux_arm64_baseline, darwin_amd64, windows_amd64 true|false +# standalone comma list of the selected macOS/Windows platforms, for standalone-binaries.yml +# any true when at least one binary is selected +# Exits non-zero, building nothing, when the request is invalid. +set -euo pipefail + +ALL=(linux-amd64 linux-arm64 linux-arm64-baseline darwin-amd64 windows-amd64) +OUT=${GITHUB_OUTPUT:-/dev/stdout} +SUMMARY=${GITHUB_STEP_SUMMARY:-/dev/null} + +asset_name() { + case "$1" in + windows-amd64) echo "floci-aws-windows-amd64.exe" ;; + *) echo "floci-aws-$1" ;; + esac +} + +fail() { + echo "::error::$1" >&2 + exit 1 +} + +emit() { + local selected=" $* " standalone="" any=false + for p in "${ALL[@]}"; do + if [[ $selected == *" $p "* ]]; then + echo "${p//-/_}=true" >> "$OUT" + any=true + case "$p" in + darwin-*|windows-*) standalone="${standalone:+$standalone,}$p" ;; + esac + else + echo "${p//-/_}=false" >> "$OUT" + fi + done + echo "standalone=$standalone" >> "$OUT" + echo "any=$any" >> "$OUT" +} + +if [ "${EVENT:?EVENT is required}" = push ]; then + emit "${ALL[@]}" + exit 0 +fi + +TAG=${TAG:?TAG is required for a backfill} +PLATFORMS=${PLATFORMS:-missing} +REPLACE=${REPLACE:-false} + +[[ $TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || fail "tag '$TAG' is not a release version (x.y.z)" +# The release identity docs/getting-started/installation.md verifies is release.yml at any ref, so +# only main's copy of this workflow may sign a backfill. +if [ -n "${REF:-}" ] && [ "$REF" != refs/heads/main ]; then + fail "a backfill runs from main only, not $REF" +fi + +command -v gh > /dev/null || fail "gh is not installed" +attached=$(gh release view "$TAG" --json assets -q '.assets[].name') \ + || fail "could not read release $TAG (does it exist?); a backfill never creates a release (semantic-release does)" + +is_attached() { + grep -qxF "$(asset_name "$1")" <<< "$attached" +} + +selected=() +case "$PLATFORMS" in + missing) + for p in "${ALL[@]}"; do + is_attached "$p" || selected+=("$p") + done + ;; + all) + selected=("${ALL[@]}") + ;; + *) + IFS=',' read -ra requested <<< "$PLATFORMS" + for p in "${requested[@]}"; do + p=${p// /} + [ -z "$p" ] && continue + [[ " ${ALL[*]} " == *" $p "* ]] || fail "unknown platform '$p' (known: ${ALL[*]})" + selected+=("$p") + done + ;; +esac + +if [ "$PLATFORMS" != missing ] && [ "$REPLACE" != true ]; then + for p in "${selected[@]}"; do + if is_attached "$p"; then + fail "$TAG already has $(asset_name "$p"); run with replace=true to rebuild and overwrite it" + fi + done +fi + +{ + echo "### Standalone binaries for $TAG" + echo + echo "Request: \`$PLATFORMS\`, replace: \`$REPLACE\`" + echo + for p in "${ALL[@]}"; do + state=$(is_attached "$p" && echo attached || echo missing) + action=skip + [[ " ${selected[*]:-} " == *" $p "* ]] && action=build + echo "- \`$(asset_name "$p")\`: $state, $action" + done +} >> "$SUMMARY" + +if [ ${#selected[@]} -eq 0 ]; then + echo "$TAG already has every standalone binary; nothing to build" >&2 +fi +emit "${selected[@]:-}" diff --git a/.github/scripts/release-binaries-sums.sh b/.github/scripts/release-binaries-sums.sh new file mode 100755 index 0000000000..db63398f16 --- /dev/null +++ b/.github/scripts/release-binaries-sums.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# Writes /sha256sums.txt for a release: the binaries staged in plus every binary the +# release already carries (downloaded into ) that does not replace. +# +# release-binaries-sums.sh +# +# The release's current sha256sums.txt is first verified against its cosign bundle, signed by +# release.yml as docs/getting-started/installation.md tells users to check it, and the existing +# binaries are then checked against that file. So a backfill never vouches for a file the release +# did not already sign: a sums file without a bundle that verifies, or an existing binary that is +# missing from it or does not match it, stops the publish. With nothing in (a tag +# run) the result is plain `sha256sum floci-aws-*` over , as before. +set -euo pipefail + +EXISTING=${1:?usage: release-binaries-sums.sh } +DIST=${2:?usage: release-binaries-sums.sh } + +binaries() { + find "$1" -maxdepth 1 -type f -name 'floci-aws-*' ! -name '*.sigstore.json' -exec basename {} \; | sort +} + +existing=$(binaries "$EXISTING") +lines=() +if [ -n "$existing" ]; then + if [ ! -f "$EXISTING/sha256sums.txt" ]; then + echo "::error::the release has binaries but no sha256sums.txt; it cannot be extended safely" >&2 + exit 1 + fi + if [ ! -f "$EXISTING/sha256sums.txt.sigstore.json" ]; then + echo "::error::the release's sha256sums.txt has no cosign bundle; it cannot be extended safely" >&2 + exit 1 + fi + cosign verify-blob "$EXISTING/sha256sums.txt" --bundle "$EXISTING/sha256sums.txt.sigstore.json" \ + --certificate-identity-regexp '^https://github.com/floci-io/floci/.github/workflows/release.yml@' \ + --certificate-oidc-issuer https://token.actions.githubusercontent.com >&2 \ + || { echo "::error::the release's sha256sums.txt does not verify against its cosign bundle" >&2; exit 1; } + while IFS= read -r name; do + grep -qE "^[0-9a-f]{64} $name\$" "$EXISTING/sha256sums.txt" \ + || { echo "::error::$name is attached but not listed in the release's sha256sums.txt" >&2; exit 1; } + done <<< "$existing" + (cd "$EXISTING" && sha256sum --ignore-missing -c sha256sums.txt) >&2 + while IFS= read -r name; do + [ -e "$DIST/$name" ] && continue + lines+=("$(grep -E "^[0-9a-f]{64} $name\$" "$EXISTING/sha256sums.txt")") + done <<< "$existing" +fi + +while IFS= read -r name; do + [ -n "$name" ] && lines+=("$(cd "$DIST" && sha256sum "$name")") +done <<< "$(binaries "$DIST")" + +[ ${#lines[@]} -gt 0 ] || { echo "::error::no binaries to list" >&2; exit 1; } +printf '%s\n' "${lines[@]}" | sort -k2 > "$DIST/sha256sums.txt" +cat "$DIST/sha256sums.txt" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ccc61ed1c..4441b5f074 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,7 @@ on: - 'src/**' - 'pom.xml' - '.github/ci/**' + - '.github/scripts/release-binaries-*' - '.github/workflows/ci.yml' pull_request: # ready_for_review is not a default type: without it, marking a draft ready @@ -17,6 +18,7 @@ on: - 'src/**' - 'pom.xml' - '.github/ci/**' + - '.github/scripts/release-binaries-*' - '.github/workflows/ci.yml' permissions: @@ -108,6 +110,7 @@ jobs: > "$GITHUB_WORKSPACE/all-classes.txt" cd "$GITHUB_WORKSPACE" python3 -m unittest discover -s .github/ci -p test_partition.py + python3 -m unittest discover -s .github/ci -p test_release_binaries.py .github/ci/partition.sh all-classes.txt "$SHARD_TOTAL" "${{ matrix.shard }}" > shard.txt # An empty includesFile makes surefire fall back to its default includes # and run the ENTIRE suite into this shard's timeout. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 99966f3270..a75c675799 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,11 +14,35 @@ name: Release # public.ecr.aws/floci/floci:1.2.3-compat public.ecr.aws/floci/floci:latest-compat # # Required secrets: DOCKERHUB_USERNAME, DOCKERHUB_TOKEN, AWS_ROLE_ARN +# +# Run by hand from main (Actions > Release > Run workflow) it backfills an existing release: it +# builds the standalone binaries the release lacks (or the ones named), from the tag's source, and +# attaches them signed and attested exactly as a tag run does, with sha256sums.txt rewritten to +# cover every binary. A backfill never pushes or signs images and never creates a release. +# gh workflow run release.yml --ref main -f tag=2.5.0 # what is missing +# gh workflow run release.yml --ref main -f tag=2.5.0 -f platforms=darwin-amd64 -f replace=true +# .github/scripts/release-binaries-plan.sh decides what to build; run it locally for a dry run. on: push: tags: - '[0-9]+.[0-9]+.[0-9]+' + workflow_dispatch: + inputs: + tag: + description: Existing release to attach binaries to (x.y.z) + required: true + type: string + platforms: + description: missing, all, or a comma list of linux-amd64, linux-arm64, linux-arm64-baseline, darwin-amd64, windows-amd64 + required: false + type: string + default: missing + replace: + description: Rebuild and overwrite binaries the release already has (only with all or a list) + required: false + type: boolean + default: false # Only the jobs that need an OIDC token request one: push-native (assume the # AWS role for ECR Public) and sign-images (that, plus a Fulcio certificate). @@ -29,14 +53,51 @@ permissions: # minutes apart) resolve to different ${{ github.ref }} values, so they run # in parallel rather than cancelling each other. Re-runs of the same tag # supersede in-flight builds of that tag. +# A backfill shares its tag's group, so it never uploads alongside that tag's own run, and it +# waits rather than cancelling one. concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true + group: ${{ github.workflow }}-${{ inputs.tag || github.ref_name }} + cancel-in-progress: ${{ github.event_name == 'push' }} + +# The version the binaries are built from and smoke-tested against: the pushed tag, or the +# release a backfill targets. +env: + RELEASE_TAG: ${{ inputs.tag || github.ref_name }} jobs: + # ── Decide what to build ───────────────────────────────────────────────── + # A tag push builds everything. A backfill builds what the release lacks, or what was named. + plan: + name: Plan the standalone binaries + runs-on: ubuntu-latest + timeout-minutes: 10 + outputs: + linux_amd64: ${{ steps.plan.outputs.linux_amd64 }} + linux_arm64: ${{ steps.plan.outputs.linux_arm64 }} + linux_arm64_baseline: ${{ steps.plan.outputs.linux_arm64_baseline }} + standalone: ${{ steps.plan.outputs.standalone }} + any: ${{ steps.plan.outputs.any }} + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Resolve the binaries to build + id: plan + env: + EVENT: ${{ github.event_name }} + TAG: ${{ inputs.tag }} + PLATFORMS: ${{ inputs.platforms }} + REPLACE: ${{ inputs.replace }} + REF: ${{ github.ref }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + run: .github/scripts/release-binaries-plan.sh + # ── Build native artifact — amd64 ──────────────────────────────────────── build-native-amd64: name: Build native artifact (amd64) + needs: plan + if: needs.plan.outputs.linux_amd64 == 'true' # Pinned, like the arm64 jobs. Built on ubuntu-26.04 the binary asks glibc for x86-64-v3 # whatever -march says, and no longer starts on x86-64-v2 CPUs. runs-on: ubuntu-24.04 @@ -44,6 +105,8 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ env.RELEASE_TAG }} - uses: graalvm/setup-graalvm@27b360dbb857524eaf0b4c4cef364d38e5b4f173 # v1 with: @@ -85,7 +148,7 @@ jobs: - name: Smoke-test the standalone binary # The same binary is published as a release asset (publish-binaries), so it is checked # the way a user runs it: on the host, no Docker image around it. - run: .github/scripts/smoke-binary.sh "$(ls target/*-runner)" "$GITHUB_REF_NAME" + run: .github/scripts/smoke-binary.sh "$(ls target/*-runner)" "$RELEASE_TAG" - name: Check the glibc floor of the standalone binary # The release asset links glibc dynamically and must run on 2.34 (RHEL 9, Debian 12, @@ -107,11 +170,15 @@ jobs: # ── Build native artifact — arm64 ──────────────────────────────────────── build-native-arm64: name: Build native artifact (arm64) + needs: plan + if: needs.plan.outputs.linux_arm64 == 'true' runs-on: ubuntu-24.04-arm timeout-minutes: 45 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ env.RELEASE_TAG }} - uses: graalvm/setup-graalvm@27b360dbb857524eaf0b4c4cef364d38e5b4f173 # v1 with: @@ -147,7 +214,7 @@ jobs: - name: Smoke-test the standalone binary # The same binary is published as a release asset (publish-binaries), so it is checked # the way a user runs it: on the host, no Docker image around it. - run: .github/scripts/smoke-binary.sh "$(ls target/*-runner)" "$GITHUB_REF_NAME" + run: .github/scripts/smoke-binary.sh "$(ls target/*-runner)" "$RELEASE_TAG" - name: Check the glibc floor of the standalone binary run: .github/scripts/check-glibc-floor.sh "$(ls target/*-runner)" @@ -166,11 +233,15 @@ jobs: # ── Build baseline native artifact — arm64 only ───────────────────────── build-native-arm64-baseline: name: Build baseline native artifact (arm64) + needs: plan + if: needs.plan.outputs.linux_arm64_baseline == 'true' runs-on: ubuntu-24.04-arm timeout-minutes: 45 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ env.RELEASE_TAG }} - uses: graalvm/setup-graalvm@27b360dbb857524eaf0b4c4cef364d38e5b4f173 # v1 with: @@ -204,7 +275,7 @@ jobs: - name: Smoke-test the standalone binary # The same binary is published as a release asset (publish-binaries), so it is checked # the way a user runs it: on the host, no Docker image around it. - run: .github/scripts/smoke-binary.sh "$(ls target/*-runner)" "$GITHUB_REF_NAME" + run: .github/scripts/smoke-binary.sh "$(ls target/*-runner)" "$RELEASE_TAG" - name: Check the glibc floor of the standalone binary run: .github/scripts/check-glibc-floor.sh "$(ls target/*-runner)" @@ -228,16 +299,21 @@ jobs: # darwin-amd64 binary under Rosetta 2 instead. standalone-binaries: name: Standalone binaries + needs: plan + if: needs.plan.outputs.standalone != '' uses: ./.github/workflows/standalone-binaries.yml with: - platforms: darwin-amd64,windows-amd64 - version: ${{ github.ref_name }} + platforms: ${{ needs.plan.outputs.standalone }} + version: ${{ inputs.tag || github.ref_name }} + ref: ${{ inputs.tag || github.ref }} # ── Publish standalone binaries to the GitHub Release ──────────────────── # semantic-release pushes this tag and then creates the release (notes only); the upload step # waits for the release to exist. This job adds # one raw executable per platform, sha256sums.txt, a keyless cosign bundle per file, and a # GitHub build-provenance attestation. It is the only job that writes to the release. + # A backfill adds only the binaries it built: it downloads the ones already attached, checks them + # against the release's sha256sums.txt, and replaces that file with one covering every binary. # Verify a download with: # sha256sum --ignore-missing -c sha256sums.txt # cosign verify-blob floci-aws-linux-amd64 --bundle floci-aws-linux-amd64.sigstore.json \ @@ -247,18 +323,21 @@ jobs: publish-binaries: name: Publish standalone binaries needs: + - plan - build-native-amd64 - build-native-arm64 - build-native-arm64-baseline - standalone-binaries - # The Linux binaries are required. A macOS or Windows build that failed or timed out leaves - # its binary out instead of holding back the others (2.4.0 and 2.5.0 published none at all - # because the macOS builds timed out); Stage the release assets warns about each one missing. + # Every Linux binary the plan selected is required (a tag run selects all three). A macOS or + # Windows build that failed or timed out leaves its binary out instead of holding back the + # others (2.4.0 and 2.5.0 published none at all because the macOS builds timed out); Stage the + # release assets warns about each one missing. if: >- ${{ always() && - needs.build-native-amd64.result == 'success' && - needs.build-native-arm64.result == 'success' && - needs.build-native-arm64-baseline.result == 'success' }} + needs.plan.result == 'success' && needs.plan.outputs.any == 'true' && + (needs.plan.outputs.linux_amd64 != 'true' || needs.build-native-amd64.result == 'success') && + (needs.plan.outputs.linux_arm64 != 'true' || needs.build-native-arm64.result == 'success') && + (needs.plan.outputs.linux_arm64_baseline != 'true' || needs.build-native-arm64-baseline.result == 'success') }} runs-on: ubuntu-latest timeout-minutes: 20 @@ -268,11 +347,18 @@ jobs: attestations: write steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: path: artifacts - name: Stage the release assets + env: + LINUX_AMD64: ${{ needs.plan.outputs.linux_amd64 }} + LINUX_ARM64: ${{ needs.plan.outputs.linux_arm64 }} + LINUX_ARM64_BASELINE: ${{ needs.plan.outputs.linux_arm64_baseline }} + STANDALONE: ${{ needs.plan.outputs.standalone }} run: | set -euo pipefail mkdir dist @@ -285,19 +371,48 @@ jobs: echo "- \`$2\` was not built and is not attached to the release." >> "$GITHUB_STEP_SUMMARY" fi } - stage native-amd64 floci-aws-linux-amd64 - stage native-arm64 floci-aws-linux-arm64 - stage native-arm64-baseline floci-aws-linux-arm64-baseline - optional binary-darwin-amd64 floci-aws-darwin-amd64 - optional binary-windows-amd64 floci-aws-windows-amd64.exe - (cd dist && sha256sum floci-aws-* > sha256sums.txt) + selected() { [[ ",$STANDALONE," == *",$1,"* ]]; } + [ "$LINUX_AMD64" = true ] && stage native-amd64 floci-aws-linux-amd64 + [ "$LINUX_ARM64" = true ] && stage native-arm64 floci-aws-linux-arm64 + [ "$LINUX_ARM64_BASELINE" = true ] && stage native-arm64-baseline floci-aws-linux-arm64-baseline + selected darwin-amd64 && optional binary-darwin-amd64 floci-aws-darwin-amd64 + selected windows-amd64 && optional binary-windows-amd64 floci-aws-windows-amd64.exe + compgen -G "dist/floci-aws-*" > /dev/null || { echo "::error::nothing was built to publish"; exit 1; } ls -l dist + - name: Wait for the GitHub Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + # The tag starts this workflow before semantic-release creates the GitHub Release, so wait + # for it (up to 10 minutes) instead of failing the upload. + run: | + for _ in $(seq 1 30); do + gh release view "$RELEASE_TAG" > /dev/null 2>&1 && break + echo "waiting for the $RELEASE_TAG release to exist"; sleep 20 + done + gh release view "$RELEASE_TAG" > /dev/null || { echo "::error::release $RELEASE_TAG not found after 10 minutes"; exit 1; } + - name: Install Cosign uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 with: cosign-release: 'v3.1.3' + - name: Write sha256sums.txt + # A tag run lists what it built. A backfill keeps the lines of the binaries the release + # already has, after verifying its sums file against its cosign bundle and those binaries + # against that file, and adds the new ones. + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + run: | + set -euo pipefail + mkdir existing + if [ "$GITHUB_EVENT_NAME" = workflow_dispatch ]; then + .github/scripts/release-binaries-existing.sh "$RELEASE_TAG" existing + fi + .github/scripts/release-binaries-sums.sh existing dist + - name: Sign the release assets working-directory: dist run: | @@ -314,20 +429,17 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} - # The tag starts this workflow before semantic-release creates the GitHub Release, so wait - # for it (up to 10 minutes) instead of failing the upload. --clobber makes a re-run idempotent. - run: | - for _ in $(seq 1 30); do - gh release view "$GITHUB_REF_NAME" > /dev/null 2>&1 && break - echo "waiting for the $GITHUB_REF_NAME release to exist"; sleep 20 - done - gh release view "$GITHUB_REF_NAME" > /dev/null || { echo "::error::release $GITHUB_REF_NAME not found after 10 minutes"; exit 1; } - gh release upload "$GITHUB_REF_NAME" dist/* --clobber + # --clobber makes a re-run idempotent. A backfill only reaches here with binaries the plan + # allowed: missing ones, or attached ones it was told to replace. + run: gh release upload "$RELEASE_TAG" dist/* --clobber # ── Push native + compat Docker images ─────────────────────────────────── push-native: name: Push native and compat Docker images needs: [build-native-amd64, build-native-arm64, build-native-arm64-baseline] + # Images are published by tag runs only; a backfill that rebuilds the Linux binaries leaves + # them alone. + if: github.event_name == 'push' runs-on: ubuntu-latest timeout-minutes: 30 diff --git a/.github/workflows/standalone-binaries.yml b/.github/workflows/standalone-binaries.yml index a2df5ddd94..9004db9260 100644 --- a/.github/workflows/standalone-binaries.yml +++ b/.github/workflows/standalone-binaries.yml @@ -31,8 +31,18 @@ on: required: false type: string default: '' + ref: + description: Branch, tag or SHA to build (default, the caller's ref). A release backfill passes its tag + required: false + type: string + default: '' workflow_dispatch: inputs: + ref: + description: Branch, tag or SHA to build (default, the branch the run is started from) + required: false + type: string + default: '' platforms: description: Comma-separated platforms to build (darwin-arm64, darwin-amd64, windows-amd64) required: false @@ -73,6 +83,8 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ inputs.ref }} - name: Read the version id: version @@ -92,6 +104,8 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ inputs.ref }} - uses: graalvm/setup-graalvm@27b360dbb857524eaf0b4c4cef364d38e5b4f173 # v1 with: @@ -136,6 +150,8 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ inputs.ref }} - name: Install Rosetta 2 if: runner.arch == 'ARM64' @@ -190,6 +206,8 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ inputs.ref }} - uses: graalvm/setup-graalvm@27b360dbb857524eaf0b4c4cef364d38e5b4f173 # v1 with: