forked from Guovin/iptv-api
-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathrelease-from-commit-messages.yml
More file actions
203 lines (164 loc) · 5.99 KB
/
Copy pathrelease-from-commit-messages.yml
File metadata and controls
203 lines (164 loc) · 5.99 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
name: Release from commit messages
on:
workflow_dispatch:
permissions:
contents: write
jobs:
build-and-release:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.13'
update-environment: true
cache: 'pipenv'
- name: Install pipenv
shell: pwsh
run: python -m pip install --upgrade pip pipenv
- name: Install dependencies with pipenv
shell: pwsh
run: |
pipenv --python 3.13
pipenv install --dev
- name: Build the application
shell: pwsh
run: pipenv run pyinstaller --clean --noconfirm tkinter_ui/tkinter_ui.spec
- name: Read version info
id: version
shell: pwsh
run: |
if (-not (Test-Path -Path version.json)) {
Write-Error 'version.json not found.'
exit 1
}
$json = Get-Content version.json -Raw | ConvertFrom-Json
if (-not $json.name -or -not $json.version) {
Write-Error 'version.json must contain name and version.'
exit 1
}
Add-Content -Path $env:GITHUB_ENV -Value "name=$($json.name)"
Add-Content -Path $env:GITHUB_ENV -Value "version=$($json.version)"
Add-Content -Path $env:GITHUB_ENV -Value "release_tag=$($json.version)"
Add-Content -Path $env:GITHUB_ENV -Value "release_title=v$($json.version)"
- name: Validate release tag does not already exist
shell: pwsh
run: |
$tag = $env:release_tag
if (-not $tag) {
Write-Error 'release_tag is empty.'
exit 1
}
$existingTag = git tag --list $tag
if ($existingTag) {
Write-Error "Tag '$tag' already exists. Bump version.json before releasing."
exit 1
}
- name: Generate release notes from commit messages
id: notes
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$versionCommits = @(git log --format=%H -- version.json)
$baseCommit = ''
if ($versionCommits.Count -ge 2) {
$baseCommit = $versionCommits[1].Trim()
} elseif ($versionCommits.Count -eq 1) {
$baseCommit = $versionCommits[0].Trim()
}
if (-not $baseCommit) {
try {
$baseCommit = (git describe --tags --abbrev=0).Trim()
} catch {
$baseCommit = ''
}
}
if (-not $baseCommit) {
$baseCommit = (git rev-list --max-parents=0 HEAD | Select-Object -First 1).Trim()
}
$rawMessages = git log --reverse --format=%s "$baseCommit..HEAD"
$skipPatterns = @(
'^(?i)release:\s*v?\d',
'^(?i)release\b',
'^(?i)chore:\s*version\b',
'^(?i)chore(?:\(.+\))?:\s*bump\s+version\b',
'^(?i)bump\s+version\b',
'^(?i)version\s+update\b',
'^(?i)merge\s+pull\s+request\b',
'^(?i)merge\b'
)
$notesLines = New-Object System.Collections.Generic.List[string]
foreach ($line in $rawMessages) {
$message = $line.Trim()
if (-not $message) { continue }
$skip = $false
foreach ($pattern in $skipPatterns) {
if ($message -match $pattern) {
$skip = $true
break
}
}
if ($skip) { continue }
$notesLines.Add("- $message")
}
$notesPath = Join-Path $PWD 'release-notes.md'
$content = New-Object System.Collections.Generic.List[string]
$content.AddRange($notesLines)
$content | Set-Content -Path $notesPath -Encoding utf8
Add-Content -Path $env:GITHUB_ENV -Value "base_commit=$baseCommit"
Add-Content -Path $env:GITHUB_OUTPUT -Value "notes_path=$notesPath"
- name: Summarize release notes
shell: pwsh
run: |
Write-Host "Release notes generated from base commit: $env:base_commit"
Get-Content "${{ steps.notes.outputs.notes_path }}" | ForEach-Object {
Write-Host $_
}
- name: Package dist into zip
id: package
shell: pwsh
run: |
$zipName = "$($env:name)-v$($env:version).zip"
$zipPath = Join-Path $PWD $zipName
if (-not (Test-Path -Path dist)) {
Write-Error 'dist directory not found. Build failed.'
exit 1
}
if (Test-Path $zipPath) {
Remove-Item $zipPath -Force
}
Compress-Archive -Path dist\* -DestinationPath $zipPath
if (-not (Test-Path $zipPath)) {
Write-Error 'Zip creation failed.'
exit 1
}
$size = (Get-Item $zipPath).Length
if ($size -gt 2147483648) {
Write-Error "Zip size ($size bytes) exceeds GitHub's 2 GB limit."
exit 1
}
Add-Content -Path $env:GITHUB_OUTPUT -Value "zip_path=$zipPath"
Add-Content -Path $env:GITHUB_OUTPUT -Value "zip_name=$zipName"
- name: Publish GitHub release
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$tag = $env:release_tag
$title = $env:release_title
$zipPath = "${{ steps.package.outputs.zip_path }}"
$notesPath = "${{ steps.notes.outputs.notes_path }}"
if (-not $env:GH_TOKEN) {
Write-Error 'GH_TOKEN is not available.'
exit 1
}
gh release create $tag $zipPath --title $title --notes-file $notesPath --target $env:GITHUB_SHA
- name: Confirm release
shell: pwsh
run: |
Write-Host "Released version $env:version with asset ${{ steps.package.outputs.zip_name }}."