Skip to content

Commit 1d290bd

Browse files
authored
Create release.yml
1 parent 72b6d9b commit 1d290bd

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Release (Stable)
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Setup .NET
22+
uses: actions/setup-dotnet@v4
23+
with:
24+
dotnet-version: 8.0.x
25+
26+
- name: Install GitVersion
27+
uses: gittools/actions/gitversion/setup@v3
28+
with:
29+
versionSpec: '6.x'
30+
31+
- name: Determine Version
32+
id: gitversion
33+
uses: gittools/actions/gitversion/execute@v3
34+
with:
35+
useConfigFile: true
36+
37+
- name: Display Version
38+
run: |
39+
echo "FullSemVer: ${{ steps.gitversion.outputs.FullSemVer }}"
40+
echo "NuGetVersionV2: ${{ steps.gitversion.outputs.NuGetVersionV2 }}"
41+
echo "IsPreRelease? ${{ steps.gitversion.outputs.PreReleaseTag != '' }}"
42+
43+
- name: Fail if Pre-release on main
44+
if: ${{ steps.gitversion.outputs.PreReleaseTag != '' }}
45+
run: |
46+
echo "Unexpected pre-release on main. Check GitVersion config."
47+
exit 1
48+
49+
- name: Restore
50+
run: dotnet restore
51+
52+
- name: Build
53+
run: dotnet build -c Release --no-restore
54+
55+
- name: Test
56+
run: dotnet test -c Release --no-build
57+
58+
- name: Pack Stable
59+
run: |
60+
dotnet pack src/MyLibrary/MyLibrary.csproj \
61+
-c Release -o artifacts \
62+
/p:PackageVersion=${{ steps.gitversion.outputs.NuGetVersionV2 }}
63+
64+
- name: Create Tag (if missing)
65+
run: |
66+
TAG="v${{ steps.gitversion.outputs.MajorMinorPatch }}"
67+
if git rev-parse "$TAG" >/dev/null 2>&1; then
68+
echo "Tag $TAG already exists."
69+
else
70+
git tag "$TAG"
71+
git push origin "$TAG"
72+
fi
73+
74+
- name: Add GitHub Packages Source
75+
run: |
76+
dotnet nuget add source \
77+
--username $GITHUB_ACTOR \
78+
--password ${{ secrets.GITHUB_TOKEN }} \
79+
--store-password-in-clear-text \
80+
--name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
81+
82+
- name: Publish to GitHub Packages
83+
run: dotnet nuget push "artifacts/*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source "github" --skip-duplicate
84+
85+
- name: Publish to NuGet
86+
env:
87+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
88+
run: |
89+
dotnet nuget push "artifacts/*.nupkg" \
90+
--api-key "$NUGET_API_KEY" \
91+
--source https://api.nuget.org/v3/index.json \
92+
--skip-duplicate

0 commit comments

Comments
 (0)