-
-
Notifications
You must be signed in to change notification settings - Fork 52
79 lines (69 loc) · 2.58 KB
/
Copy pathcreate-release.yml
File metadata and controls
79 lines (69 loc) · 2.58 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
name: Create GitHub Release
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Validate tag source
shell: bash
run: |
set -euo pipefail
TAG_NAME="${GITHUB_REF_NAME}"
TAG_COMMIT="${GITHUB_SHA}"
if [[ "${TAG_NAME}" =~ -(alpha|beta|rc) ]]; then
echo "Pre-release tag detected: ${TAG_NAME}"
if git merge-base --is-ancestor "${TAG_COMMIT}" origin/develop; then
echo 'Tag commit is reachable from develop.'
else
echo 'Tag commit is NOT reachable from develop.' >&2
exit 1
fi
else
echo "Stable tag detected: ${TAG_NAME}"
if git merge-base --is-ancestor "${TAG_COMMIT}" origin/main; then
echo 'Tag commit is reachable from main.'
else
echo 'Tag commit is NOT reachable from main.' >&2
exit 1
fi
fi
- name: Create GitHub release
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$ErrorActionPreference = 'Stop'
$tagName = $env:GITHUB_REF_NAME
$versionName = $tagName.TrimStart('v')
$notesPath = Join-Path -Path $env:RUNNER_TEMP -ChildPath 'release-notes.md'
$changelog = Get-Content -Path (Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'CHANGELOG.md') -Raw
$escapedVersion = [regex]::Escape($versionName)
$pattern = "(?ms)^##\s+.*?Version\s+$escapedVersion\s*$\r?\n(?<body>.*?)(?=^##\s+|\z)"
$match = [regex]::Match($changelog, $pattern)
if ($match.Success) {
$notes = $match.Groups['body'].Value.Trim()
Set-Content -Path $notesPath -Value $notes -Encoding UTF8
}
$preReleaseFlag = @()
if ($tagName -match '-(alpha|beta|rc)') {
$preReleaseFlag = @('--prerelease')
}
if (gh release view $tagName *> $null) {
gh release delete $tagName --yes
}
if ((Test-Path -Path $notesPath) -and -not [string]::IsNullOrWhiteSpace((Get-Content -Path $notesPath -Raw))) {
gh release create $tagName @preReleaseFlag --title $tagName --notes-file $notesPath
} else {
gh release create $tagName @preReleaseFlag --title $tagName --generate-notes
}