From b8d274d05d75490036b44da9a2862e770d5d5c61 Mon Sep 17 00:00:00 2001 From: showxu <10173746+showxu@users.noreply.github.com> Date: Sat, 28 Nov 2026 22:07:12 +0800 Subject: [PATCH] fix: recover packaging for the tagged app release --- .github/workflows/release-gate.yml | 19 +++++++++++------ Documentation/Release.md | 8 ++++--- Scripts/package-release.sh | 7 ++++-- Scripts/release-assets.sh | 22 +++++++++++++------ Scripts/verify-release-source.sh | 34 +++++++++++++++++++++++++++--- 5 files changed, 68 insertions(+), 22 deletions(-) diff --git a/.github/workflows/release-gate.yml b/.github/workflows/release-gate.yml index 98d0928..6c2ebda 100644 --- a/.github/workflows/release-gate.yml +++ b/.github/workflows/release-gate.yml @@ -49,15 +49,17 @@ jobs: persist-credentials: false - name: Verify approved tag and commit run: Scripts/verify-release-source.sh - - name: Require successful check at the approved master commit + - name: Require successful checks at the tagged source and master dispatch if: inputs.operation == 'publish' shell: bash env: GH_TOKEN: ${{ github.token }} run: | set -euo pipefail - gh api "repos/$GITHUB_REPOSITORY/actions/workflows/check.yml/runs?branch=master&event=push&status=success&head_sha=$SOURCE_COMMIT" \ - | jq -e --arg commit "$SOURCE_COMMIT" 'any(.workflow_runs[]; .head_sha == $commit and .conclusion == "success")' + for commit in "$SOURCE_COMMIT" "$GITHUB_SHA"; do + gh api "repos/$GITHUB_REPOSITORY/actions/workflows/check.yml/runs?branch=master&event=push&status=success&head_sha=$commit" \ + | jq -e --arg commit "$commit" 'any(.workflow_runs[]; .head_sha == $commit and .head_branch == "master" and .event == "push" and .conclusion == "success")' + done release: name: Build and publish notarized release @@ -79,14 +81,17 @@ jobs: persist-credentials: false - name: Verify source again before building run: Scripts/verify-release-source.sh - - name: Archive universal application + - name: Archive universal application from tagged source if: inputs.candidate_run_id == '' shell: bash run: | set -euo pipefail + source_checkout="$RUNNER_TEMP/release-source" + git worktree add --detach "$source_checkout" "$SOURCE_COMMIT" + trap 'git worktree remove "$source_checkout"' EXIT xcodebuild -version xcodebuild archive \ - -project Agents.xcodeproj -scheme AgentsApp -configuration Release \ + -project "$source_checkout/Agents.xcodeproj" -scheme AgentsApp -configuration Release \ -destination 'generic/platform=macOS' \ -archivePath "$RUNNER_TEMP/Agents App.xcarchive" \ -derivedDataPath "$RUNNER_TEMP/DerivedData" \ @@ -103,11 +108,11 @@ jobs: API_KEY_ID: ${{ secrets.ASC_API_KEY_ID }} API_ISSUER_ID: ${{ secrets.ASC_API_ISSUER_ID }} run: Scripts/package-release.sh "$RUNNER_TEMP/Agents App.xcarchive" "$RUNNER_TEMP/distribution" - - name: Record candidate source and tag object + - name: Record candidate source, tag object, and packaging commit if: inputs.candidate_run_id == '' run: | Scripts/verify-release-source.sh - git rev-parse "$SOURCE_COMMIT" "refs/tags/$RELEASE_TAG" >"$RUNNER_TEMP/distribution/source" + git rev-parse "$SOURCE_COMMIT" "refs/tags/$RELEASE_TAG" "$GITHUB_SHA" >"$RUNNER_TEMP/distribution/source" - name: Preserve the signed ZIP and checksum if: inputs.candidate_run_id == '' uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 diff --git a/Documentation/Release.md b/Documentation/Release.md index 7580554..7ca412b 100644 --- a/Documentation/Release.md +++ b/Documentation/Release.md @@ -13,7 +13,9 @@ GitHub Releases distributes a universal ZIP for Apple silicon and Intel Macs run 1. Confirm the accepted release commit is the tip of `master` and its **Check** workflow passed on the master-branch push. Check the app target's Release `MARKETING_VERSION` in `Agents.xcodeproj`. For the first release it is `0.1.0`. 2. After the owner approves the tag, create and push the annotated `v0.1.0` tag at the exact accepted commit. Keep published tags fixed. -3. Dispatch the **Release** workflow on `master` with the `publish` operation, tag, and full accepted commit SHA. The workflow verifies the remote tag and exact master check before the protected job. -4. The production job archives both architectures using the committed package lock. It signs with Developer ID and a secure timestamp, notarizes with the Team API key, and staples and verifies the app extracted from the final ZIP. The job preserves the signed ZIP, checksum, and tag identity as a workflow artifact before creating or completing a draft release. It then verifies the unauthenticated public downloads against that candidate. +3. Dispatch the **Release** workflow on `master` with the `publish` operation, tag, and full tagged source SHA. The dispatch commit must descend from the tagged source. The workflow allows differences in the release workflow, its three scripts, and this release guide. It checks the remote tag and requires a successful **Check** from a push to `master` for both the tagged commit and dispatch commit before the protected job starts. +4. The production job archives both architectures from a detached checkout of the tagged source using its committed package lock. The release scripts run from the master dispatch checkout. The job signs with Developer ID and a secure timestamp, notarizes with the Team API key, and staples and verifies the app extracted from the final ZIP. It preserves the signed ZIP, checksum, source SHA, tag object SHA, and packaging commit SHA before creating or completing a draft release. It then verifies the unauthenticated public downloads against that candidate. -Record the original signing run ID with the release. To complete an interrupted publication, dispatch `publish` with that ID as `candidate_run_id` while the approved commit is still the tip of `master`. Existing assets must match the preserved candidate. For a published release, dispatch `verify-public` with the original signing run ID, tag and full release commit to verify the downloads while the artifact is retained. This operation uses read-only GitHub permissions. Published tags and assets stay fixed. +Record the signing run ID with the release. To complete an interrupted publication after the candidate was preserved, dispatch `publish` with that run ID as `candidate_run_id` from a master commit that meets the same release-file and check requirements. Existing assets must match the preserved candidate. + +For a published release, dispatch `verify-public` on `master` with the original signing run ID, tag, and full tagged source SHA. The read-only job verifies the original run and packaging commit against the preserved candidate, even after new product commits land on `master`. Verification requires the signing run’s artifact to still be available. diff --git a/Scripts/package-release.sh b/Scripts/package-release.sh index 601d2bf..dcfa91a 100755 --- a/Scripts/package-release.sh +++ b/Scripts/package-release.sh @@ -20,8 +20,11 @@ executable=$(/usr/libexec/PlistBuddy -c 'Print CFBundleExecutable' "$plist") fail "Unexpected archived bundle identifier." [[ v$version == "$RELEASE_TAG" ]] || fail "Archive version differs from the approved tag." binary="$app/Contents/MacOS/$executable" -xcrun lipo -verify_arch arm64 x86_64 "$binary" -[[ $(xcrun lipo -archs "$binary" | wc -w | tr -d ' ') == 2 ]] || fail "Expected exactly two architectures." +architectures=$(xcrun lipo -archs "$binary") +case $architectures in + 'arm64 x86_64'|'x86_64 arm64') ;; + *) fail "Expected exactly arm64 and x86_64, found: $architectures." ;; +esac umask 077 work=$(mktemp -d "$RUNNER_TEMP/agents-release.XXXXXX") diff --git a/Scripts/release-assets.sh b/Scripts/release-assets.sh index 6ae77df..ac84dac 100755 --- a/Scripts/release-assets.sh +++ b/Scripts/release-assets.sh @@ -9,21 +9,29 @@ candidate="$RUNNER_TEMP/distribution" repo="repos/$GITHUB_REPOSITORY" check_candidate() ( - expected_source=$(git rev-parse "$SOURCE_COMMIT" "refs/tags/$RELEASE_TAG") + packaging=$(sed -n '3p' "$candidate/source") + [[ $packaging =~ ^[a-f0-9]{40}$ && $packaging == "${1:-$packaging}" ]] || + fail "Candidate packaging commit differs from the original run." + Scripts/verify-release-source.sh "$packaging" + expected_source=$(git rev-parse "$SOURCE_COMMIT" "refs/tags/$RELEASE_TAG" "$packaging") cd "$candidate" - [[ "$(cat source)" == "$expected_source" ]] || fail "Candidate tag or source commit differs." + [[ "$(cat source)" == "$expected_source" ]] || fail "Candidate source, tag, or packaging commit differs." [[ $(shasum -a 256 "$zip") == "$(cat "$checksum")" ]] || fail "Candidate checksum does not match." ) restore_candidate() { [[ ${CANDIDATE_RUN_ID:-} =~ ^[0-9]+$ ]] || fail "Specify the run ID holding the signed candidate." - gh api "$repo/actions/runs/$CANDIDATE_RUN_ID" | jq -e --arg commit "$SOURCE_COMMIT" ' - .event == "workflow_dispatch" and .head_branch == "master" and .head_sha == $commit - and .path == ".github/workflows/release-gate.yml" - ' >/dev/null || fail "Candidate run does not match the approved master workflow and source." + packaging=$(gh api "$repo/actions/runs/$CANDIDATE_RUN_ID" | jq -er --arg repo "$GITHUB_REPOSITORY" ' + select( + .event == "workflow_dispatch" and .head_branch == "master" + and .repository.full_name == $repo and .head_repository.full_name == $repo + and .path == ".github/workflows/release-gate.yml" + ) | .head_sha + ') || fail "Candidate run does not match the approved master release workflow." + Scripts/verify-release-source.sh "$packaging" gh run download "$CANDIDATE_RUN_ID" --repo "$GITHUB_REPOSITORY" \ --name "agents-app-$RELEASE_TAG-signed" --dir "$candidate" - check_candidate + check_candidate "$packaging" } assert_asset_names() { diff --git a/Scripts/verify-release-source.sh b/Scripts/verify-release-source.sh index b2571db..a450ff5 100755 --- a/Scripts/verify-release-source.sh +++ b/Scripts/verify-release-source.sh @@ -3,6 +3,22 @@ set -euo pipefail fail() { echo "Release source verification failed: $1" >&2; exit 1; } +verify_packaging_commit() { + local packaging=$1 + [[ $packaging =~ ^[a-f0-9]{40}$ ]] || fail "Expected a full packaging commit SHA." + git merge-base --is-ancestor "$packaging" refs/remotes/origin/master || + fail "Packaging commit is outside origin/master." + git merge-base --is-ancestor "$SOURCE_COMMIT" "$packaging" || + fail "Tagged source is not an ancestor of the packaging commit." + git diff --no-ext-diff --no-renames --quiet "$SOURCE_COMMIT" "$packaging" -- . \ + ':(exclude,literal).github/workflows/release-gate.yml' \ + ':(exclude,literal)Documentation/Release.md' \ + ':(exclude,literal)Scripts/package-release.sh' \ + ':(exclude,literal)Scripts/release-assets.sh' \ + ':(exclude,literal)Scripts/verify-release-source.sh' || + fail "The packaging commit differs from the tagged source outside the release files." +} + [[ ${GITHUB_ACTIONS:-} == true && ${GITHUB_REPOSITORY:-} == agents-tools/app && ${GITHUB_EVENT_NAME:-} == workflow_dispatch && @@ -10,9 +26,8 @@ fail() { echo "Release source verification failed: $1" >&2; exit 1; } [[ ${RELEASE_TAG:-} =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || fail "Expected a version tag." [[ ${SOURCE_COMMIT:-} =~ ^[a-f0-9]{40}$ && ${GITHUB_SHA:-} == "$(git rev-parse HEAD)" ]] || fail "Expected full commit SHAs." -if [[ ${OPERATION:-publish} == publish ]]; then - [[ $SOURCE_COMMIT == "$GITHUB_SHA" ]] || fail "Approve the exact source commit on master." -fi +git merge-base --is-ancestor "$GITHUB_SHA" refs/remotes/origin/master || + fail "Dispatch commit is outside origin/master." git merge-base --is-ancestor "$SOURCE_COMMIT" refs/remotes/origin/master || fail "Source is outside origin/master." @@ -21,3 +36,16 @@ git fetch --quiet --no-tags origin "refs/tags/$RELEASE_TAG" [[ $(git rev-parse 'FETCH_HEAD^{commit}') == "$SOURCE_COMMIT" ]] || fail "Tag points to another commit." [[ $(git rev-parse FETCH_HEAD) == "$(git rev-parse "refs/tags/$RELEASE_TAG")" ]] || fail "Tag object changed after checkout." + +case ${OPERATION:-publish} in + publish) verify_packaging_commit "$GITHUB_SHA" ;; + verify-public) ;; + *) fail "Expected publish or verify-public." ;; +esac + +# Restored candidates carry the packaging revision from their original run. +if [[ $# == 1 ]]; then + verify_packaging_commit "$1" +elif [[ $# != 0 ]]; then + fail "Expected at most one original packaging commit." +fi