Skip to content

Commit fa1f22a

Browse files
authored
Merge pull request #20 from chrisw-dev/copilot/fix-automatic-release-creation
Fix automatic release creation by creating releases in same workflow run as tags
2 parents 9ddf997 + 120644c commit fa1f22a

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

.github/workflows/cd.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ jobs:
4242
with:
4343
version: latest
4444

45-
auto-tag:
46-
name: Automatic Version Tagging
45+
auto-tag-and-release:
46+
name: Automatic Version Tagging and Release
4747
runs-on: ubuntu-latest
4848
needs: test
4949
# Only run on branch pushes to main, not on tag pushes
@@ -85,14 +85,41 @@ jobs:
8585
echo "Next version will be: $next_version"
8686
8787
- name: Create and push tag
88+
id: create_tag
8889
run: |
8990
git config user.name "github-actions[bot]"
9091
git config user.email "github-actions[bot]@users.noreply.github.com"
9192
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+
92107
git tag -a ${{ steps.next_version.outputs.version }} -m "Release ${{ steps.next_version.outputs.version }}"
93108
git push origin ${{ steps.next_version.outputs.version }}
94109
95110
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 }}
96123

97124
build-and-push:
98125
name: Build and Push Docker Image
@@ -187,7 +214,7 @@ jobs:
187214
echo "Creating release for ${VERSION}"
188215
189216
- name: Create Release
190-
uses: softprops/action-gh-release@v1
217+
uses: softprops/action-gh-release@v2
191218
with:
192219
name: Release ${{ steps.extract-release-notes.outputs.version }}
193220
draft: false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ mock-oauth2-server
2828

2929
# Server binary
3030
server
31+
actionlint

0 commit comments

Comments
 (0)