From a83718093d3cc66f0901b48c586649a59ab82251 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Mon, 18 Nov 2024 09:41:00 -0700 Subject: [PATCH] create release branch automatically --- .github/actions/commit_and_push/README.md | 1 + .github/actions/commit_and_push/action.yml | 14 +++-- .github/workflows/benchmark.yml | 30 +++-------- .github/workflows/benchmark_parallel.yml | 1 + .github/workflows/create_branch_prefix.yml | 50 ++++++++++++++++++ .github/workflows/release.yml | 59 ++++++++++++++++------ 6 files changed, 112 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/create_branch_prefix.yml diff --git a/.github/actions/commit_and_push/README.md b/.github/actions/commit_and_push/README.md index 36391926e8..c2e21b6ae5 100644 --- a/.github/actions/commit_and_push/README.md +++ b/.github/actions/commit_and_push/README.md @@ -9,4 +9,5 @@ steps: gpg_signing_key: ${{ secrets.GPG_SIGNING_KEY }} branch-name: 'branch-name' commit-message: 'commit message' + create-branch: 'true' ``` diff --git a/.github/actions/commit_and_push/action.yml b/.github/actions/commit_and_push/action.yml index b9937de63f..9a56b9e8c0 100644 --- a/.github/actions/commit_and_push/action.yml +++ b/.github/actions/commit_and_push/action.yml @@ -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 @@ -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:" diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 54029d626f..1b307ba8a1 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -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 }} diff --git a/.github/workflows/benchmark_parallel.yml b/.github/workflows/benchmark_parallel.yml index 3ce86db173..91122cd1e2 100644 --- a/.github/workflows/benchmark_parallel.yml +++ b/.github/workflows/benchmark_parallel.yml @@ -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' diff --git a/.github/workflows/create_branch_prefix.yml b/.github/workflows/create_branch_prefix.yml new file mode 100644 index 0000000000..ee308f544b --- /dev/null +++ b/.github/workflows/create_branch_prefix.yml @@ -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 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ec532980b1..e00219b279 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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 @@ -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 @@ -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: @@ -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 @@ -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 @@ -131,7 +149,7 @@ 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 @@ -139,21 +157,27 @@ jobs: 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: @@ -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 @@ -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 @@ -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 }}"