summaryrefslogtreecommitdiff
path: root/.github/workflows/promote-release.yml
blob: 8c1f4c1c49d496b3e5e0796791e422fe4f068b8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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:-<none>}\`"
            echo "- Public $BRANCH branch: \`${PRIOR_RELEASE_BRANCH:-<create on promotion>}\`"
            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"