diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 8540689..4497e45 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -42,8 +42,8 @@ jobs: with: version: latest - auto-tag: - name: Automatic Version Tagging + auto-tag-and-release: + name: Automatic Version Tagging and Release runs-on: ubuntu-latest needs: test # Only run on branch pushes to main, not on tag pushes @@ -85,14 +85,41 @@ jobs: echo "Next version will be: $next_version" - name: Create and push tag + id: create_tag run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" + # Check if tag already exists locally + if git tag -l "${{ steps.next_version.outputs.version }}" | grep -q .; then + echo "Tag ${{ steps.next_version.outputs.version }} already exists locally" + echo "tag_created=false" >> $GITHUB_OUTPUT + exit 0 + fi + + # Check if tag exists on remote + if git ls-remote --tags origin | grep -q "refs/tags/${{ steps.next_version.outputs.version }}$"; then + echo "Tag ${{ steps.next_version.outputs.version }} already exists on remote" + echo "tag_created=false" >> $GITHUB_OUTPUT + exit 0 + fi + git tag -a ${{ steps.next_version.outputs.version }} -m "Release ${{ steps.next_version.outputs.version }}" git push origin ${{ steps.next_version.outputs.version }} echo "Created and pushed tag: ${{ steps.next_version.outputs.version }}" + echo "tag_created=true" >> $GITHUB_OUTPUT + + - name: Create GitHub Release + if: steps.create_tag.outputs.tag_created == 'true' + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.next_version.outputs.version }} + name: Release ${{ steps.next_version.outputs.version }} + draft: false + prerelease: false + generate_release_notes: true + token: ${{ secrets.GITHUB_TOKEN }} build-and-push: name: Build and Push Docker Image @@ -187,7 +214,7 @@ jobs: echo "Creating release for ${VERSION}" - name: Create Release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: name: Release ${{ steps.extract-release-notes.outputs.version }} draft: false diff --git a/.gitignore b/.gitignore index 4efce2d..e776b94 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ mock-oauth2-server # Server binary server +actionlint