Repository navigation
133 lines (105 loc) · 3.52 KB
/
Copy pathnuget-publish.yml
File metadata and controls
133 lines (105 loc) · 3.52 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Publish NuGet Packages
on:
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
publish:
runs-on: ubuntu-latest
environment: production
steps:
- name: Verify release tag
shell: bash
run: |
if [[ ! "$GITHUB_REF" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?$ ]]; then
echo "::error::NuGet publishing requires a release tag (vX.Y.Z or vX.Y.Z-prerelease)."
exit 1
fi
- name: Checkout
uses: actions/checkout@v6
- name: Resolve supported SDKs
id: frameworks
env:
DOTNET_NOLOGO: '1'
shell: bash
run: |
frameworks=$(dotnet msbuild src/CodeBeam.UltimateAuth.Core/CodeBeam.UltimateAuth.Core.csproj -nologo -getProperty:UltimateAuthTargetFrameworks)
{
echo 'sdks<<SDKS'
IFS=';' read -ra targets <<< "$frameworks"
for target in "${targets[@]}"; do
echo "${target#net}.x"
done
echo 'SDKS'
} >> "$GITHUB_OUTPUT"
- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ steps.frameworks.outputs.sdks }}
- name: Verify package version
shell: bash
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
PROJECT_VERSION=$(dotnet msbuild \
-getProperty:Version \
src/CodeBeam.UltimateAuth.Server/CodeBeam.UltimateAuth.Server.csproj)
if [[ "$TAG_VERSION" != "$PROJECT_VERSION" ]]; then
echo "::error::Tag version ($TAG_VERSION) does not match package version ($PROJECT_VERSION)."
exit 1
fi
- name: Restore
run: dotnet restore
- name: Build (Release)
run: dotnet build -c Release --no-restore
- name: Pack (nupkg + snupkg)
run: |
dotnet pack -c Release \
--no-build \
-o ./nupkgs \
/p:IncludeSymbols=true \
/p:SymbolPackageFormat=snupkg
- name: Verify packages and symbols
shell: bash
run: |
set -euo pipefail
shopt -s nullglob
packages=(./nupkgs/*.nupkg)
if (( ${#packages[@]} == 0 )); then
echo "::error::No NuGet packages were generated."
exit 1
fi
VERSION="${GITHUB_REF_NAME#v}"
for f in "${packages[@]}"; do
if [[ "$f" != *".$VERSION.nupkg" ]]; then
echo "::error::Unexpected package version: $f"
exit 1
fi
symbols="${f%.nupkg}.snupkg"
if [[ ! -s "$symbols" ]]; then
echo "::error::Missing or empty symbols package: $symbols"
exit 1
fi
echo "Validated: $f + $symbols"
done
echo "Validated ${#packages[@]} packages and symbols."
- name: NuGet login (Trusted Publishing)
uses: NuGet/login@v1
id: login
with:
user: CodeBeam
- name: List packages
run: ls -la ./nupkgs
- name: Publish packages
shell: bash
run: |
set -euo pipefail
for f in ./nupkgs/*.nupkg; do
echo "Publishing: $f"
dotnet nuget push "$f" \
--api-key ${{ steps.login.outputs.NUGET_API_KEY }} \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
done
- name: Done
run: echo "✅ NuGet publishing completed succesfully."