forked from roflmuffin/CounterStrikeSharp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate-release.sh
More file actions
executable file
·484 lines (424 loc) · 17.2 KB
/
create-release.sh
File metadata and controls
executable file
·484 lines (424 loc) · 17.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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
#!/bin/bash
set -e
DRY_RUN=false
BETA=false
NO_LOCAL=false
FORCE=false
# Parse command line arguments
for arg in "$@"; do
case $arg in
--dry-run|-d)
DRY_RUN=true
echo "Running in DRY-RUN mode - no changes will be pushed"
shift
;;
--beta|-b)
BETA=true
echo "Running in BETA mode - will create pre-release version"
shift
;;
--no-local|-n)
NO_LOCAL=true
echo "Skipping local Linux build via act - only Windows will be built (by GitHub Actions)"
shift
;;
--force|-f)
FORCE=true
echo "FORCE mode - will tag current HEAD even if no new commits since last release"
shift
;;
*)
;;
esac
done
# Runs the Linux + managed build locally via act and appends the Linux zips
# to the GitHub release. GitHub Actions handles the Windows half on tag push
# (.github/workflows/build-windows.yml), so this covers the remaining half.
run_local_linux_build() {
local tag="$1"
if [ "$NO_LOCAL" = true ]; then
echo "Skipping local Linux build (--no-local)."
echo "Reminder: run it later with:"
echo " act workflow_dispatch -W .github/workflows/build-and-publish.yml \\"
echo " --input confirm_local=LOCAL \\"
echo " -P ubuntu-latest=catthehacker/ubuntu:full-latest \\"
echo " --artifact-server-path /tmp/act-artifacts \\"
echo " -s GITHUB_TOKEN=\$(gh auth token)"
return 0
fi
if ! command -v act &> /dev/null; then
echo "⚠️ act not installed - skipping local Linux build."
echo " Install: https://github.com/nektos/act"
echo " Then run the command printed above to append Linux zips to $tag."
return 0
fi
if ! docker info &> /dev/null; then
echo "⚠️ Docker not running - skipping local Linux build."
echo " Start Docker and run act manually to append Linux zips to $tag."
return 0
fi
if ! command -v gh &> /dev/null; then
echo "⚠️ gh CLI not found - cannot fetch GITHUB_TOKEN for act."
return 0
fi
local token
token=$(gh auth token 2>/dev/null || true)
if [ -z "$token" ]; then
echo "⚠️ gh auth token returned empty - run 'gh auth login' first."
return 0
fi
local artifact_dir
artifact_dir=$(mktemp -d -t act-artifacts-XXXXXX)
# GitVersion refuses to run on "build servers" (which act advertises as)
# when the repo has >1 remote. Stash any non-origin remotes for the act
# run; restore them on any exit path (success, failure, Ctrl+C).
local -a stashed_remotes=()
local -a stashed_urls=()
local r
while IFS= read -r r; do
if [ -n "$r" ] && [ "$r" != "origin" ]; then
stashed_remotes+=("$r")
stashed_urls+=("$(git remote get-url "$r")")
fi
done < <(git remote)
if [ "${#stashed_remotes[@]}" -gt 0 ]; then
for r in "${stashed_remotes[@]}"; do
git remote remove "$r"
done
echo "Temporarily removed non-origin remotes: ${stashed_remotes[*]}"
# Build a restore command and register it as an EXIT trap so the
# remotes come back even if act fails or the user Ctrl+Cs.
local restore_cmd=""
local i
for i in "${!stashed_remotes[@]}"; do
restore_cmd+="git remote add '${stashed_remotes[$i]}' '${stashed_urls[$i]}' 2>/dev/null; "
done
trap "$restore_cmd" EXIT
fi
echo ""
echo "Running local Linux build via act (this takes a few minutes)..."
echo " Artifacts: $artifact_dir"
echo ""
local act_status=0
act workflow_dispatch \
-W .github/workflows/build-and-publish.yml \
--input confirm_local=LOCAL \
-P ubuntu-latest=catthehacker/ubuntu:full-latest \
--artifact-server-path "$artifact_dir" \
-s GITHUB_TOKEN="$token" || act_status=$?
# Restore remotes immediately on normal exit + clear the trap
if [ "${#stashed_remotes[@]}" -gt 0 ]; then
for i in "${!stashed_remotes[@]}"; do
git remote add "${stashed_remotes[$i]}" "${stashed_urls[$i]}" 2>/dev/null || true
done
trap - EXIT
echo "Restored remotes: ${stashed_remotes[*]}"
fi
if [ "$act_status" -eq 0 ]; then
echo "✅ Linux zips appended to release $tag"
else
echo "⚠️ act run failed. The GitHub release exists; Windows zips will still"
echo " be uploaded by the GitHub workflow. Re-run act manually to add Linux."
fi
rm -rf "$artifact_dir"
return 0
}
echo "Starting automated release process..."
echo "Fetching latest tags from remote..."
git fetch --tags
# Get the highest version tag (ignore non-version tags like backup-* or build-number-*)
LATEST_TAG=$(git tag --list 'v*' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-beta)?$' | sort -V | tail -n 1)
LATEST_TAG=${LATEST_TAG:-v1.0.0}
echo "Latest tag found: $LATEST_TAG"
# Parse version from tag (handling both beta and stable versions)
if [[ $LATEST_TAG =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)(-beta)?$ ]]; then
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
PATCH=${BASH_REMATCH[3]}
IS_BETA=${BASH_REMATCH[4]}
else
echo "Error: Could not parse version from tag $LATEST_TAG"
echo "Expected format: v1.0.x or v1.0.x-beta (e.g., v1.0.355 or v1.0.356-beta)"
exit 1
fi
# Determine new version based on beta flag
if [ "$BETA" = true ]; then
if [ -n "$IS_BETA" ]; then
# Current is beta, can't create another beta of same version
echo "Error: Current version $LATEST_TAG is already a beta"
echo "To release stable version, run without --beta flag"
exit 1
fi
# Create beta of next version
NEW_PATCH=$((PATCH + 1))
NEW_TAG="v$MAJOR.$MINOR.$NEW_PATCH-beta"
RELEASE_TYPE="pre-release (beta)"
else
if [ -n "$IS_BETA" ]; then
# Current is beta, promote to stable (same version, remove -beta)
NEW_PATCH=$PATCH
NEW_TAG="v$MAJOR.$MINOR.$NEW_PATCH"
RELEASE_TYPE="stable release (promoted from beta)"
else
# Current is stable, create next stable
NEW_PATCH=$((PATCH + 1))
NEW_TAG="v$MAJOR.$MINOR.$NEW_PATCH"
RELEASE_TYPE="stable release"
fi
fi
echo "New version will be: $NEW_TAG ($RELEASE_TYPE)"
# Handle changelog generation differently for beta promotion
if [ -n "$IS_BETA" ] && [ "$BETA" = false ]; then
# Promoting beta to stable - update existing changelog entry
echo "Updating changelog entry from beta to stable..."
# Remove beta warning from changelog
sed -i "/⚠️ \*\*BETA PRE-RELEASE\*\*/d" CHANGELOG.md
# Update the version tag in changelog (remove -beta suffix)
sed -i "s/\[$LATEST_TAG\]/[$NEW_TAG]/" CHANGELOG.md
# Update the comparison link if it exists
sed -i "s/$LATEST_TAG/$NEW_TAG/g" CHANGELOG.md
echo "Changelog updated: $LATEST_TAG -> $NEW_TAG (beta warning removed)"
else
# Normal changelog generation for new versions
echo "Generating changelog with git-cliff..."
npx git-cliff -o CHANGELOG.md -t "$NEW_TAG"
# Add beta indicator to changelog if this is a beta release
if [ "$BETA" = true ]; then
# Add beta warning at the top of the new release section
sed -i "/## \[$NEW_TAG\]/a \\
\\
⚠️ **BETA PRE-RELEASE** - This version is for testing purposes only\\
" CHANGELOG.md
fi
fi
if ! git diff --quiet CHANGELOG.md; then
echo "Changelog updated successfully"
git add CHANGELOG.md
# Create appropriate commit message
if [ "$BETA" = true ]; then
COMMIT_MSG="release: $NEW_TAG (beta pre-release)"
else
if [ -n "$IS_BETA" ]; then
COMMIT_MSG="release: $NEW_TAG (promoted from beta)"
else
COMMIT_MSG="release: $NEW_TAG"
fi
fi
echo "Committing changelog with message: $COMMIT_MSG"
if [ "$DRY_RUN" = true ]; then
git commit -m "$COMMIT_MSG"
echo "Creating tag locally: $NEW_TAG"
git tag "$NEW_TAG"
echo "DRY-RUN: Would push commit to remote"
echo "DRY-RUN: Would push tag to remote"
if [ "$BETA" = true ]; then
echo "DRY-RUN: Would mark as pre-release on GitHub"
fi
else
git commit -m "$COMMIT_MSG"
echo "Pushing commit to remote..."
git push origin $(git branch --show-current)
echo "Creating and pushing tag: $NEW_TAG"
git tag "$NEW_TAG"
git push origin tag "$NEW_TAG"
if [ "$BETA" = true ]; then
echo ""
echo "Creating GitHub pre-release..."
# Check if gh CLI is installed
if command -v gh &> /dev/null; then
if gh release create "$NEW_TAG" \
--prerelease \
--title "$NEW_TAG - Beta Pre-release" \
--notes "⚠️ **BETA PRE-RELEASE** - This version is for testing purposes only
## Feedback
Please report any issues or feedback before we promote this to stable release."; then
echo "✅ Pre-release created successfully on GitHub!"
else
echo "⚠️ Failed to create pre-release. Please create it manually:"
echo " gh release create $NEW_TAG --prerelease --generate-notes"
fi
else
echo "⚠️ GitHub CLI (gh) not found. Install it to auto-create pre-releases:"
echo " https://cli.github.com/"
echo ""
echo "Manual steps:"
echo "1. Go to https://github.com/mrc4tt/CounterStrikeSharp/releases/new"
echo "2. Select tag: $NEW_TAG"
echo "3. Check 'Set as a pre-release' checkbox"
echo "4. Publish release"
fi
else
echo ""
echo "Creating GitHub release..."
# Check if gh CLI is installed
if command -v gh &> /dev/null; then
if gh release create "$NEW_TAG" \
--title "$NEW_TAG" \
--notes "✅ **STABLE RELEASE**
## Installation
Download the latest stable build from the assets below."; then
echo "✅ Release created successfully on GitHub!"
else
echo "⚠️ Failed to create release. Please create it manually:"
echo " gh release create $NEW_TAG --generate-notes"
fi
else
echo "⚠️ GitHub CLI (gh) not found. Skipping automatic release creation."
echo " Install it from: https://cli.github.com/"
fi
fi
# GitHub Actions is now handling the Windows build (build-windows.yml);
# run act locally to build Linux + managed and append to the same release.
run_local_linux_build "$NEW_TAG"
fi
echo ""
echo "=========================================="
echo "Release $NEW_TAG completed successfully!"
echo "=========================================="
echo "Summary:"
echo " - Previous version: $LATEST_TAG"
echo " - New version: $NEW_TAG"
echo " - Release type: $RELEASE_TYPE"
echo " - Changelog updated: Yes"
if [ "$DRY_RUN" = true ]; then
echo " - Commit pushed: (dry-run)"
echo " - Tag created and pushed: (dry-run)"
else
echo " - Commit pushed: Yes"
echo " - Tag created and pushed: Yes"
echo " - Windows build: running on GitHub Actions (build-windows.yml)"
if [ "$NO_LOCAL" = true ]; then
echo " - Linux build: SKIPPED (run act manually to append)"
else
echo " - Linux build: handled locally via act"
fi
fi
if [ "$BETA" = true ]; then
echo ""
echo "Next steps:"
echo " 1. Mark release as pre-release on GitHub"
echo " 2. Test beta version thoroughly"
echo " 3. When ready, run: ./create-release.sh (without --beta) to promote to stable"
fi
elif [ -n "$IS_BETA" ] && [ "$BETA" = false ]; then
# Promoting beta to stable without changelog changes - just create tag
echo "No changelog changes needed for beta promotion (same commit)"
echo "Creating stable tag on the same commit as beta..."
if [ "$DRY_RUN" = true ]; then
echo "Creating tag locally: $NEW_TAG"
git tag "$NEW_TAG"
echo "DRY-RUN: Would push tag to remote"
else
echo "Creating and pushing tag: $NEW_TAG"
git tag "$NEW_TAG"
git push origin tag "$NEW_TAG"
echo ""
echo "Creating GitHub release..."
# Check if gh CLI is installed
if command -v gh &> /dev/null; then
if gh release create "$NEW_TAG" \
--title "$NEW_TAG" \
--notes "✅ **STABLE RELEASE** (promoted from $LATEST_TAG)
## Installation
Download the latest stable build from the assets below."; then
echo "✅ Release created successfully on GitHub!"
else
echo "⚠️ Failed to create release. Please create it manually:"
echo " gh release create $NEW_TAG --generate-notes"
fi
else
echo "⚠️ GitHub CLI (gh) not found. Skipping automatic release creation."
echo " Install it from: https://cli.github.com/"
fi
run_local_linux_build "$NEW_TAG"
fi
echo ""
echo "=========================================="
echo "Release $NEW_TAG completed successfully!"
echo "=========================================="
echo "Summary:"
echo " - Previous version: $LATEST_TAG (beta)"
echo " - New version: $NEW_TAG (stable)"
echo " - Release type: $RELEASE_TYPE"
echo " - Same commit: Yes"
if [ "$DRY_RUN" = true ]; then
echo " - Tag created and pushed: (dry-run)"
else
echo " - Tag created and pushed: Yes"
echo " - Windows build: running on GitHub Actions (build-windows.yml)"
if [ "$NO_LOCAL" = true ]; then
echo " - Linux build: SKIPPED (run act manually to append)"
else
echo " - Linux build: handled locally via act"
fi
fi
elif [ "$FORCE" = true ]; then
# No changelog changes, but --force says: tag current HEAD anyway.
echo "No changelog changes, but --force set - tagging current HEAD as $NEW_TAG"
if [ "$DRY_RUN" = true ]; then
echo "Creating tag locally: $NEW_TAG"
git tag "$NEW_TAG"
echo "DRY-RUN: Would push tag to remote"
else
echo "Creating and pushing tag: $NEW_TAG"
git tag "$NEW_TAG"
git push origin tag "$NEW_TAG"
echo ""
echo "Creating GitHub release..."
if command -v gh &> /dev/null; then
if [ "$BETA" = true ]; then
if gh release create "$NEW_TAG" \
--prerelease \
--title "$NEW_TAG - Beta Pre-release" \
--notes "⚠️ **BETA PRE-RELEASE** (forced - no new commits since $LATEST_TAG)
## Feedback
Please report any issues or feedback before we promote this to stable release."; then
echo "✅ Pre-release created successfully on GitHub!"
else
echo "⚠️ Failed to create pre-release. Please create it manually:"
echo " gh release create $NEW_TAG --prerelease --generate-notes"
fi
else
if gh release create "$NEW_TAG" \
--title "$NEW_TAG" \
--notes "✅ **STABLE RELEASE** (forced - no new commits since $LATEST_TAG)
## Installation
Download the latest stable build from the assets below."; then
echo "✅ Release created successfully on GitHub!"
else
echo "⚠️ Failed to create release. Please create it manually:"
echo " gh release create $NEW_TAG --generate-notes"
fi
fi
else
echo "⚠️ GitHub CLI (gh) not found. Skipping automatic release creation."
echo " Install it from: https://cli.github.com/"
fi
run_local_linux_build "$NEW_TAG"
fi
echo ""
echo "=========================================="
echo "Release $NEW_TAG completed successfully!"
echo "=========================================="
echo "Summary:"
echo " - Previous version: $LATEST_TAG"
echo " - New version: $NEW_TAG"
echo " - Release type: $RELEASE_TYPE (forced)"
echo " - Changelog updated: No (no new commits)"
if [ "$DRY_RUN" = true ]; then
echo " - Tag created and pushed: (dry-run)"
else
echo " - Tag created and pushed: Yes"
echo " - Windows build: running on GitHub Actions (build-windows.yml)"
if [ "$NO_LOCAL" = true ]; then
echo " - Linux build: SKIPPED (run act manually to append)"
else
echo " - Linux build: handled locally via act"
fi
fi
else
echo "No changes detected in CHANGELOG.md"
echo "This might indicate that there are no new commits since the last release."
echo "Use --force / -f to tag current HEAD anyway."
exit 1
fi