Skip to content

Commit ec85fb6

Browse files
added tag and release steps
1 parent b6f8420 commit ec85fb6

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

.github/workflows/build.yml

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
jobs:
88
build:
99
runs-on: ubuntu-latest
10+
outputs:
11+
semver: ${{ steps.gitversion.outputs.semVer }}
12+
fullsemver: ${{ steps.gitversion.outputs.fullSemVer }}
13+
nugetversion: ${{ steps.gitversion.outputs.fullSemVer }}
1014

1115
steps:
1216
- name: Checkout code
@@ -28,7 +32,7 @@ jobs:
2832
echo "Version: ${{ steps.gitversion.outputs.semVer }}"
2933
echo "AssemblyVersion: ${{ steps.gitversion.outputs.assemblySemVer }}"
3034
echo "FileVersion: ${{ steps.gitversion.outputs.assemblySemFileVer }}"
31-
echo "NuGet Version: ${{ steps.gitversion.outputs.nuGetVersionV2 }}"
35+
echo "NuGet Version: ${{ steps.gitversion.outputs.fullSemVer }}"
3236
3337
- name: Setup .NET
3438
uses: actions/setup-dotnet@v5
@@ -147,4 +151,59 @@ jobs:
147151
dotnet-version: '8.0.x'
148152

149153
- name: Publish to NuGet
150-
run: dotnet nuget push packages/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
154+
run: dotnet nuget push packages/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
155+
156+
create-release-tag:
157+
runs-on: ubuntu-latest
158+
needs: [build, publish-nuget]
159+
if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
160+
permissions:
161+
contents: write
162+
163+
steps:
164+
- name: Checkout code
165+
uses: actions/checkout@v5
166+
with:
167+
fetch-depth: 0
168+
token: ${{ secrets.GITHUB_TOKEN }}
169+
170+
- name: Check if tag already exists
171+
id: check_tag
172+
run: |
173+
TAG="v${{ needs.build.outputs.semver }}"
174+
if git rev-parse "$TAG" >/dev/null 2>&1; then
175+
echo "Tag $TAG already exists"
176+
echo "tag_exists=true" >> $GITHUB_OUTPUT
177+
else
178+
echo "Creating new tag: $TAG"
179+
echo "tag_exists=false" >> $GITHUB_OUTPUT
180+
echo "new_tag=$TAG" >> $GITHUB_OUTPUT
181+
fi
182+
183+
- name: Download Release Notes
184+
if: steps.check_tag.outputs.tag_exists == 'false'
185+
uses: actions/download-artifact@v5
186+
with:
187+
name: release-notes
188+
path: .
189+
190+
- name: Create Git Tag and GitHub Release
191+
if: steps.check_tag.outputs.tag_exists == 'false'
192+
run: |
193+
TAG="${{ steps.check_tag.outputs.new_tag }}"
194+
195+
# Configure git
196+
git config user.name "github-actions[bot]"
197+
git config user.email "github-actions[bot]@users.noreply.github.com"
198+
199+
# Create and push tag
200+
git tag -a "$TAG" -m "Release $TAG"
201+
git push origin "$TAG"
202+
203+
# Create GitHub release
204+
gh release create "$TAG" \
205+
--title "Release $TAG" \
206+
--notes-file release-notes.md \
207+
--generate-notes
208+
env:
209+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)