another output #257
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
# Purpose: Publishes ScubaGear to a private repo and caches ScubaGear modules and OPA for reuse. | |
name: Publish Private Package | |
# This is a reusable workflow called by the pipeline. | |
on: | |
workflow_call: | |
secrets: | |
ClientId: | |
required: true | |
TenantId: | |
required: true | |
SubscriptionId: | |
required: true | |
KeyVaultInfo: | |
required: true | |
workflow_dispatch: | |
push: | |
paths: | |
- ".github/workflows/publish_private_package.yaml" | |
permissions: | |
id-token: write | |
contents: write | |
env: | |
GalleryName: PrivateScubaGearGallery | |
jobs: | |
publish: | |
name: Private Repo | |
runs-on: windows-latest | |
environment: Development | |
permissions: | |
id-token: write | |
contents: write | |
defaults: | |
run: | |
shell: powershell | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
path: repo | |
- name: Install Azure Signing Tool | |
run: | | |
dotnet --version | |
dotnet tool install --global AzureSignTool --version 5.0.0 | |
# OIDC Login to Azure Public Cloud with AzPowershell (enableAzPSSession true) | |
- name: Login to Azure | |
uses: azure/login@v2 | |
with: | |
# client-id: ${{ secrets.ClientId }} | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
# tenant-id: ${{ secrets.TenantId }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
# subscription-id: ${{ secrets.SubscriptionId }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
enable-AzPSSession: true | |
- name: Get Key Vault Info | |
id: key-vault-info | |
# Stop the workflow if logging into Azure failed. | |
if: ${{ success() }} | |
# TODO: Remove this env, just use secret | |
env: | |
# KEY_VAULT_INFO: ${{ secrets.KeyVaultInfo }} | |
KEY_VAULT_INFO: ${{ secrets.SCUBA_KEY_VAULT_PROD}} | |
run: | | |
$KeyVaultInfo = ${env:KEY_VAULT_INFO} | ConvertFrom-Json | |
echo "KeyVaultUrl=$($KeyVaultInfo.KeyVault.URL)" >> $env:GITHUB_OUTPUT | |
echo "KeyVaultCertificateName=$($KeyVaultInfo.KeyVault.CertificateName)" >> $env:GITHUB_OUTPUT | |
- name: Create Private Gallery | |
run: | | |
# Source the deploy utilities so the functions in it can be called. | |
. repo/utils/workflow/Publish-ScubaGear.ps1 | |
cd repo | |
New-PrivateGallery -GalleryName $env:GalleryName -Trusted | |
- name: Sign and Publish Module | |
run: | | |
# Source the deploy utilities so the functions in it can be called. | |
. repo/utils/workflow/Publish-ScubaGear.ps1 | |
# Remove non-release files | |
Remove-Item -Recurse -Force repo -Include .git* | |
# Setup the parameters | |
$Parameters = @{ | |
AzureKeyVaultUrl = '${{ steps.key-vault-info.outputs.KeyVaultUrl }}' | |
CertificateName = '${{ steps.key-vault-info.outputs.KeyVaultCertificateName }}' | |
ModuleSourcePath = 'repo/PowerShell/ScubaGear' | |
GalleryName = $env:GalleryName | |
} | |
# This publishes to a private gallery, from which we will pull in a future step. | |
# This step helps us verify that ScubaGear is in a state where it can be | |
# published to PSGallery. | |
Publish-ScubaGearModule @Parameters | |
- name: Test Module Publish | |
run: | | |
Get-Location | |
$TestContainers = @() | |
$TestContainers += New-PesterContainer -Path "repo/Testing/Functional/BuildTest" -Data @{ } | |
$PesterConfig = @{ | |
Run = @{ | |
Container = $TestContainers | |
} | |
Output = @{ | |
Verbosity = 'Detailed' | |
} | |
} | |
$Config = New-PesterConfiguration -Hashtable $PesterConfig | |
Invoke-Pester -Configuration $Config | |
- name: Initialize ScubaGear | |
run: | | |
$ExpectedName = 'ScubaGear' | |
$ExpectedDescription = 'The Secure Cloud Business Applications (SCuBA) Gear module automates conformance testing about CISA M365 Secure Configuration Baselines.' | |
$Info = Install-Module -Name ScubaGear -Repository $env:GalleryName -SkipPublisherCheck -PassThru | |
Write-Output "The name of the module is $($Info.Name)" | |
if ($Info.Name -ne $ExpectedName) { | |
Write-Output "::error::The name of the published module should be $ExpectedName" | |
} | |
Write-Output "The description of the module is $($Info.Description)" | |
$NewLine = [environment]::NewLine | |
$DescriptionFixed = $Info.Description -replace $NewLine, '\n' | |
Write-Output "The description of the module is $($DescriptionFixed)" | |
if ($DescriptionFixed -ne $ExpectedDescription) { | |
Write-Output "::error::The name of the published module should be $ExpectedDescription" | |
} | |
# Source the function | |
. repo/utils/workflow/Initialize-ScubaGearForTesting.ps1 | |
Initialize-ScubaGearForTesting | |
# This is a manual test that simply writes the version to the console. | |
Invoke-SCuBA -Version | |
Test-Path -Path "C:\Program Files\WindowsPowerShell\Modules\ScubaGear" | |
- name: Install Selenium | |
run: | | |
# Source the function | |
. repo/utils/workflow/Install-SeleniumForTesting.ps1 | |
Install-SeleniumForTesting | |
# Instead of initializing ScubaGear repeated for each of the test jobs below, | |
# we cache the PowerShell modules and OPA here and then restore them for the jobs. | |
# It's about a 20% performance improvement. | |
- name: Cache ScubaGear | |
id: scubagear-directory | |
uses: actions/cache/save@v4 | |
with: | |
path: C:\Program Files\WindowsPowerShell\Modules\ScubaGear | |
key: "scubagear-directory-${{ github.run_id }}" | |
- name: Cache Dependencies | |
id: powershell-directory | |
uses: actions/cache/save@v4 | |
with: | |
path: C:\Users\runneradmin\Documents\WindowsPowerShell\Modules | |
key: "powershell-directory-${{ github.run_id }}" | |
- name: Cache OPA | |
id: opa-directory | |
uses: actions/cache/save@v4 | |
with: | |
path: C:\Users\runneradmin\.scubagear\Tools | |
key: "opa-directory-${{ github.run_id }}" |