-
Notifications
You must be signed in to change notification settings - Fork 50
382 lines (332 loc) · 13.2 KB
/
build.yml
File metadata and controls
382 lines (332 loc) · 13.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
name: CI/CD
on:
push:
branches:
- '**'
pull_request:
permissions:
contents: write
# Cancel any in-progress run on the same branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
# ============================================================
# VERSION — calculates the shared version number once
# ============================================================
version:
name: Calculate Version
runs-on: windows-latest
outputs:
semver: ${{ steps.version.outputs.semver }}
assembly_ver: ${{ steps.version.outputs.assembly_ver }}
zip_prefix: ${{ steps.version.outputs.zip_prefix }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GitVersion
if: github.ref == 'refs/heads/master'
uses: gittools/actions/gitversion/setup@v3.0.0
with:
versionSpec: '5.x'
- name: Execute GitVersion
if: github.ref == 'refs/heads/master'
id: gitversion
uses: gittools/actions/gitversion/execute@v3.0.0
- name: Set version outputs
id: version
shell: bash
run: |
if [ "$GITHUB_REF" = "refs/heads/master" ]; then
SEMVER="${{ steps.gitversion.outputs.semVer }}"
ASSEMBLY_VER="${{ steps.gitversion.outputs.assemblySemVer }}"
else
SEMVER=""
ASSEMBLY_VER=""
fi
ZIP_PREFIX="MenuAPI-${SEMVER:-dev-${{ github.run_number }}}"
echo "semver=$SEMVER" >> "$GITHUB_OUTPUT"
echo "assembly_ver=$ASSEMBLY_VER" >> "$GITHUB_OUTPUT"
echo "zip_prefix=$ZIP_PREFIX" >> "$GITHUB_OUTPUT"
# ============================================================
# BUILD FIVEM
# Restores only the FiveM configuration to avoid CitizenFX
# NuGet package conflicting with the RedM local DLL.
# ============================================================
build-fivem:
name: Build FiveM
needs: version
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Restore NuGet (FiveM only)
shell: bash
run: dotnet restore "MenuAPI/MenuAPI.csproj" "-p:Configuration=Release FiveM"
- name: Build FiveM (versioned)
if: github.ref == 'refs/heads/master'
shell: bash
run: |
dotnet build MenuAPI/MenuAPI.csproj -c "Release FiveM" --no-restore \
-p:Version=${{ needs.version.outputs.semver }} \
-p:AssemblyVersion=${{ needs.version.outputs.assembly_ver }} \
-p:FileVersion=${{ needs.version.outputs.assembly_ver }}
- name: Build FiveM
if: github.ref != 'refs/heads/master'
run: dotnet build MenuAPI/MenuAPI.csproj -c "Release FiveM" --no-restore
- name: Package FiveM zip
shell: pwsh
run: |
$outDir = 'MenuAPI/bin/Release FiveM/net452'
Copy-Item README.md "$outDir/README.md" -Force
Compress-Archive -Path "$outDir/*" -DestinationPath "${{ needs.version.outputs.zip_prefix }}-FiveM.zip" -Force
- name: Upload FiveM zip
uses: actions/upload-artifact@v4
with:
name: zip-fivem
path: ${{ needs.version.outputs.zip_prefix }}-FiveM.zip
- name: Pack NuGet FiveM
if: github.ref == 'refs/heads/master'
run: >-
dotnet pack MenuAPI/MenuAPI.csproj
-c "Release FiveM"
--no-restore
-p:PackageVersion=${{ needs.version.outputs.semver }}
-p:DefineConstants=FIVEM
-p:PackageId=MenuAPI.FiveM
-o nupkgs
- name: Upload NuGet FiveM
if: github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: nuget-fivem
path: nupkgs/*.nupkg
# ============================================================
# BUILD REDM
# Restores only the RedM configuration so the local
# dependencies/RedM/CitizenFX.Core.dll is used, not the
# FiveM NuGet package.
# ============================================================
build-redm:
name: Build RedM
needs: version
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Restore NuGet (RedM only)
shell: bash
run: dotnet restore "MenuAPI/MenuAPI.csproj" "-p:Configuration=Release RedM"
- name: Build RedM (versioned)
if: github.ref == 'refs/heads/master'
shell: bash
run: |
dotnet build MenuAPI/MenuAPI.csproj -c "Release RedM" --no-restore \
-p:Version=${{ needs.version.outputs.semver }} \
-p:AssemblyVersion=${{ needs.version.outputs.assembly_ver }} \
-p:FileVersion=${{ needs.version.outputs.assembly_ver }}
- name: Build RedM
if: github.ref != 'refs/heads/master'
run: dotnet build MenuAPI/MenuAPI.csproj -c "Release RedM" --no-restore
- name: Package RedM zip
shell: pwsh
run: |
$outDir = 'MenuAPI/bin/Release RedM/net452'
Copy-Item README.md "$outDir/README.md" -Force
Compress-Archive -Path "$outDir/*" -DestinationPath "${{ needs.version.outputs.zip_prefix }}-RedM.zip" -Force
- name: Upload RedM zip
uses: actions/upload-artifact@v4
with:
name: zip-redm
path: ${{ needs.version.outputs.zip_prefix }}-RedM.zip
- name: Pack NuGet RedM
if: github.ref == 'refs/heads/master'
run: >-
dotnet pack MenuAPI/MenuAPI.csproj
-c "Release RedM"
--no-restore
-p:PackageVersion=${{ needs.version.outputs.semver }}
-p:DefineConstants=REDM
-p:PackageId=MenuAPI.RedM
-o nupkgs
- name: Upload NuGet RedM
if: github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: nuget-redm
path: nupkgs/*.nupkg
# ============================================================
# RELEASE — master only, after both builds succeed
# ============================================================
release:
name: Release
needs: [version, build-fivem, build-redm]
if: github.ref == 'refs/heads/master'
runs-on: windows-latest
outputs:
release_url: ${{ steps.create_release.outputs.release_url }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download FiveM zip
uses: actions/download-artifact@v4
with:
name: zip-fivem
path: release-assets
- name: Download RedM zip
uses: actions/download-artifact@v4
with:
name: zip-redm
path: release-assets
- name: Download NuGet FiveM
uses: actions/download-artifact@v4
with:
name: nuget-fivem
path: release-assets
- name: Download NuGet RedM
uses: actions/download-artifact@v4
with:
name: nuget-redm
path: release-assets
# Generate changelog BEFORE tagging so the range is correct
- name: Generate changelog
shell: bash
run: |
LAST_TAG=$(git tag --sort=-version:refname | head -n 1)
if [ -n "$LAST_TAG" ]; then
git log "$LAST_TAG..HEAD" --pretty=format:'- `%h` (%an) %s' > changelog.txt
else
git log --pretty=format:'- `%h` (%an) %s' > changelog.txt
fi
echo "Last tag used for changelog: ${LAST_TAG:-<none, full history>}"
cat changelog.txt
- name: Create and push git tag
shell: bash
run: |
VERSION="${{ needs.version.outputs.semver }}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
git tag "v$VERSION"
git push origin "v$VERSION"
- name: Create GitHub Release
id: create_release
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ needs.version.outputs.semver }}"
{
echo "MenuAPI release v${VERSION}. Download the **FiveM** or **RedM** versions below."
echo ""
echo "## Changes"
cat changelog.txt
echo ""
echo "For more info, check the [docs](https://docs.vespura.com/mapi)."
} > release_notes.md
RELEASE_URL=$(gh release create "v$VERSION" \
--title "MenuAPI v$VERSION" \
--notes-file release_notes.md \
"release-assets/MenuAPI-$VERSION-FiveM.zip" \
"release-assets/MenuAPI-$VERSION-RedM.zip")
echo "release_url=$RELEASE_URL" >> "$GITHUB_OUTPUT"
- name: Publish NuGet — FiveM
run: >-
dotnet nuget push
"release-assets/MenuAPI.FiveM.${{ needs.version.outputs.semver }}.nupkg"
--api-key ${{ secrets.NUGET_API_KEY }}
--source https://api.nuget.org/v3/index.json
--skip-duplicate
- name: Publish NuGet — RedM
run: >-
dotnet nuget push
"release-assets/MenuAPI.RedM.${{ needs.version.outputs.semver }}.nupkg"
--api-key ${{ secrets.NUGET_API_KEY }}
--source https://api.nuget.org/v3/index.json
--skip-duplicate
# ============================================================
# DISCORD NOTIFICATION — always runs
# ============================================================
notify:
name: Discord Notification
needs: [version, build-fivem, build-redm, release]
if: always()
runs-on: ubuntu-latest
steps:
- name: Send Discord notification
shell: bash
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
run: |
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
echo "DISCORD_WEBHOOK_URL not configured, skipping."
exit 0
fi
FIVEM_RESULT="${{ needs.build-fivem.result }}"
REDM_RESULT="${{ needs.build-redm.result }}"
RELEASE_RESULT="${{ needs.release.result }}"
VERSION="${{ needs.version.outputs.semver }}"
# ── Status colour & label ──────────────────────────────────────────
if [ "$FIVEM_RESULT" = "cancelled" ] || [ "$REDM_RESULT" = "cancelled" ] || [ "$RELEASE_RESULT" = "cancelled" ]; then
COLOR=16776960
STATUS_TEXT="Build cancelled."
elif [ "$FIVEM_RESULT" = "success" ] && [ "$REDM_RESULT" = "success" ] && \
{ [ "$RELEASE_RESULT" = "success" ] || [ "$RELEASE_RESULT" = "skipped" ]; }; then
COLOR=4502298
STATUS_TEXT="Build passed!"
else
COLOR=13632027
STATUS_TEXT="Build FAILED!"
fi
# ── Link field ─────────────────────────────────────────────────────
RELEASE_URL="${{ needs.release.outputs.release_url }}"
if [ -n "$RELEASE_URL" ] && [ "$RELEASE_RESULT" = "success" ]; then
LINK_NAME="GitHub Release"
LINK_URL="$RELEASE_URL"
else
LINK_NAME="Build Run"
LINK_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
fi
DISPLAY_VERSION="${VERSION:-dev-${{ github.run_number }}}"
SHA="${{ github.sha }}"
SHORT_SHA="${SHA:0:7}"
PAYLOAD=$(jq -n \
--arg title "MenuAPI (v${DISPLAY_VERSION})" \
--arg desc "$STATUS_TEXT" \
--argjson color "$COLOR" \
--arg actor "${{ github.actor }}" \
--arg actor_url "https://github.com/${{ github.actor }}" \
--arg branch "${{ github.ref_name }}" \
--arg link_name "$LINK_NAME" \
--arg link_url "$LINK_URL" \
--arg short_sha "$SHORT_SHA" \
--arg commit_url "https://github.com/${{ github.repository }}/commit/${{ github.sha }}" \
--arg commit_msg "${{ github.event.head_commit.message }}" \
'{
embeds: [{
title: $title,
description: $desc,
color: $color,
author: {
name: ("Committed by " + $actor),
url: $actor_url
},
fields: [
{ 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"