-
-
Notifications
You must be signed in to change notification settings - Fork 10
166 lines (143 loc) · 5.01 KB
/
ci.yml
File metadata and controls
166 lines (143 loc) · 5.01 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
name: CI/CD Pipeline
on:
push:
branches: ['**']
tags:
- 'v*.*.*'
paths-ignore:
- '**.md'
- 'docs/**'
- '.github/ISSUE_TEMPLATE/**'
- '.github/PULL_REQUEST_TEMPLATE/**'
pull_request:
branches: ['**']
paths-ignore:
- '**.md'
- 'docs/**'
- '.github/ISSUE_TEMPLATE/**'
- '.github/PULL_REQUEST_TEMPLATE/**'
workflow_dispatch:
permissions:
contents: write
actions: read
checks: read
jobs:
build:
name: Build and Test
runs-on: ${{ matrix.os }}
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout Repository
uses: actions/checkout@v4.2.2
- name: Bootstrap Build Environment
shell: pwsh
run: ./build.ps1
- name: Run PSScriptAnalyzer
shell: pwsh
run: ./build.ps1 -Task Analyze
- name: Run Pester Tests
shell: pwsh
run: ./build.ps1 -Task Test
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4.6.2
with:
name: test-results-${{ matrix.os }}
path: build/TestResults/TestResults.xml
if-no-files-found: warn
- name: Build Module
shell: pwsh
run: ./build.ps1 -Task Build
- name: Upload Build Artifacts
if: success() && matrix.os == 'windows-latest'
uses: actions/upload-artifact@v4.6.2
with:
name: module-build
path: build/IntuneHydrationKit/
if-no-files-found: error
release:
name: Publish and Release
needs: build
runs-on: windows-latest
if: startsWith(github.ref, 'refs/tags/v')
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
steps:
- name: Checkout Repository
uses: actions/checkout@v4.2.2
- name: Download Build Artifacts
uses: actions/download-artifact@v4.3.0
with:
name: module-build
path: build/IntuneHydrationKit/
- name: List Build Artifacts
shell: pwsh
run: |
Write-Host "=== Build Artifacts ===" -ForegroundColor Cyan
if (Test-Path build/IntuneHydrationKit) {
Get-ChildItem -Path build/IntuneHydrationKit -Recurse | ForEach-Object {
Write-Host $_.FullName
}
} else {
Write-Error "Build artifacts directory not found!"
exit 1
}
- name: Get Module Info
id: module_info
shell: pwsh
run: |
$manifest = Import-PowerShellDataFile -Path ./IntuneHydrationKit.psd1
"version=$($manifest.ModuleVersion)" >> $env:GITHUB_OUTPUT
# Use heredoc-style multiline output for proper newline handling
"release_notes<<EOF" >> $env:GITHUB_OUTPUT
$manifest.PrivateData.PSData.ReleaseNotes >> $env:GITHUB_OUTPUT
"EOF" >> $env:GITHUB_OUTPUT
- name: Validate Tag Matches Module Version
shell: pwsh
run: |
$manifest = Import-PowerShellDataFile -Path ./IntuneHydrationKit.psd1
$moduleVersion = $manifest.ModuleVersion
$tagVersion = '${{ github.ref_name }}' -replace '^v', ''
if ($moduleVersion -ne $tagVersion) {
throw "Tag version ($tagVersion) does not match module version ($moduleVersion). Please update the module manifest."
}
Write-Host "Version validated: $moduleVersion"
- name: Publish to PowerShell Gallery
shell: pwsh
env:
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
run: |
if (-not $env:PSGALLERY_API_KEY) {
throw "PSGALLERY_API_KEY secret is not set"
}
Publish-Module -Path ./build/IntuneHydrationKit -NuGetApiKey $env:PSGALLERY_API_KEY -Repository PSGallery -Force
- name: Create Release Archive
shell: pwsh
run: |
$version = '${{ steps.module_info.outputs.version }}'
$zipName = "IntuneHydrationKit-v$version.zip"
Compress-Archive -Path ./build/IntuneHydrationKit/* -DestinationPath "./build/$zipName" -Force
Write-Host "Created release archive: $zipName"
Get-ChildItem ./build/*.zip | ForEach-Object { Write-Host " $($_.Name) - $([math]::Round($_.Length/1KB, 2)) KB" }
- name: Create GitHub Release
uses: softprops/action-gh-release@da05d552573ad5aba039eaac05058a918a7bf631
with:
name: v${{ steps.module_info.outputs.version }}
body: |
## IntuneHydrationKit v${{ steps.module_info.outputs.version }}
### Installation
```powershell
Install-Module -Name IntuneHydrationKit -Scope CurrentUser
```
### Release Notes
${{ steps.module_info.outputs.release_notes }}
draft: false
prerelease: false
files: build/IntuneHydrationKit-v${{ steps.module_info.outputs.version }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}