Skip to content

Commit f705bde

Browse files
Idempotent release action (#2353)
* Do not require the released commit to be at the tip of the branch. * Update comment. * If you release an old commit, it must be ready to go as is. * Tag the commit that updates gradle.properties. * Check out the specific commit instead of the branch. * Simplify. * We need to set the release branch. * You can't refer to outputs directly. * Make sure to tag the right commit. * Pass the commit SHA explicitly.
1 parent c060263 commit f705bde

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

.github/scripts/get-or-create-release-branch.sh

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ set -eux
88
# Compute the name of the release branch starting from the version that needs to be released ($SEMANTIC_VERSION).
99
# If it's the beginning of a new release series, the branch is created and pushed to the remote (chosen according to
1010
# the value $DRY_RUN).
11-
# If it isn't the beginning of a new release series, the script makes sure that the commit that will be tagged is at
12-
# the tip of the (pre-existing) release branch.
1311
#
1412
# The script populates an output file with key-value pairs that are needed in the release CI workflow to carry out
1513
# the next steps in the release flow: the name of the release branch and a boolean flag that is set to 'true' if this
@@ -57,16 +55,7 @@ if [[ "${DRY_RUN}" == "true" ]]; then
5755
git push --force origin "HEAD:refs/heads/${branch_name}"
5856
else
5957
commit_sha=$(git rev-parse --short HEAD)
60-
if git ls-remote --exit-code --heads origin "${branch_name}"; then
61-
# The release branch already exists, we need to make sure that our commit is its current tip
62-
branch_head_sha=$(git rev-parse --verify --short "refs/remotes/origin/${branch_name}")
63-
if [[ "${branch_head_sha}" != "${commit_sha}" ]]; then
64-
echo "The release branch - ${branch_name} - already exists. ${commit_sha}, the commit you chose when "
65-
echo "launching this release, is not its current HEAD (${branch_head_sha}). This is not allowed: you "
66-
echo "MUST release from the HEAD of the release branch if it already exists."
67-
exit 1
68-
fi
69-
else
58+
if ! git ls-remote --exit-code --heads origin "${branch_name}"; then
7059
# The release branch does not exist.
7160
# We need to make sure that the commit SHA that we are releasing is on `main`.
7261
git fetch origin main
@@ -75,7 +64,7 @@ else
7564
git checkout -b "${branch_name}"
7665
git push origin "${branch_name}"
7766
else
78-
echo "You must choose a commit from main to create a new release series!"
67+
echo "You must choose a commit from main to create a new release branch!"
7968
exit 1
8069
fi
8170
fi

.github/workflows/release.yml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@ jobs:
113113
runs-on: ubuntu-latest
114114
outputs:
115115
release_branch: ${{ needs.get-or-create-release-branch.outputs.release_branch }}
116+
commit_sha: ${{ steps.gradle-push.outputs.commit_sha }}
116117
steps:
117118
- uses: actions/checkout@v3
118119
with:
119-
ref: ${{ needs.get-or-create-release-branch.outputs.release_branch }}
120+
ref: ${{ inputs.commit_sha }}
120121
path: smithy-rs
122+
fetch-depth: 0
121123
token: ${{ secrets.RELEASE_AUTOMATION_BOT_PAT }}
122124
- name: Upgrade gradle.properties
123125
uses: ./smithy-rs/.github/actions/docker-build
@@ -132,13 +134,30 @@ jobs:
132134
shell: bash
133135
env:
134136
SEMANTIC_VERSION: ${{ inputs.semantic_version }}
137+
RELEASE_COMMIT_SHA: ${{ inputs.commit_sha }}
138+
RELEASE_BRANCH_NAME: ${{ needs.get-or-create-release-branch.outputs.release_branch }}
135139
DRY_RUN: ${{ inputs.dry_run }}
136140
run: |
137141
set -x
142+
138143
# For debugging purposes
139144
git status
140-
# The file was actually changed, we need to commit the changes
141-
git diff-index --quiet HEAD || { git -c 'user.name=AWS SDK Rust Bot' -c 'user.email=aws-sdk-rust-primary@amazon.com' commit gradle.properties --message "Upgrade the smithy-rs runtime crates version to ${SEMANTIC_VERSION}" && git push origin; }
145+
146+
if ! git diff-index --quiet HEAD; then
147+
# gradle.properties was changed, we need to commit and push the diff
148+
git -c 'user.name=AWS SDK Rust Bot' -c 'user.email=aws-sdk-rust-primary@amazon.com' commit gradle.properties --message "Upgrade the smithy-rs runtime crates version to ${SEMANTIC_VERSION}"
149+
150+
# This will fail if we tried to release from a non-HEAD commit on the release branch.
151+
# The only scenario where we would try to release a non-HEAD commit from the release branch is
152+
# to retry a release action execution that failed due to a transient issue.
153+
# In that case, we expect the commit to be releasable as-is, i.e. the runtime crate version in gradle.properties
154+
# should already be the expected one.
155+
git push origin "HEAD:refs/heads/${RELEASE_BRANCH_NAME}"
156+
157+
echo "commit_sha=$(git rev-parse HEAD)" > $GITHUB_OUTPUT
158+
else
159+
echo "commit_sha=${RELEASE_COMMIT_SHA}" > $GITHUB_OUTPUT
160+
fi
142161
143162
release:
144163
name: Release
@@ -159,7 +178,7 @@ jobs:
159178
- name: Checkout smithy-rs
160179
uses: actions/checkout@v3
161180
with:
162-
ref: ${{ needs.upgrade-gradle-properties.outputs.release_branch }}
181+
ref: ${{ needs.upgrade-gradle-properties.outputs.commit_sha }}
163182
path: smithy-rs
164183
token: ${{ secrets.RELEASE_AUTOMATION_BOT_PAT }}
165184
- name: Generate release artifacts
@@ -171,9 +190,20 @@ jobs:
171190
- name: Push smithy-rs changes
172191
shell: bash
173192
working-directory: smithy-rs-release/smithy-rs
193+
id: push-changelog
194+
env:
195+
RELEASE_BRANCH_NAME: ${{ needs.upgrade-gradle-properties.outputs.release_branch }}
174196
run: |
175-
echo "Pushing release commits..."
176-
git push origin
197+
if ! git diff-index --quiet HEAD; then
198+
echo "Pushing release commits..."
199+
# This will fail if we tried to release from a non-HEAD commit on the release branch.
200+
# The only scenario where we would try to release a non-HEAD commit from the release branch is
201+
# to retry a release action execution that failed due to a transient issue.
202+
# In that case, we expect the commit to be releasable as-is, i.e. the changelog should have already
203+
# been processed.
204+
git push origin "HEAD:refs/heads/${RELEASE_BRANCH_NAME}"
205+
fi
206+
echo "commit_sha=$(git rev-parse HEAD)" > $GITHUB_OUTPUT
177207
- name: Tag release
178208
uses: actions/github-script@v6
179209
with:
@@ -184,7 +214,7 @@ jobs:
184214
github,
185215
isDryRun: ${{ inputs.dry_run }},
186216
releaseManifestPath: "smithy-rs-release/smithy-rs-release-manifest.json"
187-
releaseCommitish: ${{ needs.upgrade-gradle-properties.outputs.release_branch }},
217+
releaseCommitish: ${{ steps.push-changelog.outputs.commit_sha }}
188218
});
189219
- name: Publish to crates.io
190220
shell: bash

0 commit comments

Comments
 (0)