Skip to content

Build and publish module #15

Build and publish module

Build and publish module #15

Workflow file for this run

# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
name: Build and publish module
on:
push:
branches:
- master
paths-ignore:
- '**'
tags:
- 'v*'
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
env:
MODULE_NAME: SpfAnalyzer
steps:
- uses: actions/checkout@v4
- uses: nuget/setup-nuget@v1
with:
nuget-version: 'latest'
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore "$env:GITHUB_WORKSPACE/src/IpHelper"
- name: Build compiled code
run: dotnet build "$env:GITHUB_WORKSPACE/src/IpHelper" --no-restore
- name: Build module
shell: pwsh
run: |
$moduleName = $env:MODULE_NAME
Copy-Item -Path "$env:GITHUB_WORKSPACE\LICENSE" -Destination "$env:GITHUB_WORKSPACE\Module\$moduleName\LICENSE.txt" -Force
"Building module"
&"$env:GITHUB_WORKSPACE\Workflow\BuildModule.ps1" -RootPath "$env:GITHUB_WORKSPACE" -ModuleName $moduleName
- name: Install AzureSignTool
run: dotnet tool install --global AzureSignTool
- name: Sign files
shell: pwsh
run: |
$files = Get-ChildItem "$env:GITHUB_WORKSPACE\Module\$env:MODULE_NAME" -File -Recurse -Include *.ps1, *.ps1xml, *.psd1, *.psm1, *.pssc, *.psrc, *.cdxml, *.dll
try {
foreach ($file in $files) {
azuresigntool sign `
-kvu ${{ vars.CODESIGNING_KEYVAULTURI }} `
-kvi ${{ vars.TENANTINTEGRATION_CLIENTID }} `
-kvt ${{ vars.TENANTINTEGRATION_TENANTID }} `
-kvs ${{ secrets.TENANTINTEGRATION_CLIENTSECRET }} `
-kvc ${{ vars.CODESIGNING_CERTNAME }} `
-tr 'http://timestamp.digicert.com' `
-v "$($file.FullName)"
}
}
catch {
Write-Host "Error: $($_.Exception)"
throw
}
Write-Host "Signed files summary:"
Get-AuthenticodeSignature -FilePath $files
- name: Setup external packages
shell: pwsh
run: |
$moduleName = $env:MODULE_NAME
"Setting up packages"
&"$env:GITHUB_WORKSPACE\Workflow\SetupPackages.ps1" -ModuleName $moduleName -RootPath "$env:GITHUB_WORKSPACE" -NugetPath $env:nuget
- name: Publish
#Publish to PS Gallery
shell: pwsh
if: ${{ github.event_name != 'workflow_dispatch' }}
env:
SECRET: ${{ secrets.GC_PSGALLERY_APIKEY }}
run: |
write-host "Publishing from: $env:GITHUB_WORKSPACE\Module\$env:MODULE_NAME"
try
{
$env:PSModulePath = "$env:PSModulePath;$env:GITHUB_WORKSPACE\Module"
"PSModulePath: $env:PSModulePath"
Publish-Module -Path "$env:GITHUB_WORKSPACE\Module\$env:MODULE_NAME" -NuGetApiKey "$env:SECRET"
}
catch
{
Write-Host "Error: $($_.Exception)"
throw
}