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