-
Notifications
You must be signed in to change notification settings - Fork 248
116 lines (94 loc) · 5.33 KB
/
Release.yaml
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
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/main/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)
}