Skip to content

Commit db42786

Browse files
authored
Add Code signing and initial release worflow (#4)
* move to workflow folder * uncomment signing cert * debug * more debug * debug 3 * rm debug * clean up code * rename ported functions to their actual name * more cleaning * rename for testing * debug rogue property * create 2 separate release assets for M365 and GWS * include the forgotten v * final clean up * remove invalid comment
1 parent c0fa55f commit db42786

File tree

4 files changed

+107
-87
lines changed

4 files changed

+107
-87
lines changed

.github/workflows/release.yaml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Purpose: Build, sign and draft release. This workflow is a port of ScubaGear's release workflow
2+
# This workflow's current main purpose is to sign specific PowerShell code for GearConnect
3+
# Then create release assets
4+
5+
name: Build, Sign, and Draft Release
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: "Release Version (e.g. semver, 1.2.4)"
12+
required: true
13+
type: string
14+
15+
permissions: read-all
16+
17+
jobs:
18+
build-and-draft:
19+
name: Build and Draft Release
20+
runs-on: windows-latest
21+
environment: Development
22+
permissions:
23+
id-token: write
24+
contents: write
25+
defaults:
26+
run:
27+
shell: powershell
28+
# This condition prevents duplicate runs.
29+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
with:
34+
path: repo
35+
- name: Install Azure Signing Tool
36+
run: |
37+
# Source the function
38+
. repo/utils/workflow/Install-AzureSignTool.ps1
39+
Install-AzureSignTool
40+
# OpenID Connect (OIDC) login to Azure Public Cloud with AzPowershell
41+
- name: Login to Azure
42+
uses: azure/login@v2
43+
with:
44+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
45+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
46+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
47+
enable-AzPSSession: true
48+
# Hardcoded to sign specifically named scripts in Build-SignRelease.ps1
49+
# We don't need to sign every script
50+
- name: Sign Scripts and Bundle Release Asset(s)
51+
run: |
52+
# Source the function.
53+
. repo/utils/workflow/Build-SignRelease.ps1
54+
New-ScubaReleaseAsset `
55+
-AzureKeyVaultUrl ${{ secrets.AZURE_KEY_VAULT_URL }} `
56+
-CertificateName ${{ secrets.AZURE_CERTIFICATE_NAME }} `
57+
-ReleaseVersion ${{ inputs.version }} `
58+
-RootFolderName "repo"
59+
# Creates release assets
60+
- name: Create Release
61+
uses: softprops/action-gh-release@v1
62+
id: create-release
63+
with:
64+
draft: true
65+
prerelease: false
66+
name: v${{ inputs.version }}
67+
tag_name: v${{ inputs.version }}
68+
files: |
69+
GearConnect-${{ inputs.version }}.zip
70+
generate_release_notes: true
71+
fail_on_unmatched_files: true

.github/workflows/sign.yaml

-74
This file was deleted.

utils/Build-SignRelease.ps1 utils/workflow/Build-SignRelease.ps1

+36-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
function Use-AzureSignTool {
22
<#
33
.SYNOPSIS
4-
AzureSignTool is a utility for signing code that is used to secure ScubaGear.
4+
AzureSignTool is a utility for signing code.
55
https://github.com/vcsjones/AzureSignTool
6-
Throws an error if there was an error signing the files.
6+
Throws an error, if there was an error signing the files.
77
#>
88
param (
99
[Parameter(Mandatory = $true)]
1010
[ValidateScript({ [uri]::IsWellFormedUriString($_, 'Absolute') -and ([uri] $_).Scheme -in 'https' })]
1111
[System.Uri]
1212
$AzureKeyVaultUrl,
13+
1314
[Parameter(Mandatory = $true)]
1415
[ValidateNotNullOrEmpty()]
1516
[string]
1617
$CertificateName,
18+
1719
[Parameter(Mandatory = $false)]
1820
[ValidateScript({ [uri]::IsWellFormedUriString($_, 'Absolute') -and ([uri] $_).Scheme -in 'http', 'https' })]
1921
$TimeStampServer = 'http://timestamp.digicert.com',
22+
2023
[Parameter(Mandatory = $true)]
2124
[ValidateScript({ Test-Path -Path $_ -PathType Leaf })]
2225
$FileList
@@ -44,7 +47,9 @@ function Use-AzureSignTool {
4447
Write-Error = $ErrorMessage
4548
throw $ErrorMessage
4649
}
50+
4751
$ToolPath = (Get-Command AzureSignTool).Path
52+
4853
Write-Warning "The path to AzureSignTool is $ToolPath"
4954
# & is the call operator that executes a command, script, or function.
5055
$Results = & $ToolPath $SignArguments
@@ -55,11 +60,11 @@ function Use-AzureSignTool {
5560
$SuccessPattern = 'Failed operations: 0'
5661
$FoundNoFailures = $Results | Select-String -Pattern $SuccessPattern -Quiet
5762
if ($FoundNoFailures -eq $true) {
58-
Write-Warning "Signed the filelist without errors."
63+
Write-Warning "Signed the file list without errors."
5964
}
6065
else {
61-
$ErrorMessage = "Failed to sign the filelist without errors."
62-
Write-Error = $ErrorMessage
66+
$ErrorMessage = "Failed to sign the file list without errors."
67+
Write-Error $ErrorMessage
6368
throw $ErrorMessage
6469
}
6570
}
@@ -81,10 +86,14 @@ function New-ArrayOfFilePaths {
8186
$ArrayOfFilePaths = @()
8287
$ArrayOfFilePaths = Get-ChildItem -Recurse -Path $ModuleDestinationPath -Include $FileExtensions
8388

84-
# Write-Warning "Verifying array of file paths..."
85-
# ForEach ($FilePath in $ArrayOfFilePaths) {
86-
# Write-Warning ">>> File path is $FilePath"
87-
# }
89+
#
90+
# Files to sign. Hardcoded as the number of files to sign is 1 to few.
91+
# Since we don't need to sign every PowerShell file.
92+
#
93+
$FilesToSign = @("Install-GearConnect.ps1")
94+
95+
# Filter files to the scripts we want to sign
96+
$ArrayOfFilePaths = $ArrayOfFilePaths | Where-Object { $FilesToSign -contains $_.name }
8897

8998
if ($ArrayOfFilePaths.Length -gt 0) {
9099
Write-Warning "Found $($ArrayOfFilePaths.Count) files to sign"
@@ -127,7 +136,7 @@ function New-FileList {
127136
return $FileListFileName
128137
}
129138

130-
function New-ModuleSignature {
139+
function New-ScubaReleaseAsset {
131140
<#
132141
.SYNOPSIS
133142
Sign the module.
@@ -148,12 +157,15 @@ function New-ModuleSignature {
148157
[Parameter(Mandatory = $true)]
149158
[string]
150159
$AzureKeyVaultUrl,
160+
151161
[Parameter(Mandatory = $true)]
152162
[string]
153163
$CertificateName,
164+
154165
[Parameter(Mandatory = $true)]
155166
[string]
156167
$ReleaseVersion,
168+
157169
[Parameter(Mandatory = $true)]
158170
[string]
159171
$RootFolderName
@@ -186,7 +198,18 @@ function New-ModuleSignature {
186198
-AzureKeyVaultUrl $AzureKeyVaultUrl `
187199
-CertificateName $CertificateName `
188200
-FileList $FileListFileName
189-
$ReleaseName = "ScubaConnect"
190-
Move-Item -Path $RootFolderName -Destination "$ReleaseName-$ReleaseVersion" -Force
191-
Compress-Archive -Path "$ReleaseName-$ReleaseVersion" -DestinationPath "$ReleaseName-$ReleaseVersion.zip"
201+
202+
# create the M365 GearConnect zip asset
203+
$GearConnectAsset = "GearConnect-$ReleaseVersion"
204+
Move-Item -Path "$RootFolderName/m365" -Destination $GearConnectAsset -Force
205+
Compress-Archive -Path $GearConnectAsset -DestinationPath "$GearConnectAsset.zip"
206+
207+
# Commented out block below until GogglesConnect is release ready
208+
# Remember to also add: GogglesConnect-${{ inputs.version }}.zip
209+
# under `files` in the release action
210+
211+
# create the GWS GogglesConnect zip asset
212+
# $GogglesConnectAsset = "GogglesConnect-$ReleaseVersion"
213+
# Move-Item -Path "$RootFolderName/gws" -Destination $GogglesConnectAsset -Force
214+
# Compress-Archive -Path $GogglesConnectAsset -DestinationPath "$GogglesConnectAsset.zip"
192215
}
File renamed without changes.

0 commit comments

Comments
 (0)