|
| 1 | +# Manually triggered to cut a release. Bumps the version and changelog in place on |
| 2 | +# the trunk (no release PR), commits to the trunk, then starts the CodePipelines. |
| 3 | +# Replaces "Create Release PR" + "Sync dev and the trunk". This workflow creates the |
| 4 | +# git tag + GitHub Release (computed by AutoVer while the change files still exist), |
| 5 | +# then starts the pipelines to publish to NuGet. |
| 6 | +# |
| 7 | +# aws-lambda-dotnet has three pipelines fed by this one repo/branch (the main library, |
| 8 | +# the PowerShell module, and the test tool). One version bump + changelog + tag covers |
| 9 | +# the repo; all three pipelines are started from the single pushed commit. |
| 10 | +name: Execute Release |
| 11 | + |
| 12 | +# Dispatch from the trunk (master). Check "hold" to stage the release at the pipeline |
| 13 | +# Hold gate for a timed go-ahead instead of publishing right away. |
| 14 | +on: |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + hold: |
| 18 | + description: "Stage at the Hold gate for a timed go-ahead (do not auto-publish)" |
| 19 | + type: boolean |
| 20 | + default: false |
| 21 | + OVERRIDE_VERSION: |
| 22 | + description: "Override Version" |
| 23 | + type: string |
| 24 | + required: false |
| 25 | + |
| 26 | +# Least-privilege at the workflow level; the one job below grants only what it needs. |
| 27 | +permissions: {} |
| 28 | + |
| 29 | +# Only one release may run at a time. Do not cancel an in-progress release: it may be |
| 30 | +# mid-push to the trunk or mid-pipeline-start, and cancelling could leave things half-done. |
| 31 | +concurrency: |
| 32 | + group: execute-release |
| 33 | + cancel-in-progress: false |
| 34 | + |
| 35 | +env: |
| 36 | + # The CodePipelines to start (space-separated). The target account is the one the |
| 37 | + # assumed role lives in; the role must allow StartPipelineExecution on all of them. |
| 38 | + PIPELINE_NAMES: "aws-lambda-dotnet aws-lambda-dotnet-powershell aws-lambda-testtool" |
| 39 | + AWS_REGION: us-west-2 |
| 40 | + INPUT_OVERRIDE_VERSION: ${{ github.event.inputs.OVERRIDE_VERSION }} |
| 41 | + |
| 42 | +jobs: |
| 43 | + execute-release: |
| 44 | + name: Execute Release |
| 45 | + runs-on: ubuntu-latest |
| 46 | + permissions: |
| 47 | + id-token: write # mint the OIDC token used to assume the AWS roles below |
| 48 | + contents: write # push the version + changelog commit to the trunk |
| 49 | + steps: |
| 50 | + # Assume an AWS role that can read the deploy key and start the pipelines. |
| 51 | + - name: Configure AWS Credentials |
| 52 | + uses: aws-actions/configure-aws-credentials@254c19bd240aabef8777f48595e9d2d7b972184b # v6.2.1 |
| 53 | + with: |
| 54 | + # zizmor: ignore[secrets-outside-env] secret is a role ARN (an identifier, not |
| 55 | + # a credential); access is gated by the role's AWS OIDC trust policy, so a |
| 56 | + # dedicated GitHub environment adds no meaningful protection here. |
| 57 | + role-to-assume: ${{ secrets.RELEASE_WORKFLOW_ACCESS_TOKEN_ROLE_ARN }} |
| 58 | + aws-region: us-west-2 |
| 59 | + # Retrieve the per-repo deploy key from Secrets Manager (push to the trunk runs over SSH). |
| 60 | + - name: Retrieve secrets from AWS Secrets Manager |
| 61 | + uses: aws-actions/aws-secretsmanager-get-secrets@2cb1a461cbd4865ac4299648312e4704c646cd53 #v3 |
| 62 | + with: |
| 63 | + secret-ids: | |
| 64 | + DEPLOY_KEY, prod/devops/aws-lambda-dotnet-deploy-key |
| 65 | + # Full clone of the trunk using the deploy key. |
| 66 | + - name: Checkout # zizmor: ignore[artipacked] persist-credentials must stay true for the deploy-key push |
| 67 | + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 #v7.0.0 |
| 68 | + with: |
| 69 | + ref: master |
| 70 | + fetch-depth: '0' |
| 71 | + ssh-key: ${{ env.DEPLOY_KEY }} |
| 72 | + # Keep the SSH deploy-key config in the local git config so the later |
| 73 | + # "git push origin HEAD:master" can authenticate with it. (There is no |
| 74 | + # GITHUB_TOKEN persisted here to worry about - auth is the deploy key.) |
| 75 | + persist-credentials: true |
| 76 | + # .NET 9 is needed for AutoVer. |
| 77 | + - name: Setup .NET 9.0 |
| 78 | + uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 #v5 |
| 79 | + with: |
| 80 | + dotnet-version: 9.0.x |
| 81 | + - name: Install AutoVer |
| 82 | + run: dotnet tool install --global AutoVer --version 0.0.24 |
| 83 | + - name: Setup Git User |
| 84 | + run: | |
| 85 | + git config --global user.email "[email protected]" |
| 86 | + git config --global user.name "aws-sdk-dotnet-automation" |
| 87 | + # Bump the version from the change files (or an explicit override). autover commits the |
| 88 | + # version bump itself. |
| 89 | + - name: Increment Version |
| 90 | + run: autover version |
| 91 | + if: env.INPUT_OVERRIDE_VERSION == '' |
| 92 | + - name: Increment Version (override) |
| 93 | + run: autover version --use-version "$INPUT_OVERRIDE_VERSION" |
| 94 | + if: env.INPUT_OVERRIDE_VERSION != '' |
| 95 | + # Capture the release tag/name/notes from AutoVer NOW, while the change files still |
| 96 | + # exist - autover derives these from the pending change files. The next step consumes |
| 97 | + # them, after which autover would only see the previous release. (--tag-name / |
| 98 | + # --release-name / --output-to-console are read-only and do not consume.) |
| 99 | + - name: Compute release metadata |
| 100 | + id: relmeta |
| 101 | + run: | |
| 102 | + { |
| 103 | + echo "tag=$(autover changelog --tag-name)" |
| 104 | + echo "name=$(autover changelog --release-name)" |
| 105 | + } >> "$GITHUB_OUTPUT" |
| 106 | + autover changelog --output-to-console > "$RUNNER_TEMP/release_notes.md" |
| 107 | + # autover changelog updates CHANGELOG.md, deletes the consumed change files, and commits both. |
| 108 | + - name: Update Changelog |
| 109 | + run: autover changelog |
| 110 | + # autover already committed the version bump + changelog (incl. the change-file deletions), |
| 111 | + # so just push those commits straight to the trunk. No release PR, and no tag push here: |
| 112 | + # the pipeline tags and creates the GitHub Release after publish. |
| 113 | + - name: Push version and changelog |
| 114 | + run: git push origin HEAD:master |
| 115 | + # Switch identities: assume the pipeline account's Execute Release role (GitHub OIDC) |
| 116 | + # so the pipeline calls below run same-account. The role above (release-workflow) only |
| 117 | + # reads the deploy key; this one only starts these pipelines. |
| 118 | + - name: Configure AWS Credentials for the pipeline account |
| 119 | + uses: aws-actions/configure-aws-credentials@254c19bd240aabef8777f48595e9d2d7b972184b # v6.2.1 |
| 120 | + with: |
| 121 | + # zizmor: ignore[secrets-outside-env] role ARN, gated by AWS OIDC trust policy. |
| 122 | + role-to-assume: ${{ secrets.EXECUTE_RELEASE_ROLE_ARN }} |
| 123 | + aws-region: us-west-2 |
| 124 | + # Freeze-aware, per pipeline: if a pipeline's Release-stage transition is disabled |
| 125 | + # (re:Invent or a staging embargo), skip starting that pipeline. Start passes HOLD so |
| 126 | + # the auto-approve Lambda knows whether to publish immediately (hold=false) or wait |
| 127 | + # at the gate (hold=true). |
| 128 | + - name: Start pipelines |
| 129 | + env: |
| 130 | + # Route the workflow input through an env var instead of interpolating |
| 131 | + # ${{ github.* }} directly into the shell, to avoid script injection. |
| 132 | + HOLD: ${{ github.event.inputs.hold }} |
| 133 | + run: | |
| 134 | + for p in $PIPELINE_NAMES; do |
| 135 | + enabled=$(aws codepipeline get-pipeline-state --name "$p" --region "$AWS_REGION" \ |
| 136 | + --query "stageStates[?stageName=='Release'].inboundTransitionState.enabled | [0]" --output text) |
| 137 | + if [ "$enabled" = "False" ]; then |
| 138 | + echo "::warning::$p Release-stage transition is disabled (frozen); skipping." |
| 139 | + continue |
| 140 | + fi |
| 141 | + echo "Starting $p (HOLD=$HOLD)" |
| 142 | + aws codepipeline start-pipeline-execution --name "$p" --region "$AWS_REGION" \ |
| 143 | + --variables "name=HOLD,value=$HOLD" |
| 144 | + done |
| 145 | + # Create the tag + GitHub Release at the pushed commit, using the metadata captured |
| 146 | + # before the change files were consumed. |
| 147 | + - name: Create GitHub release |
| 148 | + env: |
| 149 | + GH_TOKEN: ${{ github.token }} |
| 150 | + RELEASE_TAG: ${{ steps.relmeta.outputs.tag }} |
| 151 | + RELEASE_NAME: ${{ steps.relmeta.outputs.name }} |
| 152 | + run: | |
| 153 | + gh release create "$RELEASE_TAG" \ |
| 154 | + --title "$RELEASE_NAME" \ |
| 155 | + --notes-file "$RUNNER_TEMP/release_notes.md" \ |
| 156 | + --target "$(git rev-parse HEAD)" |
0 commit comments