-
-
Notifications
You must be signed in to change notification settings - Fork 465
271 lines (251 loc) · 10.3 KB
/
Copy pathci.yml
File metadata and controls
271 lines (251 loc) · 10.3 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
name: pyRevit CI
on:
pull_request:
types: [opened, reopened]
branches: [develop, master]
paths:
- '.github/workflows/**'
- 'build/**'
- 'dev/**'
- 'extensions/**'
- 'pyrevitlib/**'
- 'release/**'
- 'site-packages/**'
push:
branches: [develop, master]
tags: ['v*']
paths:
- '.github/workflows/**'
- 'build/**'
- 'dev/**'
- 'extensions/**'
- 'pyrevitlib/**'
- 'release/**'
- 'site-packages/**'
workflow_dispatch:
permissions:
contents: read
actions: read
env:
MainRepo: "pyrevitlabs/pyRevit"
concurrency:
group: pyrevit-ci-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
permissions:
contents: write
actions: read
packages: write
outputs:
build_version: ${{ steps.versionmeta.outputs.build_version }}
install_version: ${{ steps.versionmeta.outputs.install_version }}
runs-on: windows-2025
steps:
- name: Checkout Repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
submodules: recursive
token: ${{ secrets.SUBMODULES_TOKEN || github.token }}
- name: Cache NuGet packages
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Build.props', 'build/Build.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Run CI pipeline
working-directory: build
env:
DOTNET_ENVIRONMENT: ${{ github.repository == env.MainRepo && 'Production' || 'Development' }}
Build__Channel: ${{ github.ref == 'refs/heads/develop' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && 'wip' || ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) && 'release') || 'none' }}
run: dotnet run -c Release -- ci
- name: Run build unit tests
working-directory: build
run: dotnet test tests/Build.Tests.csproj -c Release
- name: Capture build versions
id: versionmeta
shell: bash
run: |
echo "build_version=$(tr -d '\r\n' < pyrevitlib/pyrevit/version)" >> "$GITHUB_OUTPUT"
echo "install_version=$(tr -d '\r\n' < release/version)" >> "$GITHUB_OUTPUT"
- name: Upload unsigned bin artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: unsigned-bin-${{ github.sha }}
path: bin/**
- name: Publish unsigned bin to GitHub Release
if: >
github.repository == env.MainRepo &&
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
(github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')
shell: pwsh
working-directory: ${{ github.workspace }}
env:
GH_TOKEN: ${{ github.token }}
BRANCH_NAME: ${{ github.ref_name }}
COMMIT_SHA: ${{ github.sha }}
run: |
$ErrorActionPreference = 'Stop'
$branch = $env:BRANCH_NAME
$sha = $env:COMMIT_SHA
$safeBranch = $branch -replace '[/\\]', '-'
$shaZip = "unsigned-bin-$sha.zip"
$branchZip = "unsigned-bin-$safeBranch-latest.zip"
Compress-Archive -Path bin -DestinationPath $shaZip -Force
Copy-Item $shaZip $branchZip -Force
gh release view ci-binaries 2>$null
if ($LASTEXITCODE -ne 0) {
gh release create ci-binaries --prerelease --title "CI Binaries" --notes "Pre-built bin/ from CI (anonymous download for pyrevit clone)."
}
gh release upload ci-binaries $shaZip --clobber
gh release upload ci-binaries $branchZip --clobber
- name: Prune old CI bin release assets
if: >
github.repository == env.MainRepo &&
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
(github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$ErrorActionPreference = 'Stop'
$keep = New-Object System.Collections.Generic.HashSet[string]
foreach ($branch in @('develop', 'master')) {
$runs = gh api "repos/pyrevitlabs/pyRevit/actions/workflows/ci.yml/runs" `
-f branch=$branch -f status=completed -f per_page=10 `
--jq '.workflow_runs[] | select(.conclusion=="success") | .head_sha'
$runs | Select-Object -First 3 | ForEach-Object { [void]$keep.Add($_) }
}
$assets = gh release view ci-binaries --json assets --jq '.assets[].name'
foreach ($asset in $assets) {
if ($asset -match '^unsigned-bin-.+-latest\.zip$') { continue }
if ($asset -notmatch '^unsigned-bin-([a-f0-9]{40})\.zip$') { continue }
$sha = $Matches[1]
if (-not $keep.Contains($sha)) {
gh release delete-asset ci-binaries $asset --yes
}
}
- name: Publish unsigned bin NuGet package
if: >
github.repository == env.MainRepo &&
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
(github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')
shell: pwsh
working-directory: ${{ github.workspace }}
env:
GITHUB_TOKEN: ${{ github.token }}
COMMIT_SHA: ${{ github.sha }}
run: |
$ErrorActionPreference = 'Stop'
$sha = $env:COMMIT_SHA
$shortSha = $sha.Substring(0, 7)
$version = "1.0.0-ci-$shortSha"
$shaZip = "unsigned-bin-$sha.zip"
if (-not (Test-Path $shaZip)) {
Compress-Archive -Path bin -DestinationPath $shaZip -Force
}
$nugetVersion = '6.12.2'
$nugetUrl = "https://dist.nuget.org/win-x86-commandline/v$nugetVersion/nuget.exe"
Invoke-WebRequest -Uri $nugetUrl -OutFile nuget.exe
$nuget = ".\nuget.exe"
$nuspec = @"
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>PyRevit.UnsignedBin</id>
<version>$version</version>
<authors>pyRevitLabs</authors>
<description>Unsigned pyRevit bin/ output from CI commit $sha</description>
</metadata>
<files>
<file src="$shaZip" target="content" />
</files>
</package>
"@
Set-Content -Path PyRevit.UnsignedBin.nuspec -Value $nuspec -Encoding UTF8
& $nuget pack PyRevit.UnsignedBin.nuspec -OutputDirectory .
dotnet nuget push "PyRevit.UnsignedBin.$version.nupkg" `
--source "https://nuget.pkg.github.com/pyrevitlabs/index.json" `
--api-key $env:GITHUB_TOKEN `
--skip-duplicate
- name: Prune old CI bin NuGet package versions
if: >
github.repository == env.MainRepo &&
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
(github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$ErrorActionPreference = 'Stop'
$keep = New-Object System.Collections.Generic.HashSet[string]
foreach ($branch in @('develop', 'master')) {
$runs = gh api "repos/pyrevitlabs/pyRevit/actions/workflows/ci.yml/runs" `
-f branch=$branch -f status=completed -f per_page=10 `
--jq '.workflow_runs[] | select(.conclusion=="success") | .head_sha'
$runs | Select-Object -First 2 | ForEach-Object { [void]$keep.Add($_) }
}
$versions = gh api --paginate "orgs/pyrevitlabs/packages/nuget/pyrevit.unsignedbin/versions" | ConvertFrom-Json
foreach ($version in $versions) {
if ($version.name -notmatch '^1\.0\.0-ci-([a-f0-9]{7})$') { continue }
$shortSha = $Matches[1]
$shouldKeep = $false
foreach ($fullSha in $keep) {
if ($fullSha.StartsWith($shortSha)) {
$shouldKeep = $true
break
}
}
if (-not $shouldKeep) {
gh api --method DELETE "orgs/pyrevitlabs/packages/nuget/pyrevit.unsignedbin/versions/$($version.id)"
Write-Host "Deleted package version $($version.name) (id=$($version.id))."
}
}
- name: Upload stamped release metadata
if: github.repository == env.MainRepo
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: stamped-release-metadata-${{ github.sha }}
path: ci-stamped/**
wip:
needs: build
if: >
github.repository == 'pyrevitlabs/pyRevit' &&
github.ref == 'refs/heads/develop' &&
(github.event_name == 'push' || github.event_name == 'workflow_dispatch')
permissions:
contents: read
actions: write
uses: ./.github/workflows/wip.yml
with:
head_sha: ${{ github.sha }}
ci_run_id: ${{ github.run_id }}
install_version: ${{ needs.build.outputs.install_version }}
secrets: inherit
notify:
needs: [build, wip]
if: >
github.repository == 'pyrevitlabs/pyRevit' &&
github.ref == 'refs/heads/develop' &&
(github.event_name == 'push' || github.event_name == 'workflow_dispatch')
runs-on: windows-2025
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
ref: ${{ github.sha }}
- name: Notify linked issues
continue-on-error: true
working-directory: build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Build__Channel: wip
Build__NotifyUrl: https://github.com/${{ github.repository }}/actions/runs/${{ needs.wip.outputs.workflow_run_id }}
run: dotnet run -c Release -- notify