Repository navigation
371 lines (346 loc) · 17.7 KB
/
Copy pathrelease.yml
File metadata and controls
371 lines (346 loc) · 17.7 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
name: Release
# Two ways to publish a release (a version with a hyphen, like 1.6.0-alpha.3, is a pre-release):
# - Actions > Release > Run workflow on main, with the version and "publish" ticked: the tag and the
# release are created here, from main.
# - Push a tag like v1.3.0 (stable) or v1.3.0-beta.2 (pre-release).
# With "publish" unticked the workflow only builds and uploads the files as an artifact.
# The app's update check (UpdateService) reads these releases and looks for the
# ConsoleMode-Setup-*.exe / ConsoleMode-Portable-*.exe assets built here.
#
# "draft" (with "publish"): the release is created as a draft. Only people with write access see a draft:
# the app's update check doesn't, nothing goes to winget and the tag isn't created yet. Publishing the draft
# on GitHub creates the tag on the commit that was built, and winget.yml then sends it to winget.
#
# "legacy": a branch built next to this one (release/1.7-legacy: 1.6.2's interfaces, frozen) and attached to
# the same release as ConsoleModeLegacy-*.exe. GitHub lists a release's files by name, so those come after the
# current version's; and they don't start like the ones the update check and winget look for, so nobody is
# updated to Legacy.
#
# Publishing a draft creates its tag, and that tag push starts this workflow again. The "guard" job stops that
# run: the release is out already, with the files that were tested, and winget.yml sends it to winget. (On 1.7.0
# the second run rebuilt and replaced the installer and the portable after publishing, dropped the Legacy part
# of the notes, and winget rejected the submission made a moment before for a hash that no longer matched.)
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
version:
description: "Version (e.g. 1.6.0-alpha.3). A hyphen makes it a pre-release."
required: true
publish:
description: "Publish: create the tag and the GitHub release (only from main). Unticked, just build."
type: boolean
default: false
draft:
description: "Draft: with Publish, create the release as a draft (no update notice, no winget, no tag yet)."
type: boolean
default: false
legacy:
description: "Legacy: branch to build and attach as ConsoleModeLegacy-*.exe (e.g. release/1.7-legacy). Empty: none."
required: false
default: ""
permissions:
contents: write
# The build job fetches the Legacy job's files of this same run.
actions: read
jobs:
# A pushed tag whose release is already published (a draft that was just published) has nothing left to do.
guard:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
skip: ${{ steps.check.outputs.skip }}
steps:
- name: Is the release already published?
id: check
env:
GH_TOKEN: ${{ github.token }}
EVENT_NAME: ${{ github.event_name }}
TAG: ${{ github.ref_name }}
REPO: ${{ github.repository }}
run: |
skip=false
if [ "$EVENT_NAME" = "push" ] && [ "$(gh release view "$TAG" --repo "$REPO" --json isDraft --jq .isDraft 2>/dev/null)" = "false" ]; then
skip=true
echo "A release $TAG já está publicada (veio de um rascunho): nada a fazer."
fi
echo "skip=$skip" >> "$GITHUB_OUTPUT"
# The Legacy build: the branch's own code, tests and publish script, with the version of this release.
legacy:
if: github.event_name == 'workflow_dispatch' && github.event.inputs.legacy != ''
runs-on: windows-latest
# It runs the code of a branch named at run time: read-only, and the token doesn't stay in the checkout.
# Its files reach the release through the artifact, attached by the build job.
permissions:
contents: read
steps:
- name: Checkout the Legacy branch
uses: actions/checkout@v7
with:
ref: ${{ github.event.inputs.legacy }}
persist-credentials: false
- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: "8.0.x"
- name: Resolve version
id: version
shell: pwsh
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
run: |
$v = $env:INPUT_VERSION.TrimStart("v")
if ($v -notmatch '^\d+\.\d+\.\d+(-[0-9A-Za-z.\-]+)?$') { throw "Versão inválida: $v" }
"version=$v" >> $env:GITHUB_OUTPUT
- name: Run tests
shell: pwsh
run: dotnet test tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj -c Release --nologo
- name: Install Inno Setup (if missing)
shell: pwsh
run: |
if (-not (Test-Path "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe")) { choco install innosetup -y --no-progress }
- name: Build portable + installer
shell: pwsh
run: .\build\Publish-ConsoleMode.ps1 -Runtime x64 -Target All -Version "${{ steps.version.outputs.version }}"
- name: Name the files Legacy
shell: pwsh
run: |
Rename-Item -LiteralPath "dist/ConsoleMode-Setup-x64.exe" -NewName "ConsoleModeLegacy-Setup-x64.exe"
Rename-Item -LiteralPath "dist/ConsoleMode-Portable-x64.exe" -NewName "ConsoleModeLegacy-Portable-x64.exe"
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: ConsoleModeLegacy-${{ steps.version.outputs.version }}
path: |
dist/ConsoleModeLegacy-Setup-x64.exe
dist/ConsoleModeLegacy-Portable-x64.exe
if-no-files-found: error
build:
needs: [guard, legacy]
# Without Legacy that job is skipped, and a skipped job would skip this one too.
if: ${{ !cancelled() && needs.guard.result == 'success' && needs.guard.outputs.skip != 'true' && (needs.legacy.result == 'success' || needs.legacy.result == 'skipped') }}
runs-on: windows-latest
outputs:
version: ${{ steps.version.outputs.version }}
prerelease: ${{ steps.version.outputs.prerelease }}
publish: ${{ steps.version.outputs.publish }}
draft: ${{ steps.version.outputs.draft }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: "8.0.x"
- name: Resolve version
id: version
shell: pwsh
env:
EVENT_NAME: ${{ github.event_name }}
REF_NAME: ${{ github.ref_name }}
REF: ${{ github.ref }}
INPUT_VERSION: ${{ github.event.inputs.version }}
INPUT_PUBLISH: ${{ github.event.inputs.publish }}
INPUT_DRAFT: ${{ github.event.inputs.draft }}
run: |
$v = if ($env:EVENT_NAME -eq "push") { $env:REF_NAME } else { $env:INPUT_VERSION }
$v = $v.TrimStart("v")
if ($v -notmatch '^\d+\.\d+\.\d+(-[0-9A-Za-z.\-]+)?$') { throw "Versão inválida: $v" }
$publish = ($env:EVENT_NAME -eq "push") -or ($env:INPUT_PUBLISH -eq "true")
if ($publish -and $env:EVENT_NAME -ne "push") {
# Publishing by hand creates the tag here: only from main, and never over a tag that exists.
if ($env:REF -ne "refs/heads/main") { throw "Só dá para publicar a partir da main (rodando em $($env:REF))." }
if (git ls-remote --tags origin "refs/tags/v$v") { throw "A tag v$v já existe." }
}
"version=$v" >> $env:GITHUB_OUTPUT
"prerelease=$($v.Contains('-').ToString().ToLower())" >> $env:GITHUB_OUTPUT
"publish=$($publish.ToString().ToLower())" >> $env:GITHUB_OUTPUT
# A draft is only for a release made here: a pushed tag is public already.
$draft = $publish -and ($env:EVENT_NAME -ne "push") -and ($env:INPUT_DRAFT -eq "true")
"draft=$($draft.ToString().ToLower())" >> $env:GITHUB_OUTPUT
- name: Prepare release notes (English, a link to the Portuguese changelog, a summary per translated changelog)
if: steps.version.outputs.publish == 'true'
shell: pwsh
env:
VERSION: ${{ steps.version.outputs.version }}
LEGACY: ${{ github.event.inputs.legacy }}
run: |
function Get-Notes([string]$file) {
$changelog = Get-Content -LiteralPath $file -Raw -Encoding utf8
$pattern = "(?ms)^## \[$([regex]::Escape($env:VERSION))\]\r?\n(?<notes>.*?)(?=^## \[|\z)"
$match = [regex]::Match($changelog, $pattern)
if (-not $match.Success) { throw "$file precisa conter a seção ## [$($env:VERSION)]." }
$notes = $match.Groups["notes"].Value.Trim()
if ([string]::IsNullOrWhiteSpace($notes)) { throw "A seção $($env:VERSION) de $file está vazia." }
return $notes
}
# Both changelogs must have the section; the Portuguese one is linked, not pasted.
$pt = Get-Notes "CHANGELOG.md"
$en = Get-Notes "CHANGELOG.en-US.md"
# One hidden "<!-- summary <code>: ... -->" line per translated changelog (CHANGELOG.md is
# pt-BR, any CHANGELOG.<code>.md another language): the update notice shows it instead
# of the English first item (ReleaseNotes.cs). They go at the very end of the body, so
# clients up to 1.6.x, which show the first line they find, keep showing the English one.
function Get-FirstItem([string]$notes) {
$item = $notes -split "\r?\n" | Where-Object { $_ -match '^\s*[-*]\s+\S' } | Select-Object -First 1
if (-not $item) { return $null }
return ($item -replace '^\s*[-*]\s+', '' -replace '-->', '').Trim()
}
$summaries = @()
$ptItem = Get-FirstItem $pt
if ($ptItem) { $summaries += "<!-- summary pt-BR: $ptItem -->" }
foreach ($file in Get-ChildItem -Name -Filter "CHANGELOG.*.md" | Where-Object { $_ -ne "CHANGELOG.en-US.md" } | Sort-Object) {
$code = $file -replace '^CHANGELOG\.|\.md$', ''
# Optional: a translated changelog without this version's section is skipped, not fatal.
$notes = try { Get-Notes $file } catch { Write-Host "$file sem a seção $($env:VERSION); sem resumo em $code."; $null }
$item = if ($notes) { Get-FirstItem $notes }
if ($item) { $summaries += "<!-- summary ${code}: $item -->" }
}
# English, no language headings: ReleaseNotes.cs shows its first item to every
# language without a summary. A "(#NN)" at the end of an item becomes a link to that PR on GitHub.
$tag = "v$($env:VERSION)"
$releaseNotes = @(
$en
""
"### Downloads"
""
# Single quotes: in double-quoted pwsh strings the backtick is an escape and the Markdown code spans vanish.
'- **Installer:** `ConsoleMode-Setup-x64.exe` — installs the app and offers shortcuts and starting with Windows.'
'- **Portable:** `ConsoleMode-Portable-x64.exe` — a single executable; keeps its data in the `ConsoleMode_Data` folder next to the file.'
)
if ($env:LEGACY) {
$releaseNotes += @(
""
"### Legacy"
""
"Prefer the old interface? **Console Mode Legacy** is 1.6.2 as it was, with the Desktop and Console interfaces. It opens with the settings you already have and keeps the ones only the current version uses, so you can switch back and forth. It is frozen: no new features, no fixes, and it never offers an update. To come back, install the current version over it."
""
'- **Legacy installer:** `ConsoleModeLegacy-Setup-x64.exe`'
'- **Legacy portable:** `ConsoleModeLegacy-Portable-x64.exe`'
)
}
$releaseNotes += @(
""
"---"
""
"🇧🇷 Notas em português: [CHANGELOG.md](https://github.com/lippdev/consolemode/blob/$tag/CHANGELOG.md)"
)
if ($summaries.Count -gt 0) { $releaseNotes += @("") + $summaries }
$releaseNotes = $releaseNotes -join "`n"
Set-Content -LiteralPath "release-notes.md" -Value $releaseNotes -Encoding utf8
- name: Run tests
shell: pwsh
run: dotnet test tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj -c Release --nologo
- name: Install Inno Setup (if missing)
shell: pwsh
run: |
if (-not (Test-Path "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe")) { choco install innosetup -y --no-progress }
- name: Build portable + installer
shell: pwsh
run: .\build\Publish-ConsoleMode.ps1 -Runtime x64 -Target All -Version "${{ steps.version.outputs.version }}"
# Code signing (docs/CODE_SIGNING.md). Off until the SignPath repository variables exist:
# SIGNPATH_ORGANIZATION_ID, SIGNPATH_PROJECT_SLUG, SIGNPATH_POLICY_SLUG, plus the
# SIGNPATH_API_TOKEN secret. Only published releases are signed; each request waits for manual approval.
- name: Upload unsigned build for signing
id: unsigned
if: steps.version.outputs.publish == 'true' && vars.SIGNPATH_ORGANIZATION_ID != ''
uses: actions/upload-artifact@v7
with:
name: unsigned-${{ steps.version.outputs.version }}
path: |
dist/ConsoleMode-Setup-x64.exe
dist/ConsoleMode-Portable-x64.exe
if-no-files-found: error
- name: Sign with SignPath
if: steps.version.outputs.publish == 'true' && vars.SIGNPATH_ORGANIZATION_ID != ''
uses: signpath/github-action-submit-signing-request@v3
with:
api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
organization-id: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
project-slug: ${{ vars.SIGNPATH_PROJECT_SLUG }}
signing-policy-slug: ${{ vars.SIGNPATH_POLICY_SLUG }}
github-artifact-id: ${{ steps.unsigned.outputs.artifact-id }}
wait-for-completion: true
wait-for-completion-timeout-in-seconds: 3600
output-artifact-directory: dist-signed
- name: Use the signed files
if: steps.version.outputs.publish == 'true' && vars.SIGNPATH_ORGANIZATION_ID != ''
shell: pwsh
run: |
foreach ($name in "ConsoleMode-Setup-x64.exe", "ConsoleMode-Portable-x64.exe") {
$signed = Join-Path "dist-signed" $name
if (-not (Test-Path -LiteralPath $signed)) { throw "SignPath did not return $name" }
if ((Get-AuthenticodeSignature -LiteralPath $signed).Status -ne "Valid") { throw "$name is not validly signed" }
Copy-Item -LiteralPath $signed -Destination (Join-Path "dist" $name) -Force
}
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: ConsoleMode-${{ steps.version.outputs.version }}
path: |
dist/ConsoleMode-Setup-x64.exe
dist/ConsoleMode-Portable-x64.exe
if-no-files-found: error
# The Legacy job's files of this run, next to the ones built here.
- name: Fetch the Legacy build
id: legacy
if: github.event_name == 'workflow_dispatch' && github.event.inputs.legacy != ''
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
run: |
gh run download $env:GITHUB_RUN_ID --repo $env:GITHUB_REPOSITORY --name "ConsoleModeLegacy-$($env:VERSION)" --dir dist
foreach ($name in "ConsoleModeLegacy-Setup-x64.exe", "ConsoleModeLegacy-Portable-x64.exe") {
if (-not (Test-Path -LiteralPath (Join-Path "dist" $name))) { throw "The Legacy build did not bring $name" }
}
# A multi-line value for the release step below.
"files<<LIST" >> $env:GITHUB_OUTPUT
"dist/ConsoleModeLegacy-Setup-x64.exe" >> $env:GITHUB_OUTPUT
"dist/ConsoleModeLegacy-Portable-x64.exe" >> $env:GITHUB_OUTPUT
"LIST" >> $env:GITHUB_OUTPUT
- name: Publish GitHub release
if: steps.version.outputs.publish == 'true'
uses: softprops/action-gh-release@v3
with:
# Pushed tag: it already exists. Run by hand: it is created here, on the commit that was built
# (for a draft, when the draft is published).
tag_name: v${{ steps.version.outputs.version }}
target_commitish: ${{ github.sha }}
name: Console Mode ${{ steps.version.outputs.version }}
prerelease: ${{ steps.version.outputs.prerelease }}
draft: ${{ steps.version.outputs.draft }}
fail_on_unmatched_files: true
generate_release_notes: false
append_body: false
body_path: release-notes.md
files: |
dist/ConsoleMode-Setup-x64.exe
dist/ConsoleMode-Portable-x64.exe
${{ steps.legacy.outputs.files }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Opens the update PR on microsoft/winget-pkgs for stable releases (pre-releases and drafts are skipped;
# a draft goes to winget when it is published, through winget.yml).
# Off until the WINGET_TOKEN secret exists: a classic PAT with the public_repo scope, from the
# account that owns the lippdev/winget-pkgs fork.
winget:
needs: build
# "!cancelled()": the build job may have a skipped job (Legacy) before it.
if: ${{ !cancelled() && needs.build.result == 'success' && needs.build.outputs.publish == 'true' && needs.build.outputs.prerelease == 'false' && needs.build.outputs.draft != 'true' }}
runs-on: ubuntu-latest
env:
WINGET_TOKEN: ${{ secrets.WINGET_TOKEN }}
steps:
- name: Submit to winget-pkgs
if: env.WINGET_TOKEN != ''
uses: vedantmgoyal9/winget-releaser@v2
with:
identifier: lippdev.ConsoleMode
release-tag: v${{ needs.build.outputs.version }}
installers-regex: 'ConsoleMode-Setup-x64\.exe$'
fork-user: lippdev
token: ${{ env.WINGET_TOKEN }}