From 9821caa6d06156363c8f899f8f0e6536a7ade200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Saparelli?= Date: Wed, 11 Jan 2023 11:22:53 +1300 Subject: [PATCH] Use release-meta action instead of parsing commits (#675) --- .github/scripts/extract-release-notes.sh | 16 ------ .../extract-tag-from-release-commit.sh | 8 --- .github/workflows/release-build.yml | 4 +- .github/workflows/release.yml | 52 ++++++++----------- 4 files changed, 25 insertions(+), 55 deletions(-) delete mode 100755 .github/scripts/extract-release-notes.sh delete mode 100755 .github/scripts/extract-tag-from-release-commit.sh diff --git a/.github/scripts/extract-release-notes.sh b/.github/scripts/extract-release-notes.sh deleted file mode 100755 index 3bf70165..00000000 --- a/.github/scripts/extract-release-notes.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -set -euxo pipefail - -release_pr=$(head -n1 <<< "${COMMIT_MESSAGE:-}" | jq -Rr 'split("[()]"; "")[1] // ""') -if [[ -z "$release_pr" ]]; then - echo "::set-output name=notes_json::null" - exit -fi - -gh \ - pr --repo "$GITHUB_REPO" \ - view "$release_pr" \ - --json body \ - --jq '"::set-output name=notes_json::\((.body | split("### Release notes")[1] // "") | tojson)"' - - diff --git a/.github/scripts/extract-tag-from-release-commit.sh b/.github/scripts/extract-tag-from-release-commit.sh deleted file mode 100755 index 3e7d95bb..00000000 --- a/.github/scripts/extract-tag-from-release-commit.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -euxo pipefail - -message="$(head -n1 <<< "$COMMIT_MESSAGE")" -crate="$(cut -d ' ' -f 2 <<< "${message}")" -version="$(cut -d ' ' -f 3 <<< "${message}")" -echo "::set-output name=crate::${crate}" -echo "::set-output name=version::${version}" diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index f0c44965..f4f886f5 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -102,8 +102,8 @@ jobs: name: Publish release uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 with: - tag_name: ${{ fromJSON(inputs.publish).version }} - name: ${{ fromJSON(inputs.publish).version }} + tag_name: v${{ fromJSON(inputs.publish).version }} + name: v${{ fromJSON(inputs.publish).version }} body: ${{ fromJSON(inputs.publish).notes }} append_body: false files: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f47f9710..b286bac2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,56 +1,50 @@ -name: Release +name: On release on: - push: - branches: - - main - tags-ignore: - - "*" + pull_request: + types: closed + branches: [main] # target branch of release PRs jobs: info: - runs-on: ubuntu-latest - # the commit message will look like: `release: {crate-name} v{version} (#{pr-number})` - if: "startsWith(github.event.head_commit.message, 'release: ')" + if: github.event.pull_request.merged + outputs: - crate: ${{ steps.version.outputs.crate }} - version: ${{ steps.version.outputs.version }} - notes: ${{ fromJSON(steps.notes.outputs.notes_json) }} - env: - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} + is-release: ${{ steps.meta.outputs.is-release }} + crate: ${{ steps.meta.outputs.crate-names }} + version: ${{ steps.meta.outputs.version-actual }} + notes: ${{ steps.meta.outputs.notes }} + + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Extract tag from commit message - id: version - run: .github/scripts/extract-tag-from-release-commit.sh - - name: Extract release notes - id: notes - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_REPO: ${{ github.repository }} - run: .github/scripts/extract-release-notes.sh + - id: meta + uses: cargo-bins/release-meta@v1 + with: + event-data: ${{ toJSON(github.event) }} + extract-notes-under: '### Release notes' tag: + if: needs.info.outputs.is-release == 'true' needs: info runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Push lib release tag - if: "! startsWith(github.event.head_commit.message, 'release: cargo-binstall v')" + if: needs.info.outputs.crate != 'cargo-binstall' uses: mathieudutour/github-tag-action@v6.1 with: github_token: ${{ secrets.GITHUB_TOKEN }} custom_tag: ${{ needs.info.outputs.version }} - tag_prefix: ${{ needs.info.outputs.crate }}- + tag_prefix: ${{ needs.info.outputs.crate }}-v - name: Push cli release tag - if: "startsWith(github.event.head_commit.message, 'release: cargo-binstall v')" + if: needs.info.outputs.crate == 'cargo-binstall' uses: mathieudutour/github-tag-action@v6.1 with: github_token: ${{ secrets.GITHUB_TOKEN }} custom_tag: ${{ needs.info.outputs.version }} - tag_prefix: '' + tag_prefix: v package: - if: "startsWith(github.event.head_commit.message, 'release: cargo-binstall v')" + if: needs.info.outputs.is-release == 'true' && needs.info.outputs.crate == 'cargo-binstall' needs: - info - tag