|
42 | 42 | with: |
43 | 43 | version: latest |
44 | 44 |
|
45 | | - auto-tag: |
46 | | - name: Automatic Version Tagging |
| 45 | + auto-tag-and-release: |
| 46 | + name: Automatic Version Tagging and Release |
47 | 47 | runs-on: ubuntu-latest |
48 | 48 | needs: test |
49 | 49 | # Only run on branch pushes to main, not on tag pushes |
@@ -85,14 +85,41 @@ jobs: |
85 | 85 | echo "Next version will be: $next_version" |
86 | 86 | |
87 | 87 | - name: Create and push tag |
| 88 | + id: create_tag |
88 | 89 | run: | |
89 | 90 | git config user.name "github-actions[bot]" |
90 | 91 | git config user.email "github-actions[bot]@users.noreply.github.com" |
91 | 92 | |
| 93 | + # Check if tag already exists locally |
| 94 | + if git tag -l "${{ steps.next_version.outputs.version }}" | grep -q .; then |
| 95 | + echo "Tag ${{ steps.next_version.outputs.version }} already exists locally" |
| 96 | + echo "tag_created=false" >> $GITHUB_OUTPUT |
| 97 | + exit 0 |
| 98 | + fi |
| 99 | + |
| 100 | + # Check if tag exists on remote |
| 101 | + if git ls-remote --tags origin | grep -q "refs/tags/${{ steps.next_version.outputs.version }}$"; then |
| 102 | + echo "Tag ${{ steps.next_version.outputs.version }} already exists on remote" |
| 103 | + echo "tag_created=false" >> $GITHUB_OUTPUT |
| 104 | + exit 0 |
| 105 | + fi |
| 106 | + |
92 | 107 | git tag -a ${{ steps.next_version.outputs.version }} -m "Release ${{ steps.next_version.outputs.version }}" |
93 | 108 | git push origin ${{ steps.next_version.outputs.version }} |
94 | 109 | |
95 | 110 | echo "Created and pushed tag: ${{ steps.next_version.outputs.version }}" |
| 111 | + echo "tag_created=true" >> $GITHUB_OUTPUT |
| 112 | + |
| 113 | + - name: Create GitHub Release |
| 114 | + if: steps.create_tag.outputs.tag_created == 'true' |
| 115 | + uses: softprops/action-gh-release@v2 |
| 116 | + with: |
| 117 | + tag_name: ${{ steps.next_version.outputs.version }} |
| 118 | + name: Release ${{ steps.next_version.outputs.version }} |
| 119 | + draft: false |
| 120 | + prerelease: false |
| 121 | + generate_release_notes: true |
| 122 | + token: ${{ secrets.GITHUB_TOKEN }} |
96 | 123 |
|
97 | 124 | build-and-push: |
98 | 125 | name: Build and Push Docker Image |
@@ -187,7 +214,7 @@ jobs: |
187 | 214 | echo "Creating release for ${VERSION}" |
188 | 215 |
|
189 | 216 | - name: Create Release |
190 | | - uses: softprops/action-gh-release@v1 |
| 217 | + uses: softprops/action-gh-release@v2 |
191 | 218 | with: |
192 | 219 | name: Release ${{ steps.extract-release-notes.outputs.version }} |
193 | 220 | draft: false |
|
0 commit comments