Skip to content

Commit

Permalink
Merge pull request #1657 from luhring/rel-tag
Browse files Browse the repository at this point in the history
release: check for both tag and release
  • Loading branch information
luhring authored Nov 18, 2024
2 parents 5ce2bb4 + 75e0381 commit d1fda1d
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 }}

0 comments on commit d1fda1d

Please sign in to comment.