-
-
Notifications
You must be signed in to change notification settings - Fork 445
315 lines (277 loc) · 11.3 KB
/
build.yml
File metadata and controls
315 lines (277 loc) · 11.3 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
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
# master → 3.8.6 tag: v3.8.6
# development → 3.8.6-dev-abc1234 tag: dev-v3.8.6-dev-abc1234
# other → (empty, zip uses dev-N)
# ============================================================
version:
name: Calculate Version
runs-on: windows-latest
outputs:
semver: ${{ steps.version.outputs.semver }}
assembly_ver: ${{ steps.version.outputs.assembly_ver }}
tag: ${{ steps.version.outputs.tag }}
is_prerelease: ${{ steps.version.outputs.is_prerelease }}
zip_name: ${{ steps.version.outputs.zip_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GitVersion
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development'
uses: gittools/actions/gitversion/setup@v3.0.0
with:
versionSpec: "5.x"
- name: Execute GitVersion
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development'
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 }}"
TAG="v$SEMVER"
IS_PRERELEASE="false"
elif [ "$GITHUB_REF" = "refs/heads/development" ]; then
MMP="${{ steps.gitversion.outputs.majorMinorPatch }}"
SHORT_SHA="${{ steps.gitversion.outputs.shortSha }}"
SEMVER="${MMP}-dev-${{ github.run_number }}-${SHORT_SHA}"
ASSEMBLY_VER="${{ steps.gitversion.outputs.assemblySemVer }}"
TAG="dev-v${SEMVER}"
IS_PRERELEASE="true"
else
SEMVER=""
ASSEMBLY_VER=""
TAG=""
IS_PRERELEASE="false"
fi
ZIP_NAME="vMenu-${SEMVER:-dev-${{ github.run_number }}}.zip"
echo "semver=$SEMVER" >> "$GITHUB_OUTPUT"
echo "assembly_ver=$ASSEMBLY_VER" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "is_prerelease=$IS_PRERELEASE" >> "$GITHUB_OUTPUT"
echo "zip_name=$ZIP_NAME" >> "$GITHUB_OUTPUT"
# ============================================================
# BUILD — runs on every branch
# ============================================================
build:
name: Build
needs: version
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Restore NuGet packages
run: dotnet restore vMenu.sln
- name: Build
shell: bash
run: |
SEMVER="${{ needs.version.outputs.semver }}"
ASSEMBLY_VER="${{ needs.version.outputs.assembly_ver }}"
if [ -n "$SEMVER" ] && [ -n "$ASSEMBLY_VER" ]; then
dotnet build vMenu.sln -c Release --no-restore \
-p:Version="$SEMVER" \
-p:AssemblyVersion="$ASSEMBLY_VER" \
-p:FileVersion="$ASSEMBLY_VER"
else
dotnet build vMenu.sln -c Release --no-restore
fi
- name: Copy fxmanifest.lua
shell: pwsh
run: Copy-Item 'assets/fxmanifest.lua' 'build/vMenu/fxmanifest.lua' -Force
- name: Inject version into fxmanifest.lua
shell: pwsh
run: |
$version = '${{ needs.version.outputs.semver }}'
if (-not $version) { $version = 'dev-${{ github.run_number }}' }
(Get-Content 'build/vMenu/fxmanifest.lua') -replace 'versiongoeshere', $version |
Set-Content -Encoding ASCII 'build/vMenu/fxmanifest.lua'
- name: Copy README and LICENSE
shell: pwsh
run: |
Copy-Item README.md build/vMenu/README.md -Force
Copy-Item LICENSE.md build/vMenu/LICENSE.md -Force
- name: Package zip
shell: pwsh
run: |
Compress-Archive -Path 'build/vMenu/*' -DestinationPath '${{ needs.version.outputs.zip_name }}' -Force
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: vmenu-zip
path: ${{ needs.version.outputs.zip_name }}
# ============================================================
# RELEASE — master (full release) and development (pre-release)
# ============================================================
release:
name: Release
needs: [version, build]
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development'
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 artifact
uses: actions/download-artifact@v4
with:
name: vmenu-zip
path: release-assets
# Changelog always uses the last stable (non-dev) tag as the base,
# so development pre-releases show everything since the last release.
- name: Generate changelog
shell: bash
run: |
LAST_TAG=$(git tag --sort=-version:refname | grep -v '^dev-' | 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 "Changelog since: ${LAST_TAG:-<beginning>}"
cat changelog.txt
- name: Create and push git tag
shell: bash
run: |
TAG="${{ needs.version.outputs.tag }}"
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 "$TAG"
git push origin "$TAG"
- name: Create GitHub Release
id: create_release
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ needs.version.outputs.semver }}"
TAG="${{ needs.version.outputs.tag }}"
IS_PRERELEASE="${{ needs.version.outputs.is_prerelease }}"
if [ "$IS_PRERELEASE" = "true" ]; then
{
echo "vMenu pre-release v${VERSION}."
echo ""
echo "<details><summary>Changes since last full version release</summary>"
echo ""
cat changelog.txt
echo ""
echo "</details>"
} > release_notes.md
else
{
echo "vMenu release v${VERSION}."
echo ""
echo "## Changes"
cat changelog.txt
} > release_notes.md
fi
EXTRA_FLAGS=""
if [ "$IS_PRERELEASE" = "true" ]; then
EXTRA_FLAGS="--prerelease --draft"
fi
RELEASE_URL=$(gh release create "$TAG" \
--title "vMenu $VERSION" \
--notes-file release_notes.md \
$EXTRA_FLAGS \
"release-assets/${{ needs.version.outputs.zip_name }}")
echo "release_url=$RELEASE_URL" >> "$GITHUB_OUTPUT"
# ============================================================
# DISCORD NOTIFICATION — always runs
# ============================================================
notify:
name: Discord Notification
needs: [version, build, 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
BUILD_RESULT="${{ needs.build.result }}"
RELEASE_RESULT="${{ needs.release.result }}"
VERSION="${{ needs.version.outputs.semver }}"
# ── Status colour & label ──────────────────────────────────────────
if [ "$BUILD_RESULT" = "cancelled" ] || [ "$RELEASE_RESULT" = "cancelled" ]; then
COLOR=16776960
STATUS_TEXT="Build cancelled."
elif [ "$BUILD_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 "vMenu (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"