Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Release PR actions #76

Merged
merged 6 commits into from
Sep 25, 2024
Merged

Add Release PR actions #76

merged 6 commits into from
Sep 25, 2024

Conversation

samuelburnham
Copy link
Member

@samuelburnham samuelburnham commented Sep 20, 2024

Adds composite actions for an automated release PR and associated tag + GitHub release when the release PR is merged. Builds on prior work in collaboration with @tchataigner (1, 2)

release-pr.yml

Major/minor release

  • Triggered manually on workflow_dispatch, with major or minor as the release-type input
  • Checks out the latest compatible release/<tag-prefix>-v<version> branch, e.g. release/aptos-v1.0. Note that release/ branches omit the SemVer patch version, as they are meant to persist for production and will iteratively incorporate any patches/hotfixes.
  • Creates and pushes a new branch that increments the version number in the branch name only, e.g. release/aptos-v1.1
  • Creates a new branch called release-pr that increments the version number in Cargo.toml, e.g. 1.0.0 to 1.1.0
  • Opens a PR from release-pr to the new release/ branch. This allows for CI, PR review, and any additional commits to be added for the release. These commits should generally be cherry-picked from existing commits to the default branch.
  • On merge, triggers the tag-release workflow. The release-pr branch can be safely deleted, but the release/ branch should be kept as the release source.

Patch release

  • Triggered manually on workflow_dispatch, with patch as the release-type input
  • Checks out the latest compatible release/<tag-prefix>-v<version> branch, e.g. release/aptos-v1.0
  • Creates and pushes a new branch called patch/<tag-prefix>-v<version>.<patch-version>, e.g. patch/aptos-v1.0.1, which increments the version number in Cargo.toml accordingly
  • Opens a PR from the patch/ branch to the new release/ branch. This allows for CI, PR review, and any additional commits to be added for the release.
  • On merge, triggers the tag-release workflow. The patch/ branch can be safely deleted, but the release/ branch should be kept as the release source.

tag-release.yml

  • Intended to trigger automatically by the release-pr caller when the release PR is merged, as it relies on the head and base branch names for tagging.
  • Tags the base branch of the PR with the new release version
  • Gets the changelog from the previous release tag to the current tag
  • Creates a GitHub release for the new version, tag, and changelog

Downstream examples

Successful runs

TODOs

  • Add unique ID to PR branch name, e.g. release-pr-- in order to allow multiple release PRs at once
  • Auto-open PR to the default branch to bump the Cargo.toml version if this is the latest major.minor release
  • Add an automatic labeler for PRs based on title/commit prefix. This will enable changelogs to categorize changes more accurately

tchataigner
tchataigner previously approved these changes Sep 23, 2024
Copy link
Member

@tchataigner tchataigner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really nice 🎉 I have left a few comments

.github/actions/release-pr/action.yml Show resolved Hide resolved
GITHUB_TOKEN: ${{ inputs.token }}
shell: bash

# Include the full patch version in the PR branch name if a patch, otherwise call it `release-pr` for a major or minor release
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might also be interesting to have different names for release branches as some repositories might have multiple releases of major/minor that could be triggered in parallel.

If that's too bothersome we'll just constrain ourselves to keep it to one at a time.

Copy link
Member

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions inline!

git push origin $TAG_VERSION --follow-tags
echo "tag-version=$TAG_VERSION" | tee -a "$GITHUB_OUTPUT"
shell: bash

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider either testing the length of the get-version or making the subsequent steps conditional on if: steps.get-version.outputs.tag-version != ''

D='0|[1-9][0-9]*'
PW='[0-9]*[a-zA-Z-][0-9a-zA-Z-]*'
MW='[0-9a-zA-Z-]+'
SEMVER_REGEX="^($D)\.($D)\.($D)(-(($D|$PW)(\.($D|$PW))*))?(\+($MW(\.$MW)*))?$"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the official semver regex (from doc) is:

SEMVER_REGEX="^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$"

This one had minor differences, are they important?

# If major release, get latest minor release from prior major version
# If minor release, get latest minor release from given major version
if [[ "${{ inputs.release-type }}" == "major" || "${{ inputs.release-type }}" == "minor" ]]; then
set +o pipefail
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why disable pipefail here?

id: get-latest-release
run: |
set +o pipefail
LATEST_RELEASE=$(gh release list --repo ${{ github.repository }} --limit 100 | grep -Ei "${{ inputs.tag-prefix }}" | head -n 1 | awk '{ print $1 }')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why disable pipefail here?

huitseeker
huitseeker previously approved these changes Sep 24, 2024
Copy link
Member

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving: there's no big deal item in my comments.

@samuelburnham samuelburnham added this pull request to the merge queue Sep 25, 2024
Merged via the queue into main with commit 863a8a2 Sep 25, 2024
2 checks passed
@samuelburnham samuelburnham deleted the release-workflow branch September 25, 2024 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants