Skip to content

Invoke-Pog: Rollback import if installation fails #211

Invoke-Pog: Rollback import if installation fails

Invoke-Pog: Rollback import if installation fails #211

Workflow file for this run

name: Build
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
# versions of dependencies needed for building and bootstrapping Pog
# these should be updated periodically with the following command:
# ```
# "VERSION_PESTER: `"$((Find-Module Pester).Version)`""
# "VERSION_WIX_DARK: `"$((Find-Pog dark@ScoopInstaller).Version)`""
# Find-Pog ILRepack, UPX, 7zip | % {"VERSION_$($_.PackageName.ToUpperInvariant()): `"$($_.Version)`""}
# ```
VERSION_PESTER: "5.7.1"
VERSION_WIX_DARK: "3.14"
VERSION_ILREPACK: "2.0.41"
VERSION_UPX: "4.2.3"
VERSION_7ZIP: "24.09"
# avoid "Workload updates are available. Run `dotnet workload list` for more information."
DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_DISABLE: true
# D:\ drive on the GitHub actions runners is significantly faster than C:\, move what we can from C:\
TEMP: D:\.temp
NUGET_PACKAGES: D:\.nuget\packages
NUGET_HTTP_CACHE_PATH: D:\nuget\http-cache
NUGET_SCRATCH: D:\nuget\scratch
NUGET_PLUGINS_CACHE_PATH: D:\nuget\plugins-cache
jobs:
build:
runs-on: windows-2022
steps:
### SETUP #####################################################################################
- name: Configure git to preserve line endings
run: git config --global core.autocrlf false
- uses: actions/checkout@v4
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ${{ env.NUGET_PACKAGES }}
key: nuget-${{ github.job }}-${{ runner.os }}-${{ env.NUGET_PACKAGES }}-${{ hashFiles('**/packages.lock.json') }}
### TOOL INSTALLATION #########################################################################
# used for PowerShell unit tests
- name: Install Pester
working-directory: ..
shell: pwsh
run: |
# this is significantly faster than `Install-Module Pester -Force`
iwr "https://www.powershellgallery.com/api/v2/package/Pester/$($env:VERSION_PESTER)" -OutFile D:\pester.nupkg
$ModuleDir = "$(Split-Path $PROFILE)\Modules"
Expand-Archive D:\pester.nupkg "$ModuleDir\Pester"
# needed to unpack vcredist packages
- name: Install WiX dark.exe
shell: pwsh
run: |
iwr "https://raw.githubusercontent.com/ScoopInstaller/Binary/master/dark/dark-$($env:VERSION_WIX_DARK).zip" -OutFile D:\dark.zip
Expand-Archive D:\dark.zip D:\dark
Add-Content $env:GITHUB_PATH D:\dark
# needed to build Pog.dll
- name: Install ILRepack
shell: pwsh
run: |
iwr "https://www.nuget.org/api/v2/package/ILRepack/${env:VERSION_ILREPACK}" -OutFile D:\ilrepack.nupkg
Expand-Archive D:\ilrepack.nupkg D:\ilrepack
# add to PATH for following steps
Add-Content $env:GITHUB_PATH D:\ilrepack\tools
# needed to build PogShimTemplate.exe
- name: Install UPX
shell: pwsh
run: |
iwr "https://github.com/upx/upx/releases/download/v${env:VERSION_UPX}/upx-${env:VERSION_UPX}-win64.zip" -OutFile D:\upx.zip
Expand-Archive D:\upx.zip D:\upx_tmp
mv D:\upx_tmp\* D:\upx
rm D:\upx_tmp
# add to PATH for following steps
Add-Content $env:GITHUB_PATH D:\upx
# needed to install any Pog package (including an up-to-date 7zip)
- name: Install bootstrap 7zip
working-directory: ..
shell: pwsh
run: |
iwr "https://www.7-zip.org/a/7z$($env:VERSION_7ZIP.Replace('.', ''))-x64.exe" -OutFile D:\7zip.exe
Start-Process -Wait D:\7zip.exe -ArgumentList /S, /D=$PWD\7zip\app
# just a stub manifest, will be replaced later
Set-Content .\7zip\pog.psd1 '@{Private = $true; Enable = {Export-Command "7z" "./app/7z.exe" -VcRedist}}'
- name: Verify build dependencies
shell: pwsh
run: |
& {
[pscustomobject]@{Name = "dotnet.exe"; Version = dotnet.exe --version; Source = (gcm dotnet.exe).Source}
gmo Pester -ListAvailable | select -First 1
gcm dark.exe
gcm ilrepack.exe
gcm upx.exe
gcm ..\7zip\app\7z.exe
} | Format-Table -AutoSize
### BUILD #####################################################################################
- name: Restore NuGet dependencies
working-directory: app/Pog/lib_compiled
run: |
dotnet sln remove RandomTests RandomBenchmarks
dotnet restore -bl:D:\logs\restore.binlog
- name: Build Pog.dll
working-directory: app/Pog/lib_compiled
# most time is spent in ILRepack, and there's a lot of variance, I did not yet figure out
# an easy way to profile ILRepack execution in the CI
run: |
dotnet publish --no-restore Pog -bl:D:\logs\build.binlog
- name: Build Pog.Shim
working-directory: app/Pog/lib_compiled
# most time is spent configuring the CMake project, especially discovering compiler ID
# timing info can be found in .\Pog.Shim\cmake-build-release\CMakeFiles\CMakeConfigureLog.yaml
run: |
cmake -B .\Pog.Shim\cmake-build-release -S .\Pog.Shim -DCMAKE_BUILD_TYPE=Release
cmake --build .\Pog.Shim\cmake-build-release --config Release
gi .\PogShimTemplate.exe
- name: Download VC Redistributable
shell: pwsh
run: |
.\app\Pog\_scripts\vcredist-download.ps1 -OutDir .\app\Pog\lib_compiled\vc_redist @(
# latest vcredist 140
"https://aka.ms/vs/17/release/vc_redist.x64.exe"
# fixed vcredist 120
"https://aka.ms/highdpimfc2013x64enu"
)
- name: Setup Pog
shell: pwsh
run: |
.\setup.ps1
# add to PATH for following steps
Add-Content $env:GITHUB_PATH (Resolve-Path .\data\package_bin)
# reinstall 7zip with correct manifest
pog 7zip -Force
### TESTING ###################################################################################
- name: Pog.Tests
working-directory: app/Pog/lib_compiled
run: dotnet test --no-restore Pog.Tests
- name: Pester tests (PowerShell Core)
working-directory: app/Pog
shell: pwsh
run: Invoke-Pester -Output Detailed
- name: Pester tests (PowerShell 5)
working-directory: app/Pog
shell: powershell
run: Invoke-Pester -Output Detailed
# install a few Pog packages to check that Pog works
- name: Test Pog packages (PowerShell Core)
shell: pwsh
run: .\.github\workflows\TestPackageInstallation.ps1
# the same test in PowerShell 5, to test compatibility
- name: Test Pog packages (PowerShell 5)
shell: powershell
run: .\.github\workflows\TestPackageInstallation.ps1
### RELEASE ###################################################################################
- name: Generate release archive
shell: pwsh
run: |
.\app\Pog\_scripts\release\build-release.ps1 -ReleasePath D:\PogRelease.zip
# unpack so that the generated artifact (which is always zipped) is not a nested .zip
Expand-Archive D:\PogRelease.zip D:\PogRelease
- name: Upload release artifact
uses: actions/upload-artifact@v4
with:
name: Pog
path: D:/PogRelease
- name: Upload logs
uses: actions/upload-artifact@v4
with:
name: logs
path: D:/logs
- name: Update nightly release
shell: pwsh
run: |
.\.github\workflows\UpdateReleaseAsset.ps1 `
-ReleaseId 237074955 `
-AssetName Pog.zip `
-InFile D:\PogRelease.zip `
-GitHubToken (ConvertTo-SecureString -AsPlainText -Force "${{ secrets.GITHUB_TOKEN }}")
- name: Update nightly tag
shell: pwsh
run: |
git tag nightly HEAD -f
git push origin refs/tags/nightly -f