Skip to content

Commit 48e0d18

Browse files
committed
Add PowerShell module build and caching to workflows
Enhanced both publish_release and upload_dev GitHub Actions workflows to build PowerShell modules (CIPPCore and CippExtensions) using ModuleBuilder, with caching for dependencies to speed up builds. Also updated actions/checkout to v4 in upload_dev.yml and improved module build steps for consistency.
1 parent 4a74df8 commit 48e0d18

File tree

2 files changed

+126
-2
lines changed

2 files changed

+126
-2
lines changed

.github/workflows/publish_release.yml

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,68 @@ jobs:
6868
env:
6969
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7070

71+
- name: Setup PowerShell module cache
72+
id: cacher
73+
uses: actions/cache@v3
74+
with:
75+
path: "~/.local/share/powershell/Modules"
76+
key: ${{ runner.os }}-ModuleBuilder
77+
78+
- name: Install ModuleBuilder
79+
if: steps.cacher.outputs.cache-hit != 'true'
80+
shell: pwsh
81+
run: |
82+
Set-PSRepository PSGallery -InstallationPolicy Trusted
83+
Install-Module ModuleBuilder -AllowClobber -Force
84+
85+
- name: Build CIPPCore Module
86+
shell: pwsh
87+
run: |
88+
$ModulePath = Join-Path $env:GITHUB_WORKSPACE "Modules/CIPPCore"
89+
$OutputPath = Join-Path $env:GITHUB_WORKSPACE "Output"
90+
91+
Write-Host "Building module from: $ModulePath"
92+
Write-Host "Output directory: $OutputPath"
93+
94+
# Generate function permissions before replacing the source module
95+
$ToolsPath = Join-Path $env:GITHUB_WORKSPACE "Tools"
96+
$ScriptPath = Join-Path $ToolsPath "Build-FunctionPermissions.ps1"
97+
pwsh -File $ScriptPath -ModulePath $ModulePath
98+
99+
# Build the module using ModuleBuilder
100+
Build-Module -SourcePath $ModulePath -OutputDirectory $OutputPath -Verbose
101+
102+
# Replace the source module with the built module
103+
Remove-Item -Path $ModulePath -Recurse -Force
104+
Copy-Item -Path (Join-Path $OutputPath "CIPPCore") -Destination $ModulePath -Recurse -Force
105+
106+
Write-Host "Module built and replaced successfully"
107+
108+
# Clean up output directory
109+
Remove-Item -Path $OutputPath -Recurse -Force
110+
111+
- name: Build CippExtensions Module
112+
shell: pwsh
113+
run: |
114+
$ModulePath = Join-Path $env:GITHUB_WORKSPACE "Modules/CippExtensions"
115+
$OutputPath = Join-Path $env:GITHUB_WORKSPACE "Output"
116+
117+
Write-Host "Building module from: $ModulePath"
118+
Write-Host "Output directory: $OutputPath"
119+
120+
# Build the module using ModuleBuilder
121+
Build-Module -SourcePath $ModulePath -OutputDirectory $OutputPath -Verbose
122+
123+
# Replace the source module with the built module
124+
Remove-Item -Path $ModulePath -Recurse -Force
125+
Copy-Item -Path (Join-Path $OutputPath "CippExtensions") -Destination $ModulePath -Recurse -Force
126+
127+
Write-Host "Module built and replaced successfully"
128+
129+
# Clean up output directory
130+
Remove-Item -Path $OutputPath -Recurse -Force
131+
132+
71133
# Create ZIP File in a New Source Directory
72134
- name: Prepare and Zip Release Files
73135
if: env.tag_exists == 'false'
@@ -91,4 +153,4 @@ jobs:
91153
container_name: cipp-api
92154
source_folder: src/releases/
93155
destination_folder: /
94-
delete_if_exists: true
156+
delete_if_exists: true

.github/workflows/upload_dev.yml

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,69 @@ jobs:
1414
steps:
1515
# Checkout the repository
1616
- name: Checkout Code
17-
uses: actions/checkout@v3
17+
uses: actions/checkout@v4
18+
with:
19+
persist-credentials: false
20+
- name: Setup PowerShell module cache
21+
id: cacher
22+
uses: actions/cache@v3
23+
with:
24+
path: "~/.local/share/powershell/Modules"
25+
key: ${{ runner.os }}-ModuleBuilder
26+
27+
- name: Install ModuleBuilder
28+
if: steps.cacher.outputs.cache-hit != 'true'
29+
shell: pwsh
30+
run: |
31+
Set-PSRepository PSGallery -InstallationPolicy Trusted
32+
Install-Module ModuleBuilder -AllowClobber -Force
33+
34+
- name: Build CIPPCore Module
35+
shell: pwsh
36+
run: |
37+
$ModulePath = Join-Path $env:GITHUB_WORKSPACE "Modules/CIPPCore"
38+
$OutputPath = Join-Path $env:GITHUB_WORKSPACE "Output"
39+
40+
Write-Host "Building module from: $ModulePath"
41+
Write-Host "Output directory: $OutputPath"
42+
43+
# Generate function permissions before replacing the source module
44+
$ToolsPath = Join-Path $env:GITHUB_WORKSPACE "Tools"
45+
$ScriptPath = Join-Path $ToolsPath "Build-FunctionPermissions.ps1"
46+
pwsh -File $ScriptPath -ModulePath $ModulePath
47+
48+
# Build the module using ModuleBuilder
49+
Build-Module -SourcePath $ModulePath -OutputDirectory $OutputPath -Verbose
50+
51+
# Replace the source module with the built module
52+
Remove-Item -Path $ModulePath -Recurse -Force
53+
Copy-Item -Path (Join-Path $OutputPath "CIPPCore") -Destination $ModulePath -Recurse -Force
54+
55+
Write-Host "Module built and replaced successfully"
56+
57+
# Clean up output directory
58+
Remove-Item -Path $OutputPath -Recurse -Force
59+
60+
- name: Build CippExtensions Module
61+
shell: pwsh
62+
run: |
63+
$ModulePath = Join-Path $env:GITHUB_WORKSPACE "Modules/CippExtensions"
64+
$OutputPath = Join-Path $env:GITHUB_WORKSPACE "Output"
65+
66+
Write-Host "Building module from: $ModulePath"
67+
Write-Host "Output directory: $OutputPath"
68+
69+
# Build the module using ModuleBuilder
70+
Build-Module -SourcePath $ModulePath -OutputDirectory $OutputPath -Verbose
71+
72+
# Replace the source module with the built module
73+
Remove-Item -Path $ModulePath -Recurse -Force
74+
Copy-Item -Path (Join-Path $OutputPath "CippExtensions") -Destination $ModulePath -Recurse -Force
75+
76+
Write-Host "Module built and replaced successfully"
77+
78+
# Clean up output directory
79+
Remove-Item -Path $OutputPath -Recurse -Force
1880
1981
# Create ZIP File in a New Source Directory
2082
- name: Prepare and Zip Release Files

0 commit comments

Comments
 (0)