Skip to content

Commit bb45355

Browse files
committed
fix: make release workflow idempotent
1 parent e279ad7 commit bb45355

1 file changed

Lines changed: 19 additions & 23 deletions

File tree

.github/workflows/release-on-version-change.yml

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
push:
55
paths:
66
- 'manifest.json'
7+
- 'RELEASE_NOTES.md'
8+
- '.github/workflows/release-on-version-change.yml'
79
workflow_dispatch:
810

911
jobs:
@@ -29,36 +31,30 @@ jobs:
2931
VERSION=$(jq -r '.version' manifest.json)
3032
echo "VERSION=$VERSION" >> $GITHUB_ENV
3133
32-
- name: Get the latest tag
33-
id: get_latest_tag
34-
run: |
35-
LATEST_TAG=$(git describe --tags --abbrev=0 || echo "")
36-
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
37-
38-
- name: Compare versions
39-
id: compare_versions
34+
- name: Check whether release already exists
35+
id: release_state
36+
env:
37+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4038
run: |
41-
if [ "$LATEST_TAG" = "$VERSION" ] || [ "$LATEST_TAG" = "v$VERSION" ]; then
42-
echo "No version change. Skipping release."
39+
if gh release view "$VERSION" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
40+
echo "Release $VERSION already exists. Skipping."
4341
echo "should_release=false" >> "$GITHUB_OUTPUT"
4442
else
4543
echo "should_release=true" >> "$GITHUB_OUTPUT"
4644
fi
4745
4846
- name: Create tag and release
49-
if: steps.compare_versions.outputs.should_release == 'true'
47+
if: steps.release_state.outputs.should_release == 'true'
5048
env:
51-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5250
run: |
53-
git tag "${{ env.VERSION }}"
54-
git push origin "${{ env.VERSION }}"
51+
if ! git rev-parse "$VERSION" >/dev/null 2>&1; then
52+
git tag "$VERSION"
53+
git push origin "$VERSION"
54+
fi
5555
56-
RELEASE_BODY=$(jq -Rs . < RELEASE_NOTES.md)
57-
curl --fail-with-body -X POST -H "Authorization: token $GITHUB_TOKEN" \
58-
-H "Accept: application/vnd.github.v3+json" \
59-
https://api.github.com/repos/${{ github.repository }}/releases \
60-
-d "$(jq -n \
61-
--arg tag \"${{ env.VERSION }}\" \
62-
--arg name \"WebDataScope ${{ env.VERSION }} Release\" \
63-
--argjson body \"$RELEASE_BODY\" \
64-
'{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: false}')"
56+
gh release create "$VERSION" \
57+
--repo "$GITHUB_REPOSITORY" \
58+
--verify-tag \
59+
--title "WebDataScope $VERSION Release" \
60+
--notes-file RELEASE_NOTES.md

0 commit comments

Comments
 (0)