-
Notifications
You must be signed in to change notification settings - Fork 3
270 lines (241 loc) · 10.4 KB
/
Copy pathci.yml
File metadata and controls
270 lines (241 loc) · 10.4 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
# Continuous integration pipeline for CopilotAtelier.
#
# * Build - calculate the version with GitVersion, build and package the
# module, then publish the output/ folder as a build artifact.
# * Test - on Linux, macOS and Windows, reuse the build artifact and run the
# Sampler test workflow on PowerShell 7.
# * Deploy - on the upstream repository, for pushes to main or v* tags,
# publish the release to GitHub and the PowerShell Gallery and
# raise the changelog pull request.
#
# Required repository secrets (Settings > Secrets and variables > Actions):
# GitHubToken - personal access token used to create the GitHub release
# and the changelog pull request.
# GalleryApiToken - PowerShell Gallery API key used to publish the module.
name: CI
# Azure DevOps renames each run to the GitVersion number via
# ##vso[build.updatebuildnumber]. GitHub Actions has no equivalent: run-name is
# evaluated before any job starts and can only see the github/inputs contexts,
# so it cannot contain a version GitVersion computes mid-run. The closest we can
# get is: show the version in the run title for tag releases (the tag IS the
# version), and stamp the computed GitVersion value into the test/deploy job
# names and the build job summary on every run (see the build job's outputs).
run-name: ${{ github.ref_type == 'tag' && format('Release {0}', github.ref_name) || '' }}
on:
push:
branches:
- main
tags:
- 'v*'
- '!v*-*'
paths-ignore:
- CHANGELOG.md
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: read
env:
buildArtifactName: output
defaultBranch: main
jobs:
build:
name: Package Module
runs-on: ubuntu-latest
# Expose the GitVersion value to downstream jobs so they can show it in their
# display names - the closest GitHub gets to Azure DevOps' run renaming.
outputs:
fullSemVer: ${{ steps.gitversion.outputs.FullSemVer }}
nuGetVersion: ${{ steps.gitversion.outputs.NuGetVersionV2 }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
# GitVersion needs the full history to calculate the version.
fetch-depth: 0
- name: Calculate ModuleVersion (GitVersion)
id: gitversion
shell: pwsh
env:
# GitVersion 5.x targets an older .NET; allow it to run on the
# runner's newer shared framework.
DOTNET_ROLL_FORWARD: LatestMajor
run: |
dotnet tool install --global GitVersion.Tool --version 5.*
# Prepend, so a GitVersion already on the image cannot shadow the pinned one.
$env:PATH = (Join-Path -Path $HOME -ChildPath '.dotnet/tools') + [System.IO.Path]::PathSeparator + $env:PATH
Write-Host -Object "Resolved dotnet-gitversion: $((Get-Command -Name dotnet-gitversion).Source)"
# GitVersion writes diagnostics and JSON to the same standard output
# stream, so piping straight into ConvertFrom-Json replaces the real
# error with a parser error and the cause is lost, and requiring the
# output to start with '{' fails a run that actually succeeded.
# GitHub sets $ErrorActionPreference to Stop, which would otherwise make a
# non-zero exit throw before the output can be shown.
$PSNativeCommandUseErrorActionPreference = $false
$gitVersionOutput = (& dotnet-gitversion 2>&1 | Out-String).Trim()
$gitVersionExitCode = $LASTEXITCODE
$outputLine = $gitVersionOutput -split '\r?\n'
$jsonStartIndex = -1
for ($i = 0; $i -lt $outputLine.Length; $i++)
{
if ($outputLine[$i].Trim() -eq '{')
{
$jsonStartIndex = $i
break
}
}
if ($gitVersionExitCode -ne 0 -or $jsonStartIndex -lt 0)
{
Write-Host -Object '--- dotnet-gitversion output ---'
Write-Host -Object $gitVersionOutput
Write-Host -Object '--- end of output ---'
throw "dotnet-gitversion exited with code $gitVersionExitCode and did not return JSON."
}
if ($jsonStartIndex -gt 0)
{
# Surfaced, not swallowed: a branch-configuration multi-match shows up
# here, and GitVersion.yml is what has to change when it does.
Write-Host -Object '--- dotnet-gitversion diagnostics ---'
Write-Host -Object ($outputLine[0..($jsonStartIndex - 1)] -join [System.Environment]::NewLine)
Write-Host -Object '--- end of diagnostics ---'
}
$gitVersionJson = $outputLine[$jsonStartIndex..($outputLine.Length - 1)] -join [System.Environment]::NewLine
try
{
$gitVersionObject = $gitVersionJson | ConvertFrom-Json -ErrorAction Stop
}
catch
{
Write-Host -Object '--- dotnet-gitversion output ---'
Write-Host -Object $gitVersionOutput
Write-Host -Object '--- end of output ---'
throw "dotnet-gitversion returned output that is not valid JSON: $($_.Exception.Message)"
}
$gitVersionObject.PSObject.Properties.ForEach{
Write-Host -Object "Setting output '$($_.Name)' with value '$($_.Value)'."
"$($_.Name)=$($_.Value)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
}
Write-Host -Object "ModuleVersion (FullSemVer): $($gitVersionObject.FullSemVer)"
"## CopilotAtelier $($gitVersionObject.FullSemVer)" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append -Encoding utf8
- name: Build & Package Module
shell: pwsh
env:
ModuleVersion: ${{ steps.gitversion.outputs.NuGetVersionV2 }}
run: ./build.ps1 -ResolveDependency -Tasks pack
- name: Publish Build Artifact
uses: actions/upload-artifact@v7
with:
name: ${{ env.buildArtifactName }}
path: output/
include-hidden-files: true
if-no-files-found: error
retention-days: 7
test:
name: Test ${{ needs.build.outputs.fullSemVer }} (${{ matrix.name }})
needs: build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# The repository also tests Windows-only customizations, so the
# non-Windows runners select the module's portable tests by tag.
- name: ubuntu-latest
artifact: ubuntu-latest
os: ubuntu-latest
arguments: "-Tasks test -PesterTag @('Unit','QA')"
- name: macos-latest
artifact: macos-latest
os: macos-latest
arguments: "-Tasks test -PesterTag @('Unit','QA')"
- name: windows-latest (PowerShell 7)
artifact: windows-latest-pwsh
os: windows-latest
arguments: '-Tasks test'
# If a leg ever needs a different interpreter, parameterise this from the
# matrix - a step's own `shell` key does not accept the matrix context.
defaults:
run:
shell: pwsh
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Download Build Artifact
uses: actions/download-artifact@v8
with:
name: ${{ env.buildArtifactName }}
path: output/
# tests/SkillsRefValidate.Tests.ps1 shells out to the upstream reference
# validator through uv. Without this step it would skip, and a skipped
# gate is a green build with no validation behind it.
# Pinned to a full release tag: setup-uv publishes no floating major
# alias past v7, so `@v8`/`@v9` do not resolve.
- name: Install uv (skills-ref reference validator)
uses: astral-sh/setup-uv@v9.0.0
- name: Run Tests
run: ./build.ps1 ${{ matrix.arguments }}
- name: Publish Test Results
if: always()
uses: actions/upload-artifact@v7
with:
name: CodeCoverage-${{ matrix.artifact }}
path: output/testResults/
if-no-files-found: warn
deploy:
name: Deploy Module ${{ needs.build.outputs.fullSemVer }}
needs: [build, test]
runs-on: ubuntu-latest
# Only deploy from the upstream repository, for pushes to the default
# branch or for version tags.
if: >-
github.repository_owner == 'raandree' &&
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Download Build Artifact
uses: actions/download-artifact@v8
with:
name: ${{ env.buildArtifactName }}
path: output/
# Sampler's release tasks skip themselves when their token is empty, and a
# skipped Publish_Release_To_GitHub still lets the Gallery publish run. That
# ships a version without the v* tag GitVersion anchors the next pre-release
# number on, so the following build recomputes the published version and the
# Gallery rejects it with HTTP 409. Fail here instead of releasing untagged.
- name: Verify Release Secrets
shell: pwsh
env:
GitHubToken: ${{ secrets.GitHubToken }}
GalleryApiToken: ${{ secrets.GalleryApiToken }}
run: |
$missingSecret = @('GitHubToken', 'GalleryApiToken') |
Where-Object -FilterScript { -not [System.Environment]::GetEnvironmentVariable($_) }
if ($missingSecret)
{
throw ("Missing repository secret: {0}. Add it under Settings > Secrets and variables > Actions." -f ($missingSecret -join ', '))
}
- name: Publish Release
shell: pwsh
env:
GitHubToken: ${{ secrets.GitHubToken }}
GalleryApiToken: ${{ secrets.GalleryApiToken }}
ModuleVersion: ${{ needs.build.outputs.nuGetVersion }}
ReleaseBranch: ${{ env.defaultBranch }}
MainGitBranch: ${{ env.defaultBranch }}
run: ./build.ps1 -Tasks publish
- name: Send Changelog PR
shell: pwsh
env:
GitHubToken: ${{ secrets.GitHubToken }}
ReleaseBranch: ${{ env.defaultBranch }}
MainGitBranch: ${{ env.defaultBranch }}
run: ./build.ps1 -Tasks Create_ChangeLog_GitHub_PR