forked from PowerShell/ConsoleGuiTools
-
-
Notifications
You must be signed in to change notification settings - Fork 2
222 lines (203 loc) · 9.03 KB
/
Copy pathrelease.yml
File metadata and controls
222 lines (203 loc) · 9.03 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
name: Release
# Release pipeline for PSTui, modeled on tui-cs/clet but adapted for a
# PowerShell *binary module* published to the PowerShell Gallery (not a
# NativeAOT CLI). See .github/workflows/README.md for the branching and
# versioning model.
#
# Branching: `develop` (default, day-to-day) -> `main` (release-only).
# A push to `main` ships a release; version is driven by PSTui.Common.props.
on:
push:
branches: [ main ]
paths:
- 'src/**'
- 'test/**'
- 'PSTui.Common.props'
- 'PSTui.build.ps1'
- '.github/workflows/release.yml'
workflow_dispatch:
inputs:
version_override:
description: 'Exact version to publish (e.g. 1.0.1 or 1.1.0-rc4). Leave blank to auto-resolve from PSTui.Common.props.'
required: false
type: string
# Allow Terminal.Gui (or other upstream) to trigger a rebuild/republish when it ships.
repository_dispatch:
types: [ terminal-gui-published ]
permissions:
contents: write # create tags and GitHub releases
issues: write # open a failure-notification issue
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
env:
DOTNET_NOLOGO: true
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
# Mapped here so it can be used in step `if:` conditions. Real publish
# only happens when the PSGALLERY_API_KEY secret is configured; otherwise
# the job is a dry run (build + test + version resolve, no publish/tag).
HAS_PSGALLERY_KEY: ${{ secrets.PSGALLERY_API_KEY != '' }}
outputs:
version: ${{ steps.version.outputs.version }}
prerelease: ${{ steps.version.outputs.prerelease }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # need full tag history for version resolution
- name: Install dotnet
uses: actions/setup-dotnet@v4
with:
cache: true
cache-dependency-path: '**/*.csproj' # SDK version comes from global.json
# The module targets PS 7.6+ (net10.0); GitHub runners ship PS 7.4, whose
# Test-ModuleManifest / Publish-PSResource reject the manifest. Install
# PS 7.6 as a .NET tool and put it ahead of the bundled pwsh on PATH so
# every `shell: pwsh` step below (incl. Install PSResources) runs under it.
- name: Install PowerShell 7.6+
shell: bash
run: |
# The repo nuget.config clears sources and lists only the
# authenticated PowerShell CFS feed, which 401s on the `PowerShell`
# tool. Use a throwaway config with only nuget.org so the CFS feed
# is never consulted for this install (--ignore-failed-sources isn't
# honored during tool version resolution).
cat > "$RUNNER_TEMP/nuget.org.config" <<'EOF'
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
EOF
dotnet tool install --global --version "7.6.*" PowerShell \
--configfile "$RUNNER_TEMP/nuget.org.config"
echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH"
- name: Verify PowerShell version
shell: pwsh
run: |
"Using PowerShell $($PSVersionTable.PSVersion) at $((Get-Command pwsh).Source)"
if ($PSVersionTable.PSVersion -lt [version]'7.6') {
throw "Expected PowerShell 7.6+, got $($PSVersionTable.PSVersion)"
}
- name: Resolve version
id: version
shell: pwsh
run: |
# Source of truth: PSTui.Common.props
# <VersionPrefix> = base version (e.g. 1.0.0)
# <VersionSuffix> = prerelease phase, empty for stable (e.g. rc, beta, alpha)
# PowerShell prerelease labels are alphanumeric only (no dots), so we
# emit e.g. "rc4" -> version 1.0.0-rc4, tag v1.0.0-rc4.
[xml]$props = Get-Content ./PSTui.Common.props
$pg = $props.Project.PropertyGroup
$prefix = ([string]($pg.VersionPrefix | Select-Object -First 1)).Trim()
$suffix = ([string]($pg.VersionSuffix | Select-Object -First 1)).Trim()
$override = '${{ github.event.inputs.version_override }}'.Trim()
if ($override) {
$full = $override
if ($full -match '-') { $base, $pre = $full -split '-', 2 } else { $base = $full; $pre = '' }
}
elseif ($suffix) {
# Prerelease phase: increment the build number off existing tags.
$existing = git tag --list "v$prefix-$suffix*" |
ForEach-Object { if ($_ -match "^v$([regex]::Escape($prefix))-$([regex]::Escape($suffix))(\d+)$") { [int]$Matches[1] } }
$next = 1 + (($existing | Measure-Object -Maximum).Maximum)
$pre = "$suffix$next"
$base = $prefix
$full = "$prefix-$pre"
}
else {
# Stable phase: start at the prefix and bump the patch until we find
# a version that isn't already tagged (so successive releases off the
# same VersionPrefix don't collide with an already-published patch).
$base = $prefix; $pre = ''
while (git tag --list "v$base") {
$p = $base -split '\.'
$p[2] = [string]([int]$p[2] + 1)
$base = $p -join '.'
}
$full = $base
}
$isPre = [bool]$pre
Write-Host "Resolved version: $full (base=$base, prerelease='$pre')"
"version=$full" >> $env:GITHUB_OUTPUT
"baseversion=$base" >> $env:GITHUB_OUTPUT
"prereleaselabel=$pre" >> $env:GITHUB_OUTPUT
"prerelease=$($isPre.ToString().ToLowerInvariant())" >> $env:GITHUB_OUTPUT
- name: Install PSResources
shell: pwsh
run: ./tools/installPSResources.ps1
- name: Build and test
shell: pwsh
run: Invoke-Build -Configuration Release Build, Test
- name: Stamp module version
shell: pwsh
run: |
$manifest = './module/PSTui.psd1'
$base = '${{ steps.version.outputs.baseversion }}'
$pre = '${{ steps.version.outputs.prereleaselabel }}'
$c = Get-Content -Raw $manifest
$c = $c -replace "ModuleVersion = '[^']*'", "ModuleVersion = '$base'"
if ($pre) { $c = $c -replace "#\s*Prerelease = ''", "Prerelease = '$pre'" }
Set-Content -Path $manifest -Value $c
Test-ModuleManifest -Path $manifest | Format-List Name, Version, PrivateData
# Publishing is hard-locked to `main`: even with the key present, a
# workflow_dispatch on develop is a safe dry run (build/test/stamp only).
- name: Publish to PowerShell Gallery
if: env.HAS_PSGALLERY_KEY == 'true' && github.ref == 'refs/heads/main'
shell: pwsh
env:
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
run: |
Publish-PSResource -Path ./module -Repository PSGallery -ApiKey $env:PSGALLERY_API_KEY -Verbose
- name: Package module artifact
shell: pwsh
run: Compress-Archive -Path ./module/* -DestinationPath "PSTui-${{ steps.version.outputs.version }}.zip"
- name: Tag and create GitHub Release
if: env.HAS_PSGALLERY_KEY == 'true' && github.ref == 'refs/heads/main'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
prerelease: ${{ steps.version.outputs.prerelease == 'true' }}
generate_release_notes: true
files: PSTui-${{ steps.version.outputs.version }}.zip
- name: Upload artifact (always)
if: always()
uses: actions/upload-artifact@v4
with:
name: PSTui-${{ steps.version.outputs.version }}
path: module
notify-failure:
needs: release
if: failure()
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Open or update failure issue
uses: actions/github-script@v7
with:
script: |
const title = 'Release workflow failed';
const url = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const body = `The [Release workflow](${url}) failed on \`${context.sha.substring(0,7)}\`.`;
const existing = await github.rest.issues.listForRepo({
owner: context.repo.owner, repo: context.repo.repo,
state: 'open', labels: 'release-failure',
});
if (existing.data.length) {
await github.rest.issues.createComment({
owner: context.repo.owner, repo: context.repo.repo,
issue_number: existing.data[0].number, body,
});
} else {
await github.rest.issues.create({
owner: context.repo.owner, repo: context.repo.repo,
title, body, labels: ['release-failure'],
});
}