From ec38308bcff6fdaa23ea5af2f6e2b8f97e645417 Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Tue, 24 Sep 2024 11:11:34 -0400 Subject: [PATCH] Fix `tag-release` --- .github/workflows/tag-release.yml | 53 +++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/.github/workflows/tag-release.yml b/.github/workflows/tag-release.yml index 6cd8ad3d1..cfac0bc54 100644 --- a/.github/workflows/tag-release.yml +++ b/.github/workflows/tag-release.yml @@ -1,17 +1,29 @@ # Workflow to create a new tag release when a release branch is merged -name: Tag release +name: Create tag release on: pull_request: types: [ closed ] branches: - release/* + workflow_dispatch: + inputs: + release-branch: + description: 'Branch to release' + type: 'string' + required: true + version: + description: 'SemVer release version, e.g. `1.0.0`' + type: 'string' + required: true jobs: - tag-bump: + tag-release: if: | - github.event.pull_request.merged == true && - ((startsWith(github.event.pull_request.head.ref, 'release-pr') || startsWith(github.event.pull_request.head.ref, 'patch/')) + (github.event.pull_request.merged == true && + (startsWith(github.event.pull_request.head.ref, 'release-pr' || + startsWith(github.event.pull_request.head.ref, 'patch/'))) || + github.event_name == 'workflow_dispatch') runs-on: ubuntu-latest steps: - name: Git config @@ -29,7 +41,8 @@ jobs: ref: release-workflow - name: Create changelog config run: | - printf '%s\n' "{ + cat << 'EOF' > config.json + { "template": "#{{CHANGELOG}}", "categories": [ { @@ -41,6 +54,7 @@ jobs: "labels": ["fix", "bug"] }, { + "title": "## 🤖 CI", "labels": ["automated-issue", "ci"] }, @@ -48,14 +62,23 @@ jobs: "title": "## Other", "labels": [] } - ], - "label_extractor": [ - { - "pattern": "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\\([\\w\\-\\.]+\\))?(!)?: ([\\w ])+([\\s\\S]*)", - "target": "$1" - } - ], - }" > config.json + ] + } + EOF + - name: Get branch and version info + run: | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + RELEASE_BRANCH=${{ github.event.pull_request.base.ref }} + # Get tag and version from PR title + TAG=$(echo "${{ github.event.pull_request.title }}" | awk '/Release/ {print $NF}' | tr -d '`') + VERSION="${TAG#*-}" + else + RELEASE_BRANCH=${{ inputs.release-branch }} + VERSION=${{ inputs.version }} + fi + + echo "RELEASE_BRANCH=$RELEASE_BRANCH" | tee -a $GITHUB_ENV + echo "VERSION=$VERSION" | tee -a $GITHUB_ENV # - uses: tibdex/github-app-token@v2 # id: generate-token # with: @@ -64,5 +87,7 @@ jobs: - name: Publish release uses: ./ci-workflows/.github/actions/tag-release with: + release-branch: ${{ env.RELEASE_BRANCH }} + version: ${{ env.VERSION }} tag-prefix: sphinx - config-file: ./config.json + changelog-config-file: ./config.json