Release #53
Workflow file for this run
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
name: Release | |
on: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
id-token: write | |
concurrency: Release | |
defaults: | |
run: | |
shell: PowerShell | |
jobs: | |
Deploy: | |
if: github.repository == 'Microsoft/NavContainerHelper' | |
runs-on: [ windows-latest ] | |
steps: | |
- name: 'Az CLI login' | |
uses: azure/login@v2 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
enable-AzPSSession: true | |
- name: Install Azure Powershell Modules | |
run: | | |
if(-not (Get-Module 'Az.Storage' -ListAvailable)) { | |
Install-Module -Name 'Az.Storage' -Force -AllowClobber | |
} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Deploy | |
run: | | |
$errorActionPreference = "stop" | |
try { | |
$path = Join-Path ([System.IO.Path]::GetTempPath()) "BcContainerHelper" | |
New-Item -path $path -itemType Directory | Out-Null | |
Copy-Item -path (Join-Path $ENV:GITHUB_WORKSPACE "*") -Destination $path -Recurse -Force | |
Remove-Item -Path (Join-Path $path "Tests") -Force -Recurse | |
Remove-Item -Path (Join-Path $path ".github") -Force -Recurse | |
Remove-Item -Path (Join-Path $path ".git") -Force -Recurse | |
Remove-Item -Path (Join-Path $path ".gitignore") -Force | |
Remove-Item -Path (Join-Path $path "README.md") -Force | |
$versionFile = Join-Path $path 'Version.txt' | |
$version = (Get-Content -Path $versionFile).split('-')[0] | |
Write-Host "BcContainerHelper version $Version" | |
Set-Content -Path $versionFile -Value $version | |
$modulePath = Join-Path $ENV:GITHUB_WORKSPACE "BcContainerHelper.psm1" | |
Import-Module $modulePath -DisableNameChecking | |
$functionsToExport = (get-module -Name BcContainerHelper).ExportedFunctions.Keys | Sort-Object | |
$aliasesToExport = (get-module -Name BcContainerHelper).ExportedAliases.Keys | Sort-Object | |
$releaseNotes = Get-Content -Path (Join-Path $path "ReleaseNotes.txt") | |
$idx = $releaseNotes.IndexOf($version) | |
if ($idx -lt 0) { | |
throw 'No release notes identified' | |
} | |
$versionReleaseNotes = @() | |
while ($releaseNotes[$idx]) { | |
$versionReleaseNotes += $releaseNotes[$idx] | |
$idx++ | |
} | |
Write-Host "Release Notes:" | |
Write-Host $VersionReleaseNotes | |
Write-Host "Update Module Manifest" | |
Update-ModuleManifest -Path (Join-Path $path "BcContainerHelper.psd1") ` | |
-RootModule "BcContainerHelper.psm1" ` | |
-ModuleVersion $version ` | |
-Author "Freddy Kristiansen" ` | |
-FunctionsToExport $functionsToExport ` | |
-AliasesToExport $aliasesToExport ` | |
-CompanyName "Microsoft" ` | |
-ReleaseNotes $versionReleaseNotes ` | |
-LicenseUri 'https://github.com/microsoft/navcontainerhelper/blob/master/LICENSE' ` | |
-ProjectUri 'https://github.com/microsoft/navcontainerhelper' | |
$certFileName = Join-Path ([System.IO.Path]::GetTempPath()) "$([GUID]::NewGuid().ToString()).pfx" | |
[System.IO.File]::WriteAllBytes($certFileName, ([Convert]::FromBase64String('${{ secrets.CodeSignCertificatePfx }}'))) | |
Remove-Module BcContainerHelper | |
Write-Host $path | |
Write-Host "Signing scripts" | |
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certFileName, '${{ secrets.CodeSignCertificatePassword }}') | |
$filesToSign = @((Get-ChildItem $path -Filter "*.ps1" -Recurse -Depth 99).FullName)+ | |
@((Get-ChildItem $path -Filter "*.psm1" -Recurse -Depth 99).FullName) | |
Set-AuthenticodeSignature -Certificate $cert -HashAlgorithm SHA256 -TimestampServer "http://timestamp.digicert.com" -FilePath $filesToSign | |
Write-Host "Upload to storage (preview)" | |
$storageContext = New-AzStorageContext -StorageAccountName 'bccontainerhelper' -UseConnectedAccount | |
New-AzStorageContainer -Name 'public' -Context $storageContext -Permission 'Container' -ErrorAction Ignore | Out-Null | |
Compress-Archive -path $path -DestinationPath "$($path).zip" | |
Set-AzStorageBlobContent -File "$($path).zip" -Context $storageContext -Container 'public' -Blob "$version.zip" -Force | Out-Null | |
Set-AzStorageBlobContent -File "$($path).zip" -Context $storageContext -Container 'public' -Blob "latest.zip" -Force | Out-Null | |
Write-Host "Publishing Module" | |
Publish-Module -Path $path -NuGetApiKey '${{ secrets.NugetKey }}' -SkipAutomaticTags | |
} | |
catch { | |
Write-Host "::Error::Error publishing module. Error was $($_.Exception.Message)" | |
$host.SetShouldExit(1) | |
} |