-
Notifications
You must be signed in to change notification settings - Fork 0
329 lines (300 loc) · 10.7 KB
/
Copy pathrelease-nuget.yml
File metadata and controls
329 lines (300 loc) · 10.7 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
name: Build & Publish NuGet (Tag Release)
permissions:
contents: write
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: "Release version (e.g. v0.2.0.12)"
required: true
type: string
ref:
description: "Git reference (commit SHA, branch, or tag) to create the release from"
required: true
type: string
default: "main"
jobs:
# Blocking gate: all tests must pass before any packing/publishing can run.
test-gate:
runs-on: ubuntu-latest
outputs:
resolved_sha: ${{ steps.resolve_sha.outputs.RESOLVED_SHA }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ inputs.ref || github.ref }}
- name: Resolve checked out commit SHA
id: resolve_sha
shell: bash
run: |
RESOLVED_SHA=$(git rev-parse HEAD)
echo "RESOLVED_SHA=$RESOLVED_SHA" >> "$GITHUB_OUTPUT"
echo "✅ Resolved commit SHA: $RESOLVED_SHA"
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
cache: true
cache-dependency-path: |
FluentAAS/**/*.csproj
FluentAAS/global.json
- name: Locate solution file
id: solution
shell: bash
run: |
SOLUTION=$(find . -maxdepth 5 -name "*.sln" | head -n 1)
if [ -z "$SOLUTION" ]; then
echo "❌ No solution file (*.sln) found in the repo."
exit 1
fi
echo "SOLUTION_PATH=$SOLUTION" >> $GITHUB_OUTPUT
echo "✅ Found solution: $SOLUTION"
- name: Restore dependencies
run: dotnet restore "${{ steps.solution.outputs.SOLUTION_PATH }}"
- name: Build solution
run: dotnet build "${{ steps.solution.outputs.SOLUTION_PATH }}" -c Release --no-restore
- name: Test solution (blocking gate)
run: dotnet test "${{ steps.solution.outputs.SOLUTION_PATH }}" -c Release --no-build --verbosity normal
build-pack-push:
runs-on: ubuntu-latest
needs: test-gate
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ needs.test-gate.outputs.resolved_sha }}
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
cache: true
cache-dependency-path: |
FluentAAS/**/*.csproj
FluentAAS/global.json
- name: Determine version (from tag or input)
id: version
shell: bash
env:
INPUT_VERSION: ${{ inputs.version }}
GITHUB_REF_NAME: ${{ github.ref_name }}
EVENT_NAME: ${{ github.event_name }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
TAG="$INPUT_VERSION"
else
TAG="$GITHUB_REF_NAME"
fi
echo "Tag: $TAG"
# Guardrail: must start with v and look like vX.Y.Z(.W)
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then
echo "❌ Invalid tag format: $TAG"
echo "Expected format: v<major>.<minor>.<patch>[.<revision>] (e.g., v0.2.0.12 or v1.2.3)"
exit 1
fi
VERSION="${TAG#v}"
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "TAG=$TAG" >> $GITHUB_OUTPUT
echo "✅ Valid version format: $VERSION"
- name: Locate solution file
id: solution
shell: bash
run: |
SOLUTION=$(find . -maxdepth 5 -name "*.sln" | head -n 1)
if [ -z "$SOLUTION" ]; then
echo "❌ No solution file (*.sln) found in the repo."
exit 1
fi
echo "SOLUTION_PATH=$SOLUTION" >> $GITHUB_OUTPUT
echo "✅ Found solution: $SOLUTION"
- name: Restore dependencies
run: dotnet restore "${{ steps.solution.outputs.SOLUTION_PATH }}"
- name: Build solution
run: dotnet build "${{ steps.solution.outputs.SOLUTION_PATH }}" -c Release --no-restore
- name: Pack NuGet packages
run: dotnet pack "${{ steps.solution.outputs.SOLUTION_PATH }}" -c Release -o ./artifacts --no-build /p:PackageVersion=${{ steps.version.outputs.VERSION }}
- name: Verify package versions
shell: bash
run: |
shopt -s nullglob
packages=(./artifacts/*.nupkg)
if [ ${#packages[@]} -eq 0 ]; then
echo "❌ No NuGet packages found in ./artifacts/"
exit 1
fi
echo "📦 Generated NuGet packages:"
VERSION="${{ steps.version.outputs.VERSION }}"
ESCAPED_VERSION="${VERSION//./\\.}"
for pkg in "${packages[@]}"; do
filename=$(basename "$pkg")
echo " - $filename"
# Verify the package name contains the expected version using escaped dots
if [[ "$filename" =~ \.$ESCAPED_VERSION\.nupkg$ ]]; then
echo "✅ Version matches tag: $VERSION"
else
echo "❌ Version mismatch in package name"
exit 1
fi
done
- name: Publish to NuGet
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
- name: Build Changelog
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v6
with:
fetchReleaseInformation: true
failOnError: false
mode: "HYBRID"
configurationJson: |
{
"template": "## What's Changed\n\n#{{CHANGELOG}}\n\n**Full Changelog**: #{{RELEASE_DIFF}}",
"empty_template": "## What's Changed\n\nNo user-facing changes in this release.",
"pr_template": "- #{{TITLE}} by @#{{AUTHOR}} in ##{{NUMBER}}",
"commit_template": "- #{{TITLE}} by @#{{AUTHOR}} (`#{{MERGE_SHA}}`)",
"categories": [
{
"title": "## 🚀 Features",
"labels": ["enhancement", "feature", "feat"],
"mode": "PR"
},
{
"title": "## 🐛 Bug Fixes",
"labels": ["bug", "fix", "bugfix"],
"mode": "PR"
},
{
"title": "## 📝 Documentation",
"labels": ["docs", "documentation"],
"mode": "PR"
},
{
"title": "## 🧪 Tests",
"labels": ["test", "tests", "qa"],
"mode": "PR"
},
{
"title": "## 🧰 Maintenance",
"labels": ["chore", "ci", "build", "dependencies", "refactor"],
"mode": "PR"
},
{
"title": "## 🔒 Security",
"labels": ["security"],
"mode": "PR"
},
{
"title": "## 🚀 Features (Direct Commits)",
"mode": "COMMIT",
"rules": [
{
"pattern": "^(feat|feature)(\\(.+\\))?:\\s+.+$",
"flags": "giu",
"on_property": "title"
}
]
},
{
"title": "## 🐛 Bug Fixes (Direct Commits)",
"mode": "COMMIT",
"rules": [
{
"pattern": "^(fix|bugfix|bug)(\\(.+\\))?:\\s+.+$",
"flags": "giu",
"on_property": "title"
}
]
},
{
"title": "## 🧰 Maintenance (Direct Commits)",
"mode": "COMMIT",
"rules": [
{
"pattern": "^(build|chore|ci|refactor|perf|style|test|docs)(\\(.+\\))?:\\s+.+$",
"flags": "giu",
"on_property": "title"
}
]
},
{
"title": "## 📦 Other Direct Commits",
"mode": "COMMIT",
"rules": [
{
"pattern": "^.+$",
"flags": "gu",
"on_property": "title"
}
]
}
],
"sort": {
"order": "ASC",
"on_property": "mergedAt"
},
"label_extractor": [
{
"pattern": "(?i)^(enhancement|feature|feat)$",
"target": "$1"
},
{
"pattern": "(?i)^(bug|fix|bugfix)$",
"target": "$1"
},
{
"pattern": "(?i)^(docs|documentation)$",
"target": "$1"
},
{
"pattern": "(?i)^(test|tests|qa)$",
"target": "$1"
},
{
"pattern": "(?i)^(chore|ci|build|dependencies|refactor)$",
"target": "$1"
},
{
"pattern": "(?i)^security$",
"target": "$0"
}
],
"autolabeler": [
{
"label": "docs",
"files": ["**/*.md", "docs/**"]
},
{
"label": "test",
"files": ["**/*test*/**", "**/*tests*/**", "**/*.Tests/**"]
},
{
"label": "ci",
"files": [".github/workflows/**"]
}
]
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload NuGet Artifacts
uses: actions/upload-artifact@v7
with:
name: nuget-packages-${{ steps.version.outputs.VERSION }}
path: ./artifacts/*.nupkg
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.TAG }}
name: FluentAAS ${{ steps.version.outputs.VERSION }}
body: ${{ steps.build_changelog.outputs.changelog || 'Release notes will be added here.' }}
files: ./artifacts/*.nupkg
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}