Skip to content

Commit

Permalink
Idempotent release action (smithy-lang#2353)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
LukeMathWalker authored Feb 13, 2023
1 parent c060263 commit f705bde
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
15 changes: 2 additions & 13 deletions .github/scripts/get-or-create-release-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
44 changes: 37 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 '[email protected]' 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 '[email protected]' 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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit f705bde

Please sign in to comment.