Skip to content

Commit

Permalink
create release branch automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Nov 18, 2024
1 parent 3b0d558 commit a837180
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 43 deletions.
1 change: 1 addition & 0 deletions .github/actions/commit_and_push/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ steps:
gpg_signing_key: ${{ secrets.GPG_SIGNING_KEY }}
branch-name: 'branch-name'
commit-message: 'commit message'
create-branch: 'true'
```
14 changes: 11 additions & 3 deletions .github/actions/commit_and_push/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ name: Commit and Push Changes
description: 'Configures git, commits changes, and pushes to a new branch'
inputs:
branch-name:
description: 'Name of the branch to create'
description: 'Name of the branch to push to'
required: true
create-branch:
description: 'Whether to create a new branch'
required: false
default: 'false'
commit-message:
description: 'Commit message'
required: true
Expand All @@ -20,8 +24,12 @@ runs:
- name: Commit and push changes
shell: bash
run: |
# Create and switch to new branch
git switch -c "${{ inputs.branch-name }}"
# Create new branch if requested
if [ "${{ inputs.create-branch }}" = "true" ]; then
git switch -c "${{ inputs.branch-name }}"
else
git switch "${{ inputs.branch-name }}"
fi
# Show status of working directory
echo "Current git status:"
Expand Down
30 changes: 6 additions & 24 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,12 @@ jobs:
exclude-release-only: ${{ github.event.inputs.exclude-release-only-benchmarks }}

create-branch-prefix:
name: Create Branch and Branch Prefix
runs-on: ubuntu-latest
outputs:
branch-prefix: ${{ steps.create-prefix.outputs.branch-prefix }}
base-branch: ${{ steps.create-prefix.outputs.base-branch }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- id: create-prefix
run: |
VERSION=$(jq -r '.version' package.json)
echo "branch-prefix=benchmark--$VERSION-" >> $GITHUB_OUTPUT
echo "base-branch=benchmark--$VERSION" >> $GITHUB_OUTPUT
- uses: ./.github/actions/configure_git
with:
gpg_signing_key: ${{ secrets.GPG_SIGNING_KEY }}

- name: Create base branch
run: |
git checkout -b ${{ steps.create-prefix.outputs.base-branch }}
git push origin ${{ steps.create-prefix.outputs.base-branch }}
uses: ./.github/workflows/create_branch_prefix.yml
with:
prefix: 'benchmark'
version: VERSION=$(jq -r '.version' package.json)
secrets:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}

run-benchmarks:
name: ${{ matrix.benchmark_group.name }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/benchmark_parallel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ jobs:
branch-name: ${{ steps.create-branch-name.outputs.branch-name }}
commit-message: 'Run benchmarks for ${{ matrix.test.displayPath }}'
gpg_signing_key: ${{ secrets.GPG_SIGNING_KEY }}
create-branch: 'true'
50 changes: 50 additions & 0 deletions .github/workflows/create_branch_prefix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Create Branch Prefix
on:
workflow_call:
inputs:
prefix:
required: true
type: string
description: 'Prefix to use for branch names (e.g. benchmark, update)'
version:
required: true
type: string
description: 'Version to use in branch names'
outputs:
branch-prefix:
description: 'The generated branch prefix ({prefix}--{version}-)'
value: ${{ jobs.create-branch-prefix.outputs.branch-prefix }}
base-branch:
description: 'The generated base branch name ({prefix}--{version})'
value: ${{ jobs.create-branch-prefix.outputs.base-branch }}
secrets:
GPG_SIGNING_KEY:
required: true

jobs:
create-branch-prefix:
name: Create Branch and Branch Prefix
runs-on: ubuntu-latest
outputs:
branch-prefix: ${{ steps.create-prefix.outputs.branch-prefix }}
base-branch: ${{ steps.create-prefix.outputs.base-branch }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- id: create-prefix
shell: bash
run: |
VERSION="${{ inputs.version }}"
echo "branch-prefix=${{ inputs.prefix }}--$VERSION-" >> $GITHUB_OUTPUT
echo "base-branch=${{ inputs.prefix }}--$VERSION" >> $GITHUB_OUTPUT
- uses: ./.github/actions/configure_git
with:
gpg_signing_key: ${{ secrets.GPG_SIGNING_KEY }}

- name: Create base branch
run: |
git checkout -b ${{ steps.create-prefix.outputs.base-branch }}
git push origin ${{ steps.create-prefix.outputs.base-branch }}
59 changes: 43 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@ jobs:
exclude-unstable: ${{ github.event.inputs.exclude-unstable-benchmarks }}
exclude-release-only: ${{ github.event.inputs.exclude-release-only-benchmarks }}

create-branch-prefix:
uses: ./.github/workflows/create_branch_prefix.yml
with:
prefix: 'update'
version: ${{ inputs.release-version }}
secrets:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}

prepare-release:
name: Prepare Release
needs: get-exclude-dirs
needs:
- get-exclude-dirs
- create-branch-prefix
runs-on: ubuntu-latest
env:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }} # All commits must be verified
Expand All @@ -49,7 +59,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
ref: ${{ needs.create-branch-prefix.outputs.base-branch }}
token: ${{ secrets.LASTMJS_GITHUB_TOKEN || github.token }}

- uses: ./.github/actions/setup_node
Expand All @@ -74,6 +84,12 @@ jobs:
AZLE_VERBOSE=true npx azle template
AZLE_VERBOSE=true npx azle template --experimental
- uses: ./.github/actions/commit_and_push
with:
branch-name: ${{ needs.create-branch-prefix.outputs.base-branch }}
commit-message: 'Prepare release ${{ inputs.release-version }}'
gpg_signing_key: ${{ secrets.GPG_SIGNING_KEY }}

- name: Publish to npm
run: |
if [[ "${{ inputs.release-version }}" == *"-rc."* ]]; then
Expand All @@ -91,7 +107,9 @@ jobs:
exclude-dirs: ${{ needs.get-exclude-dirs.outputs.exclude-dirs }}

update-test-files-for-release-commit:
needs: prepare-release
needs:
- prepare-release
- create-branch-prefix
name: Update ${{ matrix.test.name }} files for release commit
runs-on: ubuntu-latest
env:
Expand All @@ -104,7 +122,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
ref: ${{ needs.create-branch-prefix.outputs.base-branch }}
token: ${{ secrets.LASTMJS_GITHUB_TOKEN || github.token }}

- uses: ./.github/actions/setup_node
Expand All @@ -115,7 +133,7 @@ jobs:
run: |
npm install
cd ${{ matrix.test.path }}
sed -E -i "s/(\"azle\": \")(.*)(\")/\1${{ needs.prepare-release.outputs.release-version }}\3/" package.json
sed -E -i "s/(\"azle\": \")(.*)(\")/\1${{ inputs.release-version }}\3/" package.json
npm install
- name: Start dfx with artificial delay 0
Expand All @@ -131,29 +149,35 @@ jobs:
id: create-branch-name
uses: ./.github/actions/create_branch_name
with:
prefix: 'update--${{ needs.prepare-release.outputs.release-version }}-'
prefix: ${{ needs.create-branch-prefix.outputs.branch-prefix }}
path: ${{ matrix.test.displayPath }}

- uses: ./.github/actions/commit_and_push
with:
branch-name: ${{ steps.create-branch-name.outputs.branch-name }}
commit-message: 'Update test files for ${{ matrix.test.displayPath }}'
gpg_signing_key: ${{ secrets.GPG_SIGNING_KEY }}
create-branch: 'true'

squash-branches:
needs: [prepare-release, update-test-files-for-release-commit]
needs:
- prepare-release
- update-test-files-for-release-commit
- create-branch-prefix
uses: ./.github/workflows/squash_branches.yml
with:
base-branch: release--${{ needs.prepare-release.outputs.release-version }}
branch-prefix: 'update--${{ needs.prepare-release.outputs.release-version }}-'
commit-message: 'Update test files for all tests and examples ${{ needs.prepare-release.outputs.release-version }}'
base-branch: ${{ needs.create-branch-prefix.outputs.base-branch }}
branch-prefix: ${{ needs.create-branch-prefix.outputs.branch-prefix }}
commit-message: 'Update test files for all tests and examples ${{ inputs.release-version }}'
secrets:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LASTMJS_GITHUB_TOKEN: ${{ secrets.LASTMJS_GITHUB_TOKEN }}

create-release:
needs: [prepare-release, squash-branches]
needs:
- prepare-release
- squash-branches
name: Create Release
runs-on: ubuntu-latest
steps:
Expand All @@ -166,7 +190,7 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=${{ needs.prepare-release.outputs.release-version }}
VERSION=${{ inputs.release-version }}
git tag $VERSION
git push origin $VERSION
Expand All @@ -177,7 +201,10 @@ jobs:
fi
create-pr:
needs: [prepare-release, squash-branches]
needs:
- prepare-release
- squash-branches
- create-branch-prefix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -190,6 +217,6 @@ jobs:
run: |
gh pr create \
--base main \
--head release--${{ needs.prepare-release.outputs.release-version }} \
--title "Release ${{ needs.prepare-release.outputs.release-version }}" \
--body "Automated PR for release ${{ needs.prepare-release.outputs.release-version }}"
--head ${{ needs.create-branch-prefix.outputs.base-branch }} \
--title "Release ${{ inputs.release-version }}" \
--body "Automated PR for release ${{ inputs.release-version }}"

0 comments on commit a837180

Please sign in to comment.