|
| 1 | +name: Rollback release |
| 2 | +on: |
| 3 | + # You can trigger this workflow via workflow dispatch to start a rollback. |
| 4 | + # This will create a draft release that mirrors the release for `rollback-tag`. |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + rollback-tag: |
| 8 | + type: string |
| 9 | + description: "The tag of an old release to roll-back to." |
| 10 | + required: true |
| 11 | + # Only for dry-runs of changes to the workflow. |
| 12 | + push: |
| 13 | + paths: |
| 14 | + - .github/workflows/rollback-release.yml |
| 15 | + - .github/actions/prepare-mergeback-branch/** |
| 16 | + |
| 17 | +jobs: |
| 18 | + prepare: |
| 19 | + name: "Prepare release" |
| 20 | + if: github.repository == 'github/codeql-action' |
| 21 | + |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + |
| 25 | + uses: ./.github/workflows/prepare-release.yml |
| 26 | + |
| 27 | + rollback: |
| 28 | + name: "Create rollback release" |
| 29 | + if: github.repository == 'github/codeql-action' |
| 30 | + runs-on: ubuntu-latest |
| 31 | + timeout-minutes: 45 |
| 32 | + |
| 33 | + # Don't set the deployment environment for test runs |
| 34 | + # The Actions token does not have permissions to push changes to workflow files. |
| 35 | + # Since workflow files may change as part of a backport PR, we use the "Automation" environment for real runs to authenticate as a GitHub App and push these changes. |
| 36 | + environment: ${{ github.event_name == 'workflow_dispatch' && 'Automation' || '' }} |
| 37 | + |
| 38 | + needs: |
| 39 | + - prepare |
| 40 | + |
| 41 | + permissions: |
| 42 | + contents: write # needed to push to the repo (tags and releases) |
| 43 | + pull-requests: write # needed to create the mergeback PR |
| 44 | + |
| 45 | + steps: |
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@v5 |
| 48 | + with: |
| 49 | + fetch-depth: 0 # Need full history for calculation of diffs |
| 50 | + |
| 51 | + - name: Configure runner for release |
| 52 | + uses: ./.github/actions/release-initialise |
| 53 | + |
| 54 | + - name: Create tag for testing |
| 55 | + if: github.event_name != 'workflow_dispatch' |
| 56 | + shell: bash |
| 57 | + run: git tag v0.0.0 |
| 58 | + |
| 59 | + # We start by preparing the mergeback branch, mainly so that we have the updated changelog |
| 60 | + # readily available for the partial changelog that's needed for the release. |
| 61 | + - name: Prepare mergeback branch |
| 62 | + id: mergeback-branch |
| 63 | + env: |
| 64 | + BASE_BRANCH: ${{ (github.event_name == 'workflow_dispatch' && 'main') || github.ref_name }} |
| 65 | + VERSION: ${{ needs.prepare.outputs.version }} |
| 66 | + run: | |
| 67 | + set -x |
| 68 | +
|
| 69 | + # Checkout the base branch, since we may be testing on a different branch |
| 70 | + git checkout "$BASE_BRANCH" |
| 71 | +
|
| 72 | + # Generate a new branch name for the mergeback PR |
| 73 | + short_sha="${GITHUB_SHA:0:8}" |
| 74 | + NEW_BRANCH="mergeback/${VERSION}-to-${BASE_BRANCH}-${short_sha}" |
| 75 | + echo "new-branch=${NEW_BRANCH}" >> $GITHUB_OUTPUT |
| 76 | +
|
| 77 | + # Create the mergeback branch |
| 78 | + git checkout -b "${NEW_BRANCH}" |
| 79 | +
|
| 80 | + - name: Prepare rollback changelog |
| 81 | + env: |
| 82 | + NEW_CHANGELOG: "${{ runner.temp }}/new_changelog.md" |
| 83 | + # We usually expect to checkout `inputs.rollback-tag` (required for `workflow_dispatch`), |
| 84 | + # but use `v0.0.0` for testing. |
| 85 | + ROLLBACK_TAG: ${{ inputs.rollback-tag || 'v0.0.0' }} |
| 86 | + LATEST_TAG: ${{ needs.prepare.outputs.latest_tag }} |
| 87 | + VERSION: "${{ needs.prepare.outputs.version }}" |
| 88 | + run: | |
| 89 | + python .github/workflows/script/rollback_changelog.py \ |
| 90 | + --target-version "${ROLLBACK_TAG:1}" \ |
| 91 | + --rollback-version "${LATEST_TAG:1}" \ |
| 92 | + --new-version "$VERSION" > $NEW_CHANGELOG |
| 93 | +
|
| 94 | + echo "::group::New CHANGELOG" |
| 95 | + cat $NEW_CHANGELOG |
| 96 | + echo "::endgroup::" |
| 97 | +
|
| 98 | + - name: Create tags |
| 99 | + shell: bash |
| 100 | + env: |
| 101 | + # We usually expect to checkout `inputs.rollback-tag` (required for `workflow_dispatch`), |
| 102 | + # but use `v0.0.0` for testing. |
| 103 | + ROLLBACK_TAG: ${{ inputs.rollback-tag || 'v0.0.0' }} |
| 104 | + RELEASE_TAG: ${{ needs.prepare.outputs.version }} |
| 105 | + MAJOR_VERSION_TAG: ${{ needs.prepare.outputs.major_version }} |
| 106 | + run: | |
| 107 | + git checkout "refs/tags/${ROLLBACK_TAG}" |
| 108 | + git tag --annotate "${RELEASE_TAG}" --message "${RELEASE_TAG}" |
| 109 | + git tag --annotate "${MAJOR_VERSION_TAG}" --message "${MAJOR_VERSION_TAG}" --force |
| 110 | +
|
| 111 | + - name: Push tags |
| 112 | + # skip when testing |
| 113 | + if: github.event_name == 'workflow_dispatch' |
| 114 | + shell: bash |
| 115 | + env: |
| 116 | + RELEASE_TAG: ${{ needs.prepare.outputs.version }} |
| 117 | + MAJOR_VERSION_TAG: ${{ needs.prepare.outputs.major_version }} |
| 118 | + run: | |
| 119 | + git push origin --atomic --force refs/tags/"${RELEASE_TAG}" refs/tags/"${MAJOR_VERSION_TAG}" |
| 120 | +
|
| 121 | + - name: Prepare partial Changelog |
| 122 | + env: |
| 123 | + NEW_CHANGELOG: "${{ runner.temp }}/new_changelog.md" |
| 124 | + PARTIAL_CHANGELOG: "${{ runner.temp }}/partial_changelog.md" |
| 125 | + VERSION: "${{ needs.prepare.outputs.version }}" |
| 126 | + run: | |
| 127 | + python .github/workflows/script/prepare_changelog.py $NEW_CHANGELOG "$VERSION" > $PARTIAL_CHANGELOG |
| 128 | +
|
| 129 | + echo "::group::Partial CHANGELOG" |
| 130 | + cat $PARTIAL_CHANGELOG |
| 131 | + echo "::endgroup::" |
| 132 | +
|
| 133 | + - name: Generate token |
| 134 | + if: github.event_name == 'workflow_dispatch' |
| 135 | + |
| 136 | + id: app-token |
| 137 | + with: |
| 138 | + app-id: ${{ vars.AUTOMATION_APP_ID }} |
| 139 | + private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }} |
| 140 | + |
| 141 | + - name: Create the rollback release |
| 142 | + if: github.event_name == 'workflow_dispatch' |
| 143 | + env: |
| 144 | + PARTIAL_CHANGELOG: "${{ runner.temp }}/partial_changelog.md" |
| 145 | + VERSION: "${{ needs.prepare.outputs.version }}" |
| 146 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 147 | + RELEASE_URL: "${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ needs.prepare.outputs.version }}" |
| 148 | + run: | |
| 149 | + set -exu |
| 150 | +
|
| 151 | + # Do not mark this release as latest. The most recent bundle release must be marked as latest. |
| 152 | + # Set as a draft to give us an opportunity to review the rollback release. |
| 153 | + gh release create \ |
| 154 | + "$VERSION" \ |
| 155 | + --latest=false \ |
| 156 | + --draft \ |
| 157 | + --title "$VERSION" \ |
| 158 | + --notes-file "$PARTIAL_CHANGELOG" |
| 159 | +
|
| 160 | + echo "Created draft rollback release at $RELEASE_URL" >> $GITHUB_STEP_SUMMARY |
| 161 | +
|
| 162 | + - name: Update changelog |
| 163 | + shell: bash |
| 164 | + env: |
| 165 | + NEW_CHANGELOG: "${{ runner.temp }}/new_changelog.md" |
| 166 | + NEW_BRANCH: "${{ steps.mergeback-branch.outputs.new-branch }}" |
| 167 | + run: | |
| 168 | + git checkout "${NEW_BRANCH}" |
| 169 | + mv ${NEW_CHANGELOG} CHANGELOG.md |
| 170 | +
|
| 171 | + - name: Create mergeback branch and PR |
| 172 | + uses: ./.github/actions/prepare-mergeback-branch |
| 173 | + with: |
| 174 | + base: "main" |
| 175 | + head: "" |
| 176 | + branch: "${{ steps.mergeback-branch.outputs.new-branch }}" |
| 177 | + version: "${{ needs.prepare.outputs.version }}" |
| 178 | + token: "${{ secrets.GITHUB_TOKEN }}" |
| 179 | + # Setting this to `true` for non-workflow_dispatch events will |
| 180 | + # still push the `branch`, but won't create a corresponding PR |
| 181 | + dry-run: "${{ github.event_name != 'workflow_dispatch' }}" |
| 182 | + |
0 commit comments