Prepare release branch #6
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
name: Prepare release branch | |
on: | |
workflow_dispatch: | |
inputs: | |
prerelease_version: | |
description: "Pre-release version number? (e.g. 1.9.0rc2)" | |
required: False | |
jobs: | |
prereqs: | |
environment: GITHUB | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install toml | |
run: pip install toml | |
- name: Verify prerequisites | |
env: | |
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }} | |
run: | | |
if [[ $GITHUB_REF_NAME != main ]]; then | |
echo this workflow should only be run against main | |
exit 1 | |
fi | |
if ! grep --quiet "^## Unreleased$" CHANGELOG.md; then | |
echo the change log is missing an \"Unreleased\" section | |
exit 1 | |
fi | |
chmod +x ./.github/scripts/get-version.sh | |
if [[ ! -z $PRERELEASE_VERSION ]]; then | |
stable_version=$(./.github/scripts/get-version.sh) | |
if [[ $PRERELEASE_VERSION != ${stable_version}* ]]; then | |
echo "$PRERELEASE_VERSION is not a prerelease for the version on main ($stable_version)" | |
exit 1 | |
fi | |
fi | |
create-pull-request-against-release-branch: | |
environment: GITHUB | |
runs-on: ubuntu-latest | |
needs: prereqs | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install toml | |
run: pip install toml | |
- name: Create release branch | |
env: | |
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }} | |
run: | | |
if [[ -z $PRERELEASE_VERSION ]]; then | |
stable_version=$(./.github/scripts/get-version.sh) | |
else | |
stable_version=$PRERELEASE_VERSION | |
fi | |
if [[ $stable_version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then | |
stable_version_branch_part=$(echo $stable_version | sed -E 's/([0-9]+)\.([0-9]+)\.0/\1.\2.0/') | |
release_branch_name="release/v${stable_version_branch_part}" | |
elif [[ $stable_version =~ ^([0-9]+)\.([0-9]+)\.0 ]]; then | |
# pre-release version, e.g. 1.9.0rc2 | |
release_branch_name="release/v$stable_version" | |
else | |
echo "unexpected version: $stable_version" | |
exit 1 | |
fi | |
git push origin HEAD:$release_branch_name | |
echo "STABLE_VERSION=$stable_version" >> $GITHUB_ENV | |
echo "RELEASE_BRANCH_NAME=$release_branch_name" >> $GITHUB_ENV | |
- name: Update the change log with the approximate release date | |
run: | | |
date=$(date "+%Y-%m-%d") | |
sed -Ei "s/^## Unreleased$/## Version ${STABLE_VERSION} ($date)/" CHANGELOG.md | |
- name: Create pull request against the release branch | |
env: | |
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }} | |
USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }} | |
USER_NAME: ${{ secrets.GIT_USER_NAME }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
message="Prepare release ${STABLE_VERSION}" | |
branch="monocle/prepare-release-${STABLE_VERSION}" | |
git config --global user.email "$USER_EMAIL" | |
git config --global user.name "$USER_NAME" | |
git commit -a -m "$message" | |
git push origin HEAD:$branch | |
gh pr create --title "[$RELEASE_BRANCH_NAME] $message" \ | |
--body "$message." \ | |
--head $branch \ | |
--base $RELEASE_BRANCH_NAME | |
create-pull-request-against-main: | |
environment: GITHUB | |
runs-on: ubuntu-latest | |
needs: [prereqs, create-pull-request-against-release-branch] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install toml | |
run: pip install toml | |
- name: Set environment variables | |
env: | |
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }} | |
run: | | |
if [[ -z $PRERELEASE_VERSION ]]; then | |
stable_version=$(./.github/scripts/get-version.sh) | |
else | |
stable_version=$PRERELEASE_VERSION | |
fi | |
if [[ $stable_version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then | |
stable_major="${BASH_REMATCH[1]}" | |
stable_minor="${BASH_REMATCH[2]}" | |
stable_next_version="$stable_major.$((stable_minor + 1)).0" | |
elif [[ $stable_version =~ ^([0-9]+)\.([0-9]+)\.0 ]]; then | |
# pre-release version, e.g. 1.9.0rc2 | |
stable_major="${BASH_REMATCH[1]}" | |
stable_minor="${BASH_REMATCH[2]}" | |
stable_next_version="$stable_major.$stable_minor.0" | |
else | |
echo "unexpected stable_version: $stable_version" | |
exit 1 | |
fi | |
echo "STABLE_VERSION=${stable_version}" >> $GITHUB_ENV | |
echo "STABLE_NEXT_VERSION=${stable_next_version}" >> $GITHUB_ENV | |
- name: Update version | |
run: | | |
chmod +x ./.github/scripts/update-version.sh | |
.github/scripts/update-version.sh $STABLE_NEXT_VERSION | |
- name: Update the change log on main | |
run: | | |
# the actual release date on main will be updated at the end of the release workflow | |
date=$(date "+%Y-%m-%d") | |
sed -Ei "s/^## Unreleased$/## Version ${STABLE_VERSION} ($date)/" CHANGELOG.md | |
- name: Create pull request against main | |
env: | |
PRERELEASE_VERSION: ${{ github.event.inputs.prerelease_version }} | |
USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }} | |
USER_NAME: ${{ secrets.GIT_USER_NAME }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
message="Update version to ${STABLE_NEXT_VERSION}" | |
body="Update version to ${STABLE_NEXT_VERSION}." | |
branch="monocle/update-version-to-${STABLE_NEXT_VERSION}" | |
git config --global user.email "$USER_EMAIL" | |
git config --global user.name "$USER_NAME" | |
git commit -a -m "$message" | |
git push origin HEAD:$branch | |
gh pr create --title "$message" \ | |
--body "$body" \ | |
--head $branch \ | |
--base main |