-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write unit tests for build and sign release #1521
Open
james-garriss
wants to merge
60
commits into
main
Choose a base branch
from
1453-write-unit-tests-for-build-sign-release
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+144
−35
Open
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
5ba46c8
move sign code into function
james-garriss 021a9d8
fix lint
james-garriss 43da682
fix path
james-garriss 9cd0bb1
fix path
james-garriss aa00717
fix path
james-garriss 31f5706
remove commented out code
james-garriss 1e35e16
run test release method
james-garriss 6bc8651
Add debugging
james-garriss db57541
Add temp pester test
james-garriss b21b053
test file
james-garriss ee43e3c
add more debug
james-garriss a9bfb11
debug path
james-garriss 348bf9f
use copy instead of move
james-garriss 6699668
remove debug
james-garriss 73ce101
Back to move
james-garriss 703f157
restore
james-garriss 6676866
create Pester test for installing AST
james-garriss 7250133
install before checking for install
james-garriss 426f4b2
verify commands
james-garriss 2f900fd
Spell toolpath with a L
james-garriss 55a2a38
Spell $true as $true
james-garriss 84ed7c8
remove debug
james-garriss 09e5c71
fix lint
james-garriss 23d0b07
test for dotnet
james-garriss 1c02f37
Replace env
james-garriss 9580ab2
test azure login
james-garriss 046f12d
Remove dead code, test copy folder again
james-garriss 0822608
Restore code for a test
james-garriss 41391b4
Restore login
james-garriss e42dddc
restore env
james-garriss a103a41
try copy item again
james-garriss 5e3bc2c
restore move
james-garriss abf8012
set to copy
james-garriss 41951fc
test for zip
james-garriss e5885f6
add debug
james-garriss f4ac865
Return to move
james-garriss 3bfe37a
improve tests
james-garriss ce7096d
fix path errors
james-garriss 158cd49
fix path
james-garriss 71842f1
add root folder name
james-garriss 29410e4
fix root folder name
james-garriss f4776bd
add bad input checks
james-garriss 69a7798
fix unused variable
james-garriss bba4576
change root folder name
james-garriss 46b0155
Test for root
james-garriss dd40f78
add resolve
james-garriss 220f6ad
fix root folder name
james-garriss 932bca3
Throw exception for missing dir
james-garriss 96cca59
added function doc
james-garriss a4cb084
remove the remove-item
james-garriss 7c2c843
set root to repo
james-garriss e786cbd
add remove-item back
james-garriss c99f5b7
clarify comments
james-garriss 28dfeb5
Cleanup
james-garriss c0ec264
add exception test
james-garriss 2568231
add scriptblock
james-garriss 430a3c1
Comments
james-garriss cfb9af2
remove outdated comments
james-garriss c5a09b5
Add comment
james-garriss a6ecb8d
Lint
james-garriss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# The purpose of this test to ensure that the function fails | ||
# gracefully if the root folder name does not exist. | ||
# Note: Functional testing (not unit testing) should be used | ||
# to verify that AST itself actually works. | ||
|
||
Describe "Bad Inputs Check" { | ||
It "The root folder name should exist" { | ||
$ScriptPath = Join-Path -Path $PSScriptRoot -ChildPath '../../utils/workflow/Build-SignRelease.ps1' -Resolve | ||
# Source the function | ||
. $ScriptPath | ||
# The function should throw an exception if the root folder name does not exist. | ||
{ New-ModuleSignature ` | ||
-AzureKeyVaultUrl "https://www.cisa.gov" ` | ||
-CertificateName "certificate name" ` | ||
-ReleaseVersion "0.0.1" ` | ||
-RootFolderName "nonexistantfoldername" } | Should -Throw | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# The purpose of this test is to verify that Azure Sign Tool is working. | ||
|
||
BeforeDiscovery { | ||
$ScriptPath = Join-Path -Path $PSScriptRoot -ChildPath '../../utils/workflow/Install-AzureSignTool.ps1' -Resolve | ||
# Source the function | ||
. $ScriptPath | ||
Install-AzureSignTool | ||
} | ||
|
||
Describe "AST Check" { | ||
It "Dotnet should be installed" { | ||
$ToolPath = (Get-Command dotnet).Path | ||
Write-Warning "The path to dotnet is $ToolPath" | ||
Test-Path -Path $ToolPath | Should -Be $true | ||
} | ||
It "AST should be installed" { | ||
$ToolPath = (Get-Command AzureSignTool).Path | ||
Write-Warning "The path to AzureSignTool is $ToolPath" | ||
Test-Path -Path $ToolPath | Should -Be $true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
function New-ModuleSignature { | ||
<# | ||
.SYNOPSIS | ||
Sign the ScubaGear module. | ||
.PARAMETER $AzureKeyVaultUrl | ||
The URL for the KeyVault in Azure. | ||
.PARAMETER $CertificateName | ||
The name of the certificate stored in the KeyVault. | ||
.PARAMETER $ReleaseVersion | ||
The version number of the release (e.g., 1.5.1). | ||
.PARAMETER $RootFolderName | ||
The name of the root folder. | ||
.EXCEPTIONS | ||
System.IO.DirectoryNotFoundException | ||
Thrown if $RootFolderName does not exist. | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[string] | ||
$AzureKeyVaultUrl, | ||
[Parameter(Mandatory = $true)] | ||
[string] | ||
$CertificateName, | ||
[Parameter(Mandatory = $true)] | ||
[string] | ||
$ReleaseVersion, | ||
[Parameter(Mandatory = $true)] | ||
[string] | ||
$RootFolderName | ||
) | ||
|
||
Write-Warning "Signing the module with AzureSignTool..." | ||
|
||
# Verify that $RootFolderName exists | ||
Write-Warning "The root folder name is $RootFolderName" | ||
if (Test-Path -Path $RootFolderName) { | ||
Write-Warning "Directory exists" | ||
} else { | ||
Write-Warning "Directory does not exist; throwing an exception..." | ||
throw [System.IO.DirectoryNotFoundException] "Directory not found: $RootFolderName" | ||
} | ||
|
||
# Source the deploy utilities so the functions in it can be called. | ||
$PublishPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\utils\workflow\Publish-ScubaGear.ps1' -Resolve | ||
. $PublishPath | ||
|
||
# Remove non-release files, like the .git dir, required for non-Windows machines | ||
Remove-Item -Recurse -Force $RootFolderName -Include .git* | ||
Write-Warning "Creating an array of the files to sign..." | ||
$ArrayOfFilePaths = New-ArrayOfFilePaths ` | ||
-ModuleDestinationPath $RootFolderName | ||
|
||
Write-Warning "Creating a file with a list of the files to sign..." | ||
$FileListFileName = New-FileList ` | ||
-ArrayOfFilePaths $ArrayOfFilePaths | ||
|
||
Write-Warning "Calling AzureSignTool function to sign scripts, manifest, and modules..." | ||
Use-AzureSignTool ` | ||
-AzureKeyVaultUrl $AzureKeyVaultUrl ` | ||
-CertificateName $CertificateName ` | ||
-FileList $FileListFileName | ||
Move-Item -Path $RootFolderName -Destination "ScubaGear-$ReleaseVersion" -Force | ||
Compress-Archive -Path "ScubaGear-$ReleaseVersion" -DestinationPath "ScubaGear-$ReleaseVersion.zip" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function Install-AzureSignTool { | ||
<# | ||
.SYNOPSIS | ||
Install Azure Signing Tool | ||
#> | ||
|
||
Write-Warning "Installing AST..." | ||
|
||
dotnet tool install --global AzureSignTool --version 5.0.0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A question.
Is this unit test ever meant to be run locally?
If yes, then would it beneficial to check if the AzureSignInTool is already installed before attempting to do another installation?
If no, disregard question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions that are in
/utils
are intended to be used and reused by any code. Functions that are in/utils/workflow
, however, are only intended to be used by workflows. As we would not expect AST to already be installed on the runner, there doesn't seem to be a need to add a Pester test for that. If we moved this function up into/utils
, then I think your idea would be smart.Can you think of any other (non-workflow) code that would want to use the
Install-AzureSignTool
function?