forked from PSAppDeployToolkit/PSAppDeployToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
195 lines (171 loc) · 8.28 KB
/
module-build.yml
File metadata and controls
195 lines (171 loc) · 8.28 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
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/software-installed-on-github-hosted-runners
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#using-a-specific-shell
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-powershell
# https://github.com/actions/upload-artifact#where-does-the-upload-go
name: PSAppDeployToolkit-Windows-PowerShell
on:
pull_request:
push:
permissions:
id-token: write # Require write permission to Fetch an OIDC token.
contents: read
env:
NUGET_PACKAGES: ${{ github.workspace }}\.nuget\packages
jobs:
test:
name: Run Tests
runs-on: windows-latest
strategy:
fail-fast: false
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Display the path
shell: powershell
run: echo ${env:PATH}
- name: Version Display
shell: powershell
run: $PSVersionTable
# actions/setup-dotnet caching is unwieldy with multiple projects
# https://github.com/NuGet/Home/issues/12409
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ${{ env.NUGET_PACKAGES }}
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Cache PowerShell modules
uses: potatoqualitee/psmodulecache@v6.2.1
with:
modules-to-cache: Pester:5.7.1, InvokeBuild:5.14.20, PSScriptAnalyzer:1.24.0, platyPS:0.14.2, Alt3.Docusaurus.Powershell:1.0.37
shell: powershell
- name: NuGet Latest
shell: powershell
run: Install-PackageProvider -Name NuGet -Confirm:$false -Force -Verbose
- name: PowerShellGet Latest
shell: powershell
run: Install-Module -Name PowerShellGet -Repository PSGallery -Force
- name: Test and Build
shell: powershell
run: Invoke-Build -File .\src\PSAppDeployToolkit.build.ps1
- name: Install AzureSignTool
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/4.0.x' || github.ref == 'refs/heads/4.1.x'
run: dotnet tool install --global azuresigntool
- name: Azure Login
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/4.0.x' || github.ref == 'refs/heads/4.1.x'
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Sign module source
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/4.0.x' || github.ref == 'refs/heads/4.1.x'
shell: powershell
run: |
Get-ChildItem -Path "$($PWD)\src\Artifacts\Module\PSAppDeployToolkit" -Include '*.ps*1', 'PSAppDeployToolkit.dll', 'PSADT*.dll', 'PSADT*.exe', 'iNKORE.UI.WPF*.dll', 'Deploy-Application.exe', 'Invoke-AppDeployToolkit.exe' -Recurse | Select-Object -ExpandProperty FullName | Out-File "FilesToSign.txt"
& azuresigntool.exe sign -s -kvu https://psadt-kv-prod-codesign.vault.azure.net -kvc PSADT -kvm -tr http://timestamp.digicert.com -td sha256 -ifl FilesToSign.txt
- name: Generate artifact templates
shell: powershell
run: |
$ArtifactsPath = "$($PWD)\src\Artifacts"
$BuildModuleRoot = "$ArtifactsPath\Module\PSAppDeployToolkit"
$spParams = @{
FilePath = [System.Diagnostics.Process]::GetCurrentProcess().Path
ArgumentList = "-ExecutionPolicy Bypass -NonInteractive -NoProfile -NoLogo -Command `$ErrorActionPreference = 'Stop'; Import-Module -Name '$BuildModuleRoot'; $([System.String]::Join('; ', (3, 4).ForEach({"New-ADTTemplate -Destination '$ArtifactsPath' -Name 'Template_v$_' -Version $_"})))"
NoNewWindow = $true
Wait = $true
}
if ((Start-Process @spParams -PassThru).ExitCode -ne 0)
{
throw "Failed to generate frontend templates."
}
- name: Make artifact name suffix
id: ts
shell: powershell
run: |
"suffix=$(if ($env:GITHUB_REF_NAME -match 'merge$') {$env:GITHUB_REF_NAME.Split('/')[-2]} else {$env:GITHUB_REF_NAME.Split('/')[-1]})_$($env:GITHUB_SHA.Substring(0, 7))_$([System.DateTime]::Now.ToUniversalTime().ToString('O').Replace(':', $null) -replace '\.\d+')" >> $env:GITHUB_OUTPUT
- name: Upload module
uses: actions/upload-artifact@v6
with:
name: PSAppDeployToolkit_ModuleOnly__${{ steps.ts.outputs.suffix }}
path: .\src\Artifacts\Module
if-no-files-found: error
compression-level: 9
overwrite: true
- name: Upload v3 module template
uses: actions/upload-artifact@v6
with:
name: PSAppDeployToolkit_Template_v3_${{ steps.ts.outputs.suffix }}
path: .\src\Artifacts\Template_v3
if-no-files-found: error
compression-level: 9
overwrite: true
- name: Upload v4 module template
uses: actions/upload-artifact@v6
with:
name: PSAppDeployToolkit_Template_v4_${{ steps.ts.outputs.suffix }}
path: .\src\Artifacts\Template_v4
if-no-files-found: error
compression-level: 9
overwrite: true
- name: Update Website Docs
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/4.0.x' || github.ref == 'refs/heads/4.1.x'
shell: powershell
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
run: |
# Perform initial setup.
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop
Set-StrictMode -Version 3
# Clone the destination repo.
$dstBnch = 'main'
$dstRepo = "https://$env:API_TOKEN_GITHUB@github.com/$env:GITHUB_REPOSITORY_OWNER/website.git"
$dstBase = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())
$dstPath = ("$dstBase\docs\reference\functions", "$dstBase\versioned_docs\version-4.0.0\reference\functions")[$env:GITHUB_REF_NAME -match '4\.0\.x']
Write-Host -Object "Cloning destination repository, please wait..."
git clone -b $dstBnch $dstRepo $dstBase
if ($Global:LASTEXITCODE)
{
throw "The cloning of the destination repository failed."
}
# Update the docs from the source repo to the destination.
Write-Host -Object "Updating the markdown files in destination repository."
Remove-Item -Path "$dstPath\*" -Force -Confirm:$false
Get-ChildItem -Path ".\src\Artifacts\Docusaurus\commands\*" -File | Copy-Item -Destination $dstPath
# Change into the repository's directory.
Push-Location -LiteralPath $dstBase
# Add any changes that may exist.
git add --all
# Commit any changes if found.
if (git diff --cached)
{
# Set up author details.
git config user.email "$env:USERNAME@psappdeploytoolkit.com"
git config user.name "PSAppDeployToolkit Action Workflow"
# Do the commit.
$commitMsg = "Commit of document changes from https://github.com/$env:GITHUB_REPOSITORY/commit/$env:GITHUB_SHA"
Write-Host -Object "Documents changed, committing as `"$commitMsg`""
git commit -a -m $commitMsg
if ($Global:LASTEXITCODE)
{
throw "The committing of destination repo changes failed."
}
# Push it to the website.
Write-Host -Object "Pushing committed changes to origin."
git push origin
if ($Global:LASTEXITCODE)
{
throw "The pushing of commits from destination repo failed."
}
Write-Host -Object "Successfully completed operation."
}
else
{
Write-Host -Object "Found no document changes to commit."
}
# Pop back to the original $PWD.
Pop-Location