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.
This commit is contained in:
Luca Palmieri 2023-02-13 17:33:14 +00:00 committed by GitHub
parent c060263f35
commit f705bde5ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 20 deletions

View File

@ -8,8 +8,6 @@ set -eux
# Compute the name of the release branch starting from the version that needs to be released ($SEMANTIC_VERSION).
# If it's the beginning of a new release series, the branch is created and pushed to the remote (chosen according to
# the value $DRY_RUN).
# If it isn't the beginning of a new release series, the script makes sure that the commit that will be tagged is at
# the tip of the (pre-existing) release branch.
#
# The script populates an output file with key-value pairs that are needed in the release CI workflow to carry out
# 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
git push --force origin "HEAD:refs/heads/${branch_name}"
else
commit_sha=$(git rev-parse --short HEAD)
if git ls-remote --exit-code --heads origin "${branch_name}"; then
# The release branch already exists, we need to make sure that our commit is its current tip
branch_head_sha=$(git rev-parse --verify --short "refs/remotes/origin/${branch_name}")
if [[ "${branch_head_sha}" != "${commit_sha}" ]]; then
echo "The release branch - ${branch_name} - already exists. ${commit_sha}, the commit you chose when "
echo "launching this release, is not its current HEAD (${branch_head_sha}). This is not allowed: you "
echo "MUST release from the HEAD of the release branch if it already exists."
exit 1
fi
else
if ! git ls-remote --exit-code --heads origin "${branch_name}"; then
# The release branch does not exist.
# We need to make sure that the commit SHA that we are releasing is on `main`.
git fetch origin main
@ -75,7 +64,7 @@ else
git checkout -b "${branch_name}"
git push origin "${branch_name}"
else
echo "You must choose a commit from main to create a new release series!"
echo "You must choose a commit from main to create a new release branch!"
exit 1
fi
fi

View File

@ -113,11 +113,13 @@ jobs:
runs-on: ubuntu-latest
outputs:
release_branch: ${{ needs.get-or-create-release-branch.outputs.release_branch }}
commit_sha: ${{ steps.gradle-push.outputs.commit_sha }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.get-or-create-release-branch.outputs.release_branch }}
ref: ${{ inputs.commit_sha }}
path: smithy-rs
fetch-depth: 0
token: ${{ secrets.RELEASE_AUTOMATION_BOT_PAT }}
- name: Upgrade gradle.properties
uses: ./smithy-rs/.github/actions/docker-build
@ -132,13 +134,30 @@ jobs:
shell: bash
env:
SEMANTIC_VERSION: ${{ inputs.semantic_version }}
RELEASE_COMMIT_SHA: ${{ inputs.commit_sha }}
RELEASE_BRANCH_NAME: ${{ needs.get-or-create-release-branch.outputs.release_branch }}
DRY_RUN: ${{ inputs.dry_run }}
run: |
set -x
# For debugging purposes
git status
# The file was actually changed, we need to commit the changes
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; }
if ! git diff-index --quiet HEAD; then
# gradle.properties was changed, we need to commit and push the diff
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}"
# This will fail if we tried to release from a non-HEAD commit on the release branch.
# The only scenario where we would try to release a non-HEAD commit from the release branch is
# to retry a release action execution that failed due to a transient issue.
# In that case, we expect the commit to be releasable as-is, i.e. the runtime crate version in gradle.properties
# should already be the expected one.
git push origin "HEAD:refs/heads/${RELEASE_BRANCH_NAME}"
echo "commit_sha=$(git rev-parse HEAD)" > $GITHUB_OUTPUT
else
echo "commit_sha=${RELEASE_COMMIT_SHA}" > $GITHUB_OUTPUT
fi
release:
name: Release
@ -159,7 +178,7 @@ jobs:
- name: Checkout smithy-rs
uses: actions/checkout@v3
with:
ref: ${{ needs.upgrade-gradle-properties.outputs.release_branch }}
ref: ${{ needs.upgrade-gradle-properties.outputs.commit_sha }}
path: smithy-rs
token: ${{ secrets.RELEASE_AUTOMATION_BOT_PAT }}
- name: Generate release artifacts
@ -171,9 +190,20 @@ jobs:
- name: Push smithy-rs changes
shell: bash
working-directory: smithy-rs-release/smithy-rs
id: push-changelog
env:
RELEASE_BRANCH_NAME: ${{ needs.upgrade-gradle-properties.outputs.release_branch }}
run: |
echo "Pushing release commits..."
git push origin
if ! git diff-index --quiet HEAD; then
echo "Pushing release commits..."
# This will fail if we tried to release from a non-HEAD commit on the release branch.
# The only scenario where we would try to release a non-HEAD commit from the release branch is
# to retry a release action execution that failed due to a transient issue.
# In that case, we expect the commit to be releasable as-is, i.e. the changelog should have already
# been processed.
git push origin "HEAD:refs/heads/${RELEASE_BRANCH_NAME}"
fi
echo "commit_sha=$(git rev-parse HEAD)" > $GITHUB_OUTPUT
- name: Tag release
uses: actions/github-script@v6
with:
@ -184,7 +214,7 @@ jobs:
github,
isDryRun: ${{ inputs.dry_run }},
releaseManifestPath: "smithy-rs-release/smithy-rs-release-manifest.json"
releaseCommitish: ${{ needs.upgrade-gradle-properties.outputs.release_branch }},
releaseCommitish: ${{ steps.push-changelog.outputs.commit_sha }}
});
- name: Publish to crates.io
shell: bash