Repository navigation
467 lines (409 loc) · 16.2 KB
/
Copy pathbuild.yml
File metadata and controls
467 lines (409 loc) · 16.2 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
name: CI
# Keeps the name build.yml on purpose, nuget.org trusted publishing is tied to the workflow file name.
# main releases, develop publishes prereleases, everything else only builds. See .github/scripts/version.sh.
on:
push:
# Without a branch filter, pushing a tag would start a full build too.
branches: ['**']
paths-ignore:
- 'docs/**'
- '.github/workflows/docs.yml'
pull_request:
paths-ignore:
- 'docs/**'
- '.github/workflows/docs.yml'
workflow_dispatch:
inputs:
publish:
description: 'Publish a prerelease to nuget.org (ignored on main and develop)'
type: boolean
default: false
permissions:
contents: read
# main and develop never cancel a running build, so a release or prerelease is never cut off halfway.
concurrency:
group: ${{ github.ref == 'refs/heads/main' && 'release' || format('{0}-{1}', github.workflow, github.ref) }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }}
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
VERSION_FLOOR: 4.0.0
jobs:
version:
name: Version
runs-on: ubuntu-latest
outputs:
kind: ${{ steps.version.outputs.kind }}
version: ${{ steps.version.outputs.version }}
assembly: ${{ steps.version.outputs.assembly }}
previous: ${{ steps.version.outputs.previous }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Work out the version
id: version
shell: bash
env:
EVENT: ${{ github.event_name }}
BRANCH: ${{ github.ref_name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PUBLISH_INPUT: ${{ inputs.publish }}
ACTOR: ${{ github.actor }}
RUN_NUMBER: ${{ github.run_number }}
run: |
bash .github/scripts/version.sh | tee version.txt
{
echo "## Version"
echo ""
echo "| | |"
echo "| --- | --- |"
sed -E 's/^([a-z]+)=(.*)$/| \1 | `\2` |/' version.txt
} >> "$GITHUB_STEP_SUMMARY"
build:
name: Build
needs: version
runs-on: windows-latest
env:
VERSION: ${{ needs.version.outputs.version }}
ASSEMBLY: ${{ needs.version.outputs.assembly }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install web build tooling
shell: bash
run: npm ci
# Everything, both frameworks and the TestMenus, so a break anywhere fails the run.
- name: Build FiveM solution
shell: bash
run: dotnet build MenuAPI.FiveM.slnx -c Release
- name: Build RedM solution
shell: bash
run: dotnet build redm/MenuAPI.RedM.slnx -c Release
# Packing builds again, once per package, so each one gets the version stamped in.
- name: Pack Enhanced
shell: bash
run: |
dotnet pack MenuAPI/MenuAPI.csproj -c Release -p:MenuApiFlavor=Enhanced \
-p:Version="$VERSION" -p:AssemblyVersion="$ASSEMBLY" -p:FileVersion="$ASSEMBLY" \
-o nupkgs
- name: Zip Enhanced
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path zips | Out-Null
$outDir = 'MenuAPI/bin/Release/net10.0'
Copy-Item README.md "$outDir/README.md" -Force
Compress-Archive -Path "$outDir/*" -DestinationPath "zips/MenuAPI-$env:VERSION-FiveM-Enhanced.zip" -Force
- name: Pack Legacy
shell: bash
run: |
dotnet pack MenuAPI/MenuAPI.csproj -c Release -p:MenuApiFlavor=Legacy \
-p:Version="$VERSION" -p:AssemblyVersion="$ASSEMBLY" -p:FileVersion="$ASSEMBLY" \
-o nupkgs
- name: Zip Legacy
shell: pwsh
run: |
$outDir = 'MenuAPI/bin/Release/net452'
Copy-Item README.md "$outDir/README.md" -Force
Compress-Archive -Path "$outDir/*" -DestinationPath "zips/MenuAPI-$env:VERSION-FiveM.zip" -Force
- name: Pack RedM
shell: bash
run: |
dotnet pack redm/MenuAPI/MenuAPI.csproj -c Release \
-p:Version="$VERSION" -p:AssemblyVersion="$ASSEMBLY" -p:FileVersion="$ASSEMBLY" \
-o nupkgs
- name: Zip RedM
shell: pwsh
run: |
$outDir = 'redm/MenuAPI/bin/Release/net452'
Copy-Item README.md "$outDir/README.md" -Force
Compress-Archive -Path "$outDir/*" -DestinationPath "zips/MenuAPI-$env:VERSION-RedM.zip" -Force
# Profiling build, slower than the normal one, so it only ships as a zip and never to nuget.org.
- name: Pack NativeHooks
shell: bash
run: |
dotnet pack MenuAPI/MenuAPI.csproj -c NativeHooks \
-p:Version="$VERSION" -p:AssemblyVersion="$ASSEMBLY" -p:FileVersion="$ASSEMBLY" \
-o nupkgs-nativehooks
- name: Zip NativeHooks
shell: pwsh
run: Compress-Archive -Path 'nupkgs-nativehooks/*.nupkg' -DestinationPath "zips/MenuAPI-$env:VERSION-NativeHooks-NuGet.zip" -Force
- name: Upload NuGet packages
uses: actions/upload-artifact@v4
with:
name: nuget
path: nupkgs/*.nupkg
- name: Upload zips
uses: actions/upload-artifact@v4
with:
name: zips
path: zips/*.zip
release:
name: GitHub release
needs: [version, build]
if: needs.version.outputs.kind == 'release'
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
url: ${{ steps.release.outputs.url }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
VERSION: ${{ needs.version.outputs.version }}
PREVIOUS: ${{ needs.version.outputs.previous }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download zips
uses: actions/download-artifact@v4
with:
name: zips
path: release-assets
# A hand written intro for a release can sit in .github/release-notes/<version>.md.
- name: Write release notes
shell: bash
run: |
RANGE="${PREVIOUS:+$PREVIOUS..}$GITHUB_SHA"
LIMIT=100
TOTAL=$(git rev-list --count --no-merges "$RANGE")
# The first 4.x release does not descend from the last 3.x tag, so a commit list would hold all of history.
HISTORY=true
if [ -n "$PREVIOUS" ] && ! git merge-base --is-ancestor "$PREVIOUS" "$GITHUB_SHA"; then
HISTORY=false
fi
breaking() {
local sha subject note
for sha in $(git log "$RANGE" --no-merges --format='%H'); do
subject=$(git log -1 "$sha" --format='%s')
note=$(git log -1 "$sha" --format='%b' \
| awk '/^BREAKING[ -]CHANGE:/ { flag = 1; sub(/^BREAKING[ -]CHANGE:[[:space:]]*/, "") } flag' \
| paste -sd ' ' - \
| sed 's/[[:space:]]*$//')
if [ -z "$note" ] && ! echo "$subject" | grep -qE '^[a-zA-Z]+(\([^)]*\))?!:'; then
continue
fi
echo "> - \`$(git log -1 "$sha" --format='%h')\` $subject"
if [ -n "$note" ]; then
echo "> $note"
fi
done
}
if [ "$HISTORY" = "true" ]; then
breaking > breaking.txt
else
: > breaking.txt
fi
{
if [ -f ".github/release-notes/$VERSION.md" ]; then
cat ".github/release-notes/$VERSION.md"
echo ""
fi
if [ -s breaking.txt ]; then
echo "> [!WARNING]"
echo "> **This release contains breaking changes.** Read these before updating."
echo ">"
cat breaking.txt
echo ""
fi
echo "## Downloads"
echo ""
echo "Every package has the same version. Pick the one for your server."
echo ""
echo "| Server | NuGet package | Zip |"
echo "| --- | --- | --- |"
echo "| FiveM with the Enhanced runtime (.NET 10) | \`MenuAPI.FiveM.Enhanced\` | \`MenuAPI-$VERSION-FiveM-Enhanced.zip\` |"
echo "| FiveM with the Legacy runtime (.NET Framework 4.5.2) | \`MenuAPI.FiveM\` | \`MenuAPI-$VERSION-FiveM.zip\` |"
echo "| RedM | \`MenuAPI.RedM\` | \`MenuAPI-$VERSION-RedM.zip\` |"
echo ""
if [ "$HISTORY" = "true" ]; then
echo "## Changes since ${PREVIOUS:-the beginning}"
echo ""
git log "$RANGE" --no-merges -n "$LIMIT" --pretty=format:'- `%h` %s'
echo ""
if [ "$TOTAL" -gt "$LIMIT" ]; then
echo "- ...and $((TOTAL - LIMIT)) more."
fi
echo ""
fi
echo "## Notes"
echo ""
echo "The NativeHooks zip is a profiling build of Enhanced, packed as a NuGet package you can install from a local folder feed. It is slower than the normal build and is not published to nuget.org. You only need it when profiling."
echo ""
echo "Docs: [FiveM](https://docs.vespura.com/menuapi/fivem), [RedM](https://docs.vespura.com/menuapi/redm)."
} > release_notes.md
cat release_notes.md
# GitHub creates the tag together with the release, so a failed run never leaves a tag without a release.
# Safe to re-run: an existing release for this commit gets its notes and zips replaced.
- name: Tag and release
id: release
shell: bash
run: |
TAG="v$VERSION"
TAGGED=$(git ls-remote --tags origin "refs/tags/$TAG" | cut -f1)
if [ -n "$TAGGED" ] && [ "$TAGGED" != "$GITHUB_SHA" ]; then
echo "::error::Tag $TAG already exists on another commit. Remove it, or bump the version with +semver."
exit 1
fi
if gh release view "$TAG" >/dev/null 2>&1; then
gh release edit "$TAG" --title "MenuAPI v$VERSION" --notes-file release_notes.md --draft=false
gh release upload "$TAG" release-assets/*.zip --clobber
else
gh release create "$TAG" --target "$GITHUB_SHA" --title "MenuAPI v$VERSION" --notes-file release_notes.md release-assets/*.zip
fi
URL=$(gh release view "$TAG" --json url --jq .url)
echo "url=$URL" >> "$GITHUB_OUTPUT"
echo "Released [MenuAPI v$VERSION]($URL)." >> "$GITHUB_STEP_SUMMARY"
# After the release on main, so a failed tag never leaves packages on nuget.org without a release.
publish:
name: Publish to NuGet
needs: [version, build, release]
if: >-
!cancelled()
&& needs.build.result == 'success'
&& (needs.version.outputs.kind == 'prerelease'
|| (needs.version.outputs.kind == 'release' && needs.release.result == 'success'))
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Download packages
uses: actions/download-artifact@v4
with:
name: nuget
path: packages
- name: NuGet login (trusted publishing)
id: login
uses: NuGet/login@v1
with:
user: ${{ vars.NUGET_USER }}
- name: Push packages
shell: bash
env:
NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }}
run: |
for package in packages/*.nupkg; do
dotnet nuget push "$package" \
--source https://api.nuget.org/v3/index.json \
--api-key "$NUGET_API_KEY" \
--skip-duplicate
done
notify:
name: Discord
needs: [version, build, release, publish]
if: >-
!cancelled()
&& (needs.version.outputs.kind == 'release'
|| needs.version.outputs.kind == 'prerelease'
|| (needs.version.result == 'failure' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')))
runs-on: ubuntu-latest
steps:
- name: Send Discord message
shell: bash
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
COMMIT_MSG: ${{ github.event.head_commit.message }}
KIND: ${{ needs.version.outputs.kind }}
VERSION: ${{ needs.version.outputs.version }}
VERSION_RESULT: ${{ needs.version.result }}
BUILD_RESULT: ${{ needs.build.result }}
RELEASE_RESULT: ${{ needs.release.result }}
NUGET_RESULT: ${{ needs.publish.result }}
RELEASE_URL: ${{ needs.release.outputs.url }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
SHA: ${{ github.sha }}
ACTOR: ${{ github.actor }}
BRANCH: ${{ github.ref_name }}
REPO: ${{ github.repository }}
run: |
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
echo "DISCORD_WEBHOOK_URL not configured, skipping."
exit 0
fi
icon() {
case "$1" in
success) echo "✅" ;;
cancelled) echo "⚠️" ;;
skipped) echo "⏭️" ;;
*) echo "❌" ;;
esac
}
FAILED=false
CANCELLED=false
for RESULT in "$VERSION_RESULT" "$BUILD_RESULT" "$RELEASE_RESULT" "$NUGET_RESULT"; do
case "$RESULT" in
cancelled) CANCELLED=true ;;
success|skipped) ;;
*) FAILED=true ;;
esac
done
if [ "$CANCELLED" = "true" ]; then
COLOR=16776960
STATUS_TEXT="Build cancelled."
elif [ "$FAILED" = "true" ]; then
COLOR=13632027
STATUS_TEXT="Build FAILED!"
elif [ "$KIND" = "release" ]; then
COLOR=4502298
STATUS_TEXT="New release published."
else
COLOR=7506394
STATUS_TEXT="New prerelease published."
fi
if [ -z "$VERSION" ]; then
TITLE="MenuAPI ($BRANCH)"
elif [ "$KIND" = "release" ]; then
TITLE="MenuAPI v$VERSION"
else
TITLE="MenuAPI $VERSION (prerelease)"
fi
if [ -n "$RELEASE_URL" ]; then
LINK_NAME="GitHub Release"
LINK_URL="$RELEASE_URL"
else
LINK_NAME="Build Run"
LINK_URL="$RUN_URL"
fi
# Discord rejects field values over 1024 characters, squash merges easily get there.
COMMIT_SUBJECT=$(printf '%s' "${COMMIT_MSG:-Manual run}" | head -n 1)
if [ "${#COMMIT_SUBJECT}" -gt 256 ]; then
COMMIT_SUBJECT="${COMMIT_SUBJECT:0:253}..."
fi
PAYLOAD=$(jq -n \
--arg title "$TITLE" \
--arg desc "$STATUS_TEXT" \
--argjson color "$COLOR" \
--arg actor "$ACTOR" \
--arg actor_url "https://github.com/$ACTOR" \
--arg build "$(icon "$BUILD_RESULT") $BUILD_RESULT" \
--arg nuget "$(icon "$NUGET_RESULT") $NUGET_RESULT" \
--arg branch "$BRANCH" \
--arg link_name "$LINK_NAME" \
--arg link_url "$LINK_URL" \
--arg short_sha "${SHA:0:7}" \
--arg commit_url "https://github.com/$REPO/commit/$SHA" \
--arg commit_msg "$COMMIT_SUBJECT" \
'{
embeds: [{
title: $title,
description: $desc,
color: $color,
author: { name: ("Committed by " + $actor), url: $actor_url },
fields: [
{ name: "Build", value: $build, inline: true },
{ name: "NuGet", value: $nuget, inline: true },
{ name: "Branch", value: $branch, inline: true },
{ name: $link_name, value: ("[Link](" + $link_url + ")"), inline: true },
{ name: "Commit", value: ("[`" + $short_sha + "`](" + $commit_url + ") " + $commit_msg), inline: false }
]
}]
}')
curl -fsSL -H "Content-Type: application/json" -X POST -d "$PAYLOAD" "$DISCORD_WEBHOOK_URL"