forked from ni/actor-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
385 lines (343 loc) · 15.4 KB
/
Copy pathbuild-vi-package.yml
File metadata and controls
385 lines (343 loc) · 15.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
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
name: Build VI Package
on:
push:
branches:
- main
- develop
- release-alpha/*
- release-beta/*
- release-rc/*
- hotfix/*
pull_request:
branches:
- main
- develop
- release-alpha/*
- release-beta/*
- release-rc/*
- hotfix/*
workflow_dispatch:
env:
DRAFT_RELEASE: true
USE_AUTO_NOTES: true
DISABLE_GPG_ON_FORKS: false
ATTACH_ARTIFACTS_TO_RELEASE: true
jobs:
build-release:
runs-on: [self-hosted, actorframework]
permissions:
contents: write
issues: read
pull-requests: read
steps:
########################################################################
# A) Possibly disable GPG signing on forks
########################################################################
- name: Possibly disable GPG signing on forks
if: ${{ env.DISABLE_GPG_ON_FORKS == 'true' }}
id: disable_signing
shell: pwsh
run: |
if ("${{ github.repository }}" -ne "ni/actor-framework") {
Write-Host "Detected a fork; disabling GPG signing..."
$currentCommitGpgsign = git config --global commit.gpgsign
if (-not $currentCommitGpgsign) { $currentCommitGpgsign = "" }
$currentTagGpgsign = git config --global tag.gpgsign
if (-not $currentTagGpgsign) { $currentTagGpgsign = "" }
"old_commit_gpgsign=$currentCommitGpgsign" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"old_tag_gpgsign=$currentTagGpgsign" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
git config --global commit.gpgsign false
git config --global tag.gpgsign false
}
else {
Write-Host "This is the official repo => no GPG changes."
"old_commit_gpgsign=" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"old_tag_gpgsign=" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
}
########################################################################
# 1) Check out code (full depth)
########################################################################
- name: Check out code
uses: actions/checkout@v3
with:
persist-credentials: true
fetch-depth: 0
########################################################################
# 2) Determine bump type from labels (major/minor/patch), else none
########################################################################
- name: Determine bump type
id: bump_type
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
if (context.event_name === 'pull_request') {
const labels = context.payload.pull_request.labels.map(l => l.name.toLowerCase());
core.info(`Found labels on PR: ${labels.join(', ')}`);
let bump = 'none';
if (labels.includes('major')) {
bump = 'major';
} else if (labels.includes('minor')) {
bump = 'minor';
} else if (labels.includes('patch')) {
bump = 'patch';
}
core.setOutput('bump_type', bump);
} else {
core.setOutput('bump_type', 'none');
}
########################################################################
# 3) Commit-based build number
########################################################################
- name: Determine build number
id: inc_build
shell: pwsh
run: |
git fetch --unshallow 2>$null || Write-Host "Already a full clone."
$commitCount = git rev-list --count HEAD
Write-Host "Commit-based build number => $commitCount"
"new_build_number=$commitCount" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
########################################################################
# 4) Parse latest version tag, apply major/minor/patch if found
########################################################################
- name: Compute version string
id: next_version
shell: pwsh
env:
BUMP_TYPE: ${{ steps.bump_type.outputs.bump_type }}
BUILD_NUMBER: ${{ steps.inc_build.outputs.new_build_number }}
run: |
Write-Host "Bump type: $($env:BUMP_TYPE)"
Write-Host "Build number: $($env:BUILD_NUMBER)"
$branchRef = $env:GITHUB_REF -replace '^refs/heads/', ''
Write-Host "Full branchRef: $branchRef"
# Find the last stable tag (fallback to 0.0.0 if none)
$latestTag = git describe --tags --abbrev=0 2>$null
if ([string]::IsNullOrEmpty($latestTag)) {
$baseMajor = 0
$baseMinor = 0
$basePatch = 0
}
else {
$tagNoPrefix = $latestTag.TrimStart('v')
$versionPart = $tagNoPrefix -replace '-build.*',''
$baseMajor, $baseMinor, $basePatch = $versionPart.Split('.')
}
$newMajor = [int]$baseMajor
$newMinor = [int]$baseMinor
$newPatch = [int]$basePatch
# Apply label-based semantic bump
switch ($env:BUMP_TYPE) {
'major' {
$newMajor++
$newMinor = 0
$newPatch = 0
}
'minor' {
$newMinor++
$newPatch = 0
}
'patch' {
$newPatch++
}
'none' { }
}
# If alpha/beta/rc => generate pre-release suffix
$preSuffix = ""
if ($branchRef -like 'release-alpha/*') {
$countAlpha = git rev-list --count HEAD
if ([string]::IsNullOrEmpty($countAlpha)) { $countAlpha = 1 }
$preSuffix = "alpha.$countAlpha"
}
elseif ($branchRef -like 'release-beta/*') {
$countBeta = git rev-list --count HEAD
if ([string]::IsNullOrEmpty($countBeta)) { $countBeta = 1 }
$preSuffix = "beta.$countBeta"
}
elseif ($branchRef -like 'release-rc/*') {
$countRc = git rev-list --count HEAD
if ([string]::IsNullOrEmpty($countRc)) { $countRc = 1 }
$preSuffix = "rc.$countRc"
}
if ([string]::IsNullOrEmpty($preSuffix)) {
$version = "v$($newMajor).$($newMinor).$($newPatch)-build$($env:BUILD_NUMBER)"
$isPrerelease = "false"
}
else {
$version = "v$($newMajor).$($newMinor).$($newPatch)-$preSuffix-build$($env:BUILD_NUMBER)"
$isPrerelease = "true"
}
Write-Host "Computed version => $version"
"VERSION=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"IS_PRERELEASE=$isPrerelease" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"MAJOR=$newMajor" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"MINOR=$newMinor" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"PATCH=$newPatch" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
########################################################################
# 5) Build the icon editor VI package
########################################################################
- name: Build the icon editor VI package
shell: pwsh
env:
MAJOR: ${{ steps.next_version.outputs.MAJOR }}
MINOR: ${{ steps.next_version.outputs.MINOR }}
PATCH: ${{ steps.next_version.outputs.PATCH }}
BUILD: ${{ steps.inc_build.outputs.new_build_number }}
COMMIT: ${{ github.sha }}
run: |
$repoRoot = $env:GITHUB_WORKSPACE
$scriptsFolder = Join-Path $repoRoot 'pipeline/scripts'
# Split the 'owner/repo' string to extract org and repository
$org, $repo = $env:GITHUB_REPOSITORY -split '/'
Write-Host "Building VI package => MAJOR=$($env:MAJOR), MINOR=$($env:MINOR), PATCH=$($env:PATCH), BUILD=$($env:BUILD)"
Write-Host "CompanyName => $org"
Write-Host "AuthorName => $repo"
# Call the updated Build.ps1 which now expects -CompanyName and -AuthorName
.\pipeline\scripts\Build.ps1 `
-BasePath $repoRoot `
-BasePathScripts $scriptsFolder `
-Major $env:MAJOR `
-Minor $env:MINOR `
-Patch $env:PATCH `
-Build $env:BUILD `
-Commit $env:COMMIT `
-CompanyName $org `
-AuthorName $repo
########################################################################
# 6) Capture the .vip file path as a step output
########################################################################
- name: Discover .vip path
id: find_vip
shell: pwsh
run: |
$vipFile = Get-ChildItem -Path "builds" -Filter "*.vip" -ErrorAction Stop | Select-Object -First 1
if (-not $vipFile) {
Write-Host "No .vip file found in builds!"
exit 1
}
Write-Host "Discovered VIP File: $($vipFile.FullName)"
"vip_path=$($vipFile.FullName)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
########################################################################
# 7) Upload ephemeral artifact (the .vip file)
########################################################################
- name: Upload ephemeral artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.next_version.outputs.VERSION }}
path: ${{ steps.find_vip.outputs.vip_path }}
########################################################################
# 8) Create & push tag (skip if it's a PR)
########################################################################
- name: Create & push tag
if: ${{ github.event_name != 'pull_request' }}
shell: pwsh
run: |
$VERSION = "${{ steps.next_version.outputs.VERSION }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a $VERSION -m "Auto-tag by CI for $VERSION"
git push origin $VERSION
########################################################################
# 9) Create GitHub Release (capture release_id)
########################################################################
- name: Create GitHub Release
if: ${{ success() && github.event_name != 'pull_request' }}
id: create_release
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const versionTag = '${{ steps.next_version.outputs.VERSION }}';
const draftRelease = (process.env.DRAFT_RELEASE || 'true').toLowerCase() === 'true';
const useAutoNotes = (process.env.USE_AUTO_NOTES || 'true').toLowerCase() === 'true';
const isPrerelease = (('${{ steps.next_version.outputs.IS_PRERELEASE }}' || '').toLowerCase() === 'true');
const createParams = {
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: versionTag,
name: versionTag,
draft: draftRelease,
prerelease: isPrerelease
};
if (useAutoNotes) {
createParams.generate_release_notes = true;
} else {
createParams.body = "Reference local release notes or embed within .vip.";
}
const response = await github.rest.repos.createRelease(createParams);
core.setOutput("upload_url", response.data.upload_url);
core.setOutput("release_id", response.data.id);
core.info(
`Created release [draft=${draftRelease}, prerelease=${isPrerelease}] => ${versionTag}`
);
########################################################################
# 10) Attach .vip file(s) to Release using github-script
########################################################################
- name: Attach .vip file(s) to Release
if: ${{ success() && env.ATTACH_ARTIFACTS_TO_RELEASE == 'true' && github.event_name != 'pull_request' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const path = require('path');
const releaseId = '${{ steps.create_release.outputs.release_id }}';
if (!releaseId) {
core.warning("No release_id found; skipping attach.");
return;
}
const vipDir = path.join(process.env.GITHUB_WORKSPACE, 'builds');
let vipFiles = [];
try {
vipFiles = fs.readdirSync(vipDir).filter(f => f.toLowerCase().endsWith('.vip'));
} catch (err) {
core.warning(`Could not read directory 'builds/VI Package': ${err.message}`);
return;
}
if (!vipFiles.length) {
core.warning("No .vip files found to attach.");
return;
}
core.info(`Discovered .vip files: ${vipFiles.join(', ')}`);
for (const vipFile of vipFiles) {
const fullPath = path.join(vipDir, vipFile);
const fileData = fs.readFileSync(fullPath);
core.info(`Uploading '${vipFile}' to release #${releaseId}...`);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: parseInt(releaseId, 10),
name: vipFile,
data: fileData,
headers: {
'content-type': 'application/octet-stream',
'content-length': fileData.length
}
});
core.info(`Successfully attached '${vipFile}'!`);
}
########################################################################
# B) Re-enable GPG signing if it was disabled
########################################################################
- name: Re-enable GPG signing (if disabled)
if: ${{ always() && env.DISABLE_GPG_ON_FORKS == 'true' }}
shell: pwsh
run: |
if ("${{ github.repository }}" -ne "ni/actor-framework") {
Write-Host "Restoring GPG signing..."
$oldCommitGpgsign = '${{ steps.disable_signing.outputs.old_commit_gpgsign }}'
$oldTagGpgsign = '${{ steps.disable_signing.outputs.old_tag_gpgsign }}'
if ($oldCommitGpgsign) {
git config --global commit.gpgsign $oldCommitGpgsign
} else {
git config --global --unset commit.gpgsign || Write-Host "commit.gpgsign wasn't originally set."
}
if ($oldTagGpgsign) {
git config --global tag.gpgsign $oldTagGpgsign
} else {
git config --global --unset tag.gpgsign || Write-Host "tag.gpgsign wasn't originally set."
}
}
else {
Write-Host "Official repo or DISABLE_GPG_ON_FORKS==false => no restore needed."
}