name: Promote Release Source on: workflow_dispatch: inputs: version: description: "Version without v (X.Y.Z, X.Y.Z-betaN, or X.Y.Z-rcN)" required: true type: string candidate_run_id: description: "Successful Prepare Release Candidate workflow run" required: true type: string operation: description: "Validate only, or copy the exact source tag to the public repository" required: true type: choice options: [validate, promote] default: validate permissions: actions: read contents: read jobs: validate: runs-on: ubuntu-latest timeout-minutes: 20 outputs: sha: ${{ steps.candidate.outputs.sha }} public_tag: ${{ steps.candidate.outputs.public_tag }} channel: ${{ steps.candidate.outputs.channel }} prior_master: ${{ steps.public.outputs.prior_master }} prior_release_branch: ${{ steps.public.outputs.prior_release_branch }} tag_exists: ${{ steps.public.outputs.tag_exists }} advance_master: ${{ steps.public.outputs.advance_master }} newest_ga_line: ${{ steps.public.outputs.newest_ga_line }} legacy_tag_only: ${{ steps.public.outputs.legacy_tag_only }} public_refs_digest: ${{ steps.public.outputs.public_refs_digest }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: fetch-depth: 0 - name: Validate candidate run and immutable tag id: candidate env: GH_TOKEN: ${{ github.token }} VERSION: ${{ inputs.version }} RUN_ID: ${{ inputs.candidate_run_id }} run: | set -euo pipefail if [[ ! "$RUN_ID" =~ ^[0-9]+$ ]]; then echo "::error::candidate_run_id must be numeric" exit 1 fi IDENTITY=$(python3 .github/scripts/release-policy.py classify "$VERSION") BRANCH=$(jq -r .release_branch <<<"$IDENTITY") CHANNEL=$(jq -r .channel <<<"$IDENTITY") TAG="build/v$VERSION" RUN=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$RUN_ID") if [ "$(jq -r .path <<<"$RUN")" != ".github/workflows/release-tag-helper.yml" ] || \ [ "$(jq -r .conclusion <<<"$RUN")" != success ]; then echo "::error::Run $RUN_ID must be a successful release-tag-helper.yml run" exit 1 fi RUN_SHA=$(jq -r .head_sha <<<"$RUN") git fetch origin "+refs/tags/$TAG:refs/tags/$TAG" "+refs/heads/$BRANCH:refs/remotes/origin/$BRANCH" TAG_SHA=$(git rev-parse "$TAG^{commit}") BRANCH_SHA=$(git rev-parse "origin/$BRANCH^{commit}") if [ "$GITHUB_REF" != "refs/heads/$BRANCH" ] || [ "$GITHUB_SHA" != "$BRANCH_SHA" ]; then echo "::error::Run this workflow from the current $BRANCH tip at $BRANCH_SHA" exit 1 fi if [ "$TAG_SHA" != "$RUN_SHA" ]; then echo "::error::$TAG resolves to $TAG_SHA but run $RUN_ID built $RUN_SHA" exit 1 fi git checkout --detach "$TAG_SHA" python3 .github/scripts/release-policy.py validate-source "$VERSION" CANDIDATE_DIR="$RUNNER_TEMP/release-candidate" gh run download "$RUN_ID" --name "release-candidate-$VERSION" --dir "$CANDIDATE_DIR" PROVENANCE=$(find "$CANDIDATE_DIR" -name candidate-provenance.json -type f -print -quit) if [ -z "$PROVENANCE" ]; then echo "::error::Candidate provenance was not found in run $RUN_ID" exit 1 fi test "$(jq -r .tag "$PROVENANCE")" = "$TAG" test "$(jq -r .commit "$PROVENANCE")" = "$TAG_SHA" test "$(jq -r .version "$PROVENANCE")" = "$VERSION" python3 .github/scripts/release-linux-images.py verify-provenance \ release-linux-images.json "$PROVENANCE" python3 .github/scripts/release-linux-images.py validate \ release-linux-images.json --check-remote { echo "sha=$TAG_SHA" echo "tag=$TAG" echo "public_tag=v$VERSION" echo "branch=$BRANCH" echo "channel=$CHANNEL" } >> "$GITHUB_OUTPUT" - name: Validate public ref state id: public env: VERSION: ${{ inputs.version }} SHA: ${{ steps.candidate.outputs.sha }} run: | set -euo pipefail git remote add public https://github.com/WSJTX/wsjtx.git PLAN=$(python3 .github/scripts/release-policy.py plan-public-promotion \ "$VERSION" --sha "$SHA" --remote public) { echo "prior_master=$(jq -r '.prior_master // ""' <<<"$PLAN")" echo "prior_release_branch=$(jq -r '.prior_release_branch // ""' <<<"$PLAN")" echo "tag_exists=$(jq -r .tag_exists <<<"$PLAN")" echo "advance_master=$(jq -r .advance_master <<<"$PLAN")" echo "newest_ga_line=$(jq -r .newest_ga_line <<<"$PLAN")" echo "legacy_tag_only=$(jq -r .legacy_tag_only <<<"$PLAN")" echo "public_refs_digest=$(jq -r .public_refs_digest <<<"$PLAN")" } >> "$GITHUB_OUTPUT" - name: Summarize validation env: VERSION: ${{ inputs.version }} RUN_ID: ${{ inputs.candidate_run_id }} SHA: ${{ steps.candidate.outputs.sha }} CHANNEL: ${{ steps.candidate.outputs.channel }} BRANCH: ${{ steps.candidate.outputs.branch }} PRIOR_MASTER: ${{ steps.public.outputs.prior_master }} PRIOR_RELEASE_BRANCH: ${{ steps.public.outputs.prior_release_branch }} TAG_EXISTS: ${{ steps.public.outputs.tag_exists }} ADVANCE_MASTER: ${{ steps.public.outputs.advance_master }} NEWEST_GA_LINE: ${{ steps.public.outputs.newest_ga_line }} LEGACY_TAG_ONLY: ${{ steps.public.outputs.legacy_tag_only }} run: | { echo "## Public source validation" echo echo "- Version: \`$VERSION\` ($CHANNEL)" echo "- Candidate run: [\`$RUN_ID\`]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$RUN_ID)" echo "- Exact commit: \`$SHA\`" echo "- Public tag: \`v$VERSION\`" echo "- Prior public master: \`${PRIOR_MASTER:-}\`" echo "- Public $BRANCH branch: \`${PRIOR_RELEASE_BRANCH:-}\`" echo "- Newest public GA line: $NEWEST_GA_LINE$([ "$LEGACY_TAG_ONLY" = true ] && echo ' (legacy tag-only state)')" if [ "$TAG_EXISTS" = true ]; then echo "- Existing public tag: already resolves to the exact candidate SHA" else echo "- Existing public tag: will be created" fi if [ "$CHANNEL" = GA ] && [ "$ADVANCE_MASTER" = true ]; then echo "- Public master: advance by fast-forward with the newest-line GA" elif [ "$CHANNEL" = GA ]; then echo "- Public master: leave unchanged; this is an older-line GA" else echo "- Public master: leave unchanged for a beta or RC" fi } >> "$GITHUB_STEP_SUMMARY" promote: if: inputs.operation == 'promote' needs: validate concurrency: group: public-release-source-promotion cancel-in-progress: false runs-on: ubuntu-latest timeout-minutes: 10 environment: source-promotion steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: fetch-depth: 0 ref: ${{ needs.validate.outputs.sha }} persist-credentials: false - name: Promote exact source commit env: TOKEN: ${{ secrets.CROSS_REPO_TOKEN }} SHA: ${{ needs.validate.outputs.sha }} VERSION: ${{ inputs.version }} PUBLIC_REFS_DIGEST: ${{ needs.validate.outputs.public_refs_digest }} run: | set -euo pipefail if [ -z "$TOKEN" ]; then echo "::error::CROSS_REPO_TOKEN is required for source promotion" exit 1 fi git remote add public "https://x-access-token:${TOKEN}@github.com/WSJTX/wsjtx.git" python3 .github/scripts/release-policy.py promote-public-source \ "$VERSION" --sha "$SHA" --remote public \ --expected-refs-digest "$PUBLIC_REFS_DIGEST"