Skip to content

Commit

Permalink
ci: refactor release flow (#127)
Browse files Browse the repository at this point in the history
* ci: refactor release flow

* refactor: apply suggestions

Co-authored-by: Samuel Burnham <[email protected]>

* refactor: integrate review

---------

Co-authored-by: Samuel Burnham <[email protected]>
  • Loading branch information
tchataigner and samuelburnham committed Jul 30, 2024
1 parent 8ed43be commit 3d2d273
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
39 changes: 27 additions & 12 deletions .github/workflows/bump-version-PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ name: Bump Version
on:
workflow_dispatch:
inputs:
light-client:
description: 'aptos or ethereum'
type: choice
options:
- aptos
- ethereum
required: true
default: 'aptos'
type:
description: 'release or hotfix'
type: choice
Expand Down Expand Up @@ -39,28 +47,28 @@ jobs:
- name: Install `tq-rs`
run: cargo install tq-rs

# The `release/1.0` branch is always truncated, so that patch version merges still are valid Semver
# However, when we make the initial `release/1.0` version bump, we include the full `1.0.0` in `Cargo.toml`
# The `release/<aptos|ethereum>-v1.0` branch is always truncated, so that patch version merges still are valid Semver
# However, when we make the initial `release/<aptos|ethereum>-v1.0` version bump, we include the full `1.0.0` in `Cargo.toml`
# and the release for clarity
- name: Set branches
run: |
BASE_VERSION_SHORT=$(echo "${{ inputs.version }}" | cut -d'.' -f1-2)
BASE_VERSION="${BASE_VERSION_SHORT}.0"
if [[ "${{ inputs.type }}" == "hotfix" ]]; then
VERSION=${{ inputs.version }}
BASE_BRANCH="release/v$BASE_VERSION_SHORT"
PR_BRANCH="${{ inputs.type }}/v${{ inputs.version }}"
git checkout $PR_BRANCH
BASE_BRANCH="release/${{ inputs.light-client }}-v$BASE_VERSION_SHORT"
PR_BRANCH="${{ inputs.type }}/${{ inputs.light-client }}-v${{ inputs.version }}"
git checkout -b $PR_BRANCH
else
VERSION=$BASE_VERSION
BASE_BRANCH="dev"
PR_BRANCH="release/v$BASE_VERSION_SHORT"
PR_BRANCH="release/${{ inputs.light-client }}-v$BASE_VERSION_SHORT"
git checkout -b $PR_BRANCH
fi
echo "BASE_BRANCH=$BASE_BRANCH" | tee -a $GITHUB_ENV
echo "PR_BRANCH=$PR_BRANCH" | tee -a $GITHUB_ENV
echo "PR_DESCRIPTION=chore: Release $VERSION" | tee -a $GITHUB_ENV
echo "PR_DESCRIPTION=chore(${{ inputs.light-client }}): Release $VERSION" | tee -a $GITHUB_ENV
echo "VERSION=$VERSION" | tee -a $GITHUB_ENV
# Regex from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
Expand All @@ -81,7 +89,14 @@ jobs:
run: |
echo "Updating version in Cargo.toml..."
members=$(tq workspace.members -f Cargo.toml | jq -r '. += ["programs/inclusion", "programs/epoch-change"] | .[]')
if [[ "${{ inputs.light-client }}" == "ethereum" ]]; then
members=$(tq workspace.members -f Cargo.toml | jq -r '. += ["programs/inclusion", "programs/committee-change"] | .[]')
elif [[ "${{ inputs.light-client }}" == "aptos" ]]; then
members=$(tq workspace.members -f Cargo.toml | jq -r '. += ["programs/inclusion", "programs/epoch-change"] | .[]')
else
echo "Unknown light-client: ${{ inputs.light-client }}. Aborting..."
exit 1
fi
bump_version() {
cd "$1"
Expand All @@ -106,7 +121,7 @@ jobs:
bump_version "$path"
fi
done <<< "$members"
working-directory: ${{ github.workspace }}/aptos
working-directory: ${{ github.workspace }}/${{ inputs.light-client }}

- name: Commit changes
run: |
Expand All @@ -119,13 +134,13 @@ jobs:
- name: Create PR
run: |
cat << 'EOF' > body.md
This is an automated release PR for version `${ env.VERSION }}`.
This is an automated release PR for version `${{ env.VERSION }}` of the ${{ inputs.light-client }} light client.
On merge, this will trigger the [release publish workflow](${{ github.server_url }}/${{ github.repository }}/actions/workflows/tag-release.yml), which will upload a new GitHub release with tag `v${{ env.VERSION }}`.
On merge, this will trigger the [release publish workflow](${{ github.server_url }}/${{ github.repository }}/actions/workflows/tag-release.yml), which will upload a new GitHub release with tag `${{ inputs.light-client }}-v${{ env.VERSION }}`.
[Workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
EOF
gh pr create --title "${{ env.PR_DESCRIPTION }}" --body-file ./body.md --head ${{ env.PR_BRANCH }} --base ${{ env.BASE_BRANCH }}
env:
GH_TOKEN: ${{ github.token }}
GH_TOKEN: ${{ github.token }}
2 changes: 1 addition & 1 deletion .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ jobs:
body: ${{ steps.github_release.outputs.changelog }}
tag: ${{ steps.get-version.outputs.version }}
commit: ${{ env.RELEASE_BRANCH }}
allowUpdates: true
allowUpdates: true

0 comments on commit 3d2d273

Please sign in to comment.