-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #555 from github/fix/update-release
Fix release automation
- Loading branch information
Showing
5 changed files
with
79 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,12 @@ on: | |
inputs: | ||
ref: | ||
description: | | ||
The release branch to finalize. | ||
The ref of release to finalize (e.g., 'rc/MAJOR.MINOR.PATCH'). | ||
required: true | ||
tool-ref: | ||
description: | | ||
The ref to the tooling to use for the finalize (e.g., 'rc/MAJOR.MINOR.PATCH'). | ||
required: false | ||
|
||
jobs: | ||
finalize-release: | ||
|
@@ -20,34 +24,56 @@ jobs: | |
- name: Determine ref | ||
env: | ||
REF_FROM_INPUT: ${{ inputs.ref }} | ||
TOOL_REF_FROM_INPUT: ${{ inputs.tool-ref }} | ||
REF_FROM_PR: ${{ github.event.pull_request.merge_commit_sha }} | ||
BASE_REF_FROM_PR: ${{ github.event.pull_request.base.ref }} | ||
run: | | ||
if [[ $GITHUB_EVENT_NAME == "workflow_dispatch" ]]; then | ||
echo "REF=$REF_FROM_INPUT" >> "$GITHUB_ENV" | ||
echo "TOOL_REF=$TOOL_REF_FROM_INPUT" >> "$GITHUB_ENV" | ||
echo "BASE_REF=$REF_FROM_INPUT" >> "$GITHUB_ENV" | ||
else | ||
echo "REF=$REF_FROM_PR" >> "$GITHUB_ENV" | ||
echo "TOOL_REF=$REF_FROM_PR" >> "$GITHUB_ENV" | ||
echo "BASE_REF=$BASE_REF_FROM_PR" >> "$GITHUB_ENV" | ||
fi | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ env.REF }} | ||
fetch-depth: 0 | ||
path: release | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ env.TOOL_REF }} | ||
path: tooling | ||
|
||
- name: Install Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.9" | ||
|
||
- name: Install dependencies | ||
run: pip install -r scripts/release/requirements.txt | ||
working-directory: tooling | ||
|
||
- name: Configure git | ||
run: | | ||
git config user.name "$GITHUB_ACTOR" | ||
git config user.email "[email protected]" | ||
working-directory: release | ||
|
||
- name: Update release tag | ||
run: | | ||
version=${BASE_REF#rc/} | ||
echo "Creating release tag v$version" | ||
git tag -a v$version -m "Release v$version" | ||
git push -f origin v$version | ||
git tag -f -a v$version -m "Release v$version" | ||
git push --force origin v$version | ||
working-directory: release | ||
|
||
- name: Finalize release | ||
env: | ||
|
@@ -57,30 +83,40 @@ jobs: | |
echo "Finalizing release v$version" | ||
gh release edit "v$version" --draft=false --tag=v$version | ||
working-directory: release | ||
|
||
- name: Determine if release was a hotfix release | ||
run: | | ||
version=${BASE_REF#rc/} | ||
echo "HOTFIX_RELEASE=$(python scripts/release/is-hotfix.py $version)" >> "$GITHUB_ENV" | ||
# We are running the script in the tooling directory with the release directory as the working directory | ||
echo "HOTFIX_RELEASE=$(python ../tooling/scripts/release/is-hotfix-release.py $version)" >> "$GITHUB_ENV" | ||
working-directory: release | ||
|
||
- name: Determine next release version | ||
if: env.HOTFIX_RELEASE == 'false' | ||
run: | | ||
version=${BASE_REF#rc/} | ||
next_version=$(python scripts/release/next-version.py --component minor --pre-release dev -- $version) | ||
echo "NEXT_VERSION=$next_version" >> "$GITHUB_ENV" | ||
working-directory: tooling | ||
|
||
- name: Bump main version | ||
if: env.HOTFIX_RELEASE == 'false' | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
version=${BASE_REF#rc/} | ||
next_version="$version-dev" | ||
echo "Bumping main version to $next_version" | ||
echo "Bumping main version to $NEXT_VERSION" | ||
git switch main | ||
git pull --ff-only origin main | ||
git switch -c release-automation/bump-version | ||
./scripts/release/bump-version.sh "$next_version" | ||
# We are running the script in the tooling directory with the release directory as the working directory | ||
../tooling/scripts/release/bump-version.sh "$NEXT_VERSION" | ||
git add -u . | ||
git commit -m "Bump version to $next_version" | ||
git commit -m "Bump version to $NEXT_VERSION" | ||
git push --set-upstream origin release-automation/bump-version | ||
gh pr create --repo $GITHUB_REPOSITORY --base main --head release-automation/bump-version --body "Bump the version of main to the dev label of the just released version $next_version" --title "Bump version to $next_version" | ||
gh pr create --repo $GITHUB_REPOSITORY --base main --head release-automation/bump-version --body "Bump the version of main to $NEXT_VERSION" --title "Bump version to $NEXT_VERSION" | ||
working-directory: release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from semantic_version import Version | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description='Prints the next release version') | ||
parser.add_argument('-c', '--component', default="minor", help='The component to increment (major, minor, patch)') | ||
parser.add_argument('-p', '--pre-release', nargs='*', help='The pre-release label(s) (e.g. alpha, dev). Multiple labels can be specified so separate the options and the version using `--`!') | ||
parser.add_argument('-b', '--build', nargs='*', help='The build identifier(s). Multiple identifiers can be specified so separate the options and the version using `--`!') | ||
parser.add_argument('current_version', type=Version, help='The current version') | ||
|
||
if __name__ == "__main__": | ||
args = parser.parse_args() | ||
version : Version = args.current_version | ||
next_version = None | ||
if args.component== "major": | ||
next_version = version.next_major() | ||
elif args.component == "minor": | ||
next_version = version.next_minor() | ||
elif args.component == "patch": | ||
next_version = version.next_patch() | ||
else: | ||
raise ValueError(f"Invalid release type: {args.release_type}") | ||
|
||
if args.pre_release: | ||
next_version.prerelease = args.pre_release | ||
if args.build: | ||
next_version.build = args.build | ||
|
||
print(next_version) |