-
-
Notifications
You must be signed in to change notification settings - Fork 52
183 lines (161 loc) · 6.48 KB
/
Copy pathrelease.yml
File metadata and controls
183 lines (161 loc) · 6.48 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
name: Build and Publish Module
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
on:
push:
tags:
- 'v*'
workflow_dispatch:
permissions:
contents: write
jobs:
build:
name: Build Module
runs-on: windows-latest
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Validate tag source
if: github.event_name != 'workflow_dispatch'
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$tagName = $env:GITHUB_REF_NAME
$tagCommit = $env:GITHUB_SHA
if ($tagName -match '-(alpha|beta|rc)') {
Write-Host "Pre-release tag detected: $tagName"
$developCommit = (git rev-parse origin/develop)
$mergeBase = (git merge-base $tagCommit $developCommit)
if ($mergeBase -ne $tagCommit) {
throw 'Pre-release tag commit is not reachable from develop.'
}
Write-Host 'Tag commit is reachable from develop.'
} else {
Write-Host "Stable tag detected: $tagName"
$mainCommit = (git rev-parse origin/main)
$mergeBase = (git merge-base $tagCommit $mainCommit)
if ($mergeBase -ne $tagCommit) {
throw 'Stable tag commit is not reachable from main.'
}
Write-Host 'Tag commit is reachable from main.'
}
- name: Bootstrap environment
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
& "$env:GITHUB_WORKSPACE\DevOps\Build\bootstrap.ps1"
- name: Build module
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
& "$env:GITHUB_WORKSPACE\DevOps\Build\build.ps1" -TaskNames 'clean', 'build'
- name: Generate documentation
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
& "$env:GITHUB_WORKSPACE\DevOps\Build\build.ps1" -TaskNames 'updateHelp', 'publishDocs'
- name: Verify build outputs
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$moduleOutputPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'Output'
$docsOutputPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath '.build\docs'
if (-not (Test-Path -Path $moduleOutputPath -PathType Container)) {
throw "Expected module output path was not found: $moduleOutputPath"
}
if (-not (Test-Path -Path $docsOutputPath -PathType Container)) {
throw "Expected documentation output path was not found: $docsOutputPath"
}
Write-Host "Module output path: $moduleOutputPath" -ForegroundColor Cyan
Get-ChildItem -Path $moduleOutputPath -Recurse | Select-Object -First 20 FullName
Write-Host "Documentation output path: $docsOutputPath" -ForegroundColor Cyan
Get-ChildItem -Path $docsOutputPath -Recurse | Select-Object -First 20 FullName
- name: Upload build artifacts
uses: actions/upload-artifact@v6
with:
name: module-build
path: ${{ github.workspace }}/Output/**
if-no-files-found: error
retention-days: 30
- name: Upload documentation
uses: actions/upload-artifact@v6
with:
name: module-docs
path: ${{ github.workspace }}/.build/docs/**
if-no-files-found: error
retention-days: 30
publish:
name: Publish Module
runs-on: windows-latest
needs: build
if: startsWith(github.ref, 'refs/tags/v')
environment:
name: production
url: https://www.powershellgallery.com/packages/HaloAPI
env:
TF_BUILD: true
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Bootstrap environment
shell: pwsh
working-directory: ${{ github.workspace }}
run: |
$ErrorActionPreference = 'Stop'
& "$env:GITHUB_WORKSPACE\DevOps\Build\bootstrap.ps1"
- name: Download build artifacts
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$ErrorActionPreference = 'Stop'
gh run download ${{ github.run_id }} --name module-build --dir Output
- name: Package module for release
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$tagName = "$env:GITHUB_REF_NAME"
$zipName = "HaloAPI-$tagName.zip"
$zipPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $zipName
if (Test-Path -Path $zipPath) {
Remove-Item -Path $zipPath -Force
}
Compress-Archive -Path (Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'Output\*') -DestinationPath $zipPath
- name: Validate PowerShell Gallery secret
shell: pwsh
env:
PSGalleryAPIKey: ${{ secrets.PSGALLERY_API_KEY }}
run: |
$ErrorActionPreference = 'Stop'
if ([string]::IsNullOrWhiteSpace($env:PSGalleryAPIKey)) {
throw 'The PSGALLERY_API_KEY secret is required to publish releases.'
}
- name: Publish to PowerShell Gallery
shell: pwsh
env:
PSGalleryAPIKey: ${{ secrets.PSGALLERY_API_KEY }}
run: |
$ErrorActionPreference = 'Stop'
$moduleManifest = Get-ChildItem -Path "$env:GITHUB_WORKSPACE\Output" -Recurse -Filter 'HaloAPI.psd1' | Select-Object -First 1
if (-not $moduleManifest) {
throw 'Module manifest not found under Output/. Ensure build artifacts are present.'
}
$manifest = Test-ModuleManifest -Path $moduleManifest.FullName
$version = $manifest.Version.ToString()
if ($manifest.PrivateData.PSData.Prerelease) {
$version = "$version-$($manifest.PrivateData.PSData.Prerelease)"
}
Write-Host "Checking if HaloAPI version $version already exists on PSGallery..."
try {
$existingModule = Find-Module -Name 'HaloAPI' -RequiredVersion $version -AllowPrerelease -ErrorAction SilentlyContinue
if ($existingModule) {
Write-Host "::warning::Module version $version already exists on PSGallery. Skipping publish."
exit 0
}
} catch {
Write-Host "Module version $version not found on PSGallery. Proceeding with publish."
}
& "$env:GITHUB_WORKSPACE\DevOps\Build\build.ps1" -TaskNames 'publish'