From 75e038130cbea0b1d5efac6ce7bad932ace03f5b Mon Sep 17 00:00:00 2001 From: Dan Luhring Date: Mon, 18 Nov 2024 09:29:00 -0500 Subject: [PATCH] release: check for both tag and release Signed-off-by: Dan Luhring --- .github/workflows/release.yaml | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f63c4e754..dd293c8a6 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -22,29 +22,39 @@ jobs: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Check if any changes since last tag + - name: Check if any changes since last release id: check + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | git fetch --tags - if [ -z "$(git tag --points-at HEAD)" ]; then - echo "Nothing points at HEAD, so we need a new tag+release." + TAG=$(git tag --points-at HEAD) + if [ -z "$TAG" ]; then + echo "No tag points at HEAD, so we need a new tag and then a new release." echo "need_release=yes" >> $GITHUB_OUTPUT else - echo "A tag already points to head, no need for a new tag+release." - echo "need_release=no" >> $GITHUB_OUTPUT + RELEASE=$(gh release view "$TAG" --json tagName --jq '.tagName' || echo "none") + if [ "$RELEASE" == "$TAG" ]; then + echo "A release exists for tag $TAG, which has the latest changes, so no need for a new tag or release." + echo "need_release=no" >> $GITHUB_OUTPUT + else + echo "Tag $TAG exists, but no release is associated. Need a new release." + echo "need_release=yes" >> $GITHUB_OUTPUT + echo "existing_tag=$TAG" >> $GITHUB_OUTPUT + fi fi - name: Bump version and push tag id: create_tag uses: mathieudutour/github-tag-action@a22cf08638b34d5badda920f9daf6e72c477b07b # v6.2 - if: steps.check.outputs.need_release == 'yes' + if: steps.check.outputs.need_release == 'yes' && steps.check.outputs.existing_tag == '' with: github_token: ${{ secrets.GITHUB_TOKEN }} - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 if: steps.check.outputs.need_release == 'yes' with: - ref: ${{ steps.create_tag.outputs.new_tag }} + ref: ${{ steps.check.outputs.existing_tag || steps.create_tag.outputs.new_tag }} - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 if: steps.check.outputs.need_release == 'yes' @@ -76,3 +86,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} HOMEBREW_TAP_GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }} + TAG: ${{ steps.check.outputs.existing_tag || steps.create_tag.outputs.new_tag }}