Skip to content

ci: Fix build, maybe. #37

ci: Fix build, maybe.

ci: Fix build, maybe. #37

Workflow file for this run

name: Build and Package
on: [push]
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: false
jobs:
compute-revision:
runs-on: windows-latest
outputs:
rev: ${{ steps.branch_build.outputs.number }}
steps:
- name: Compute per-branch build number
id: branch_build
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh
run: |
$ownerRepo = "${{ github.repository }}"
$branch = if ($env:GITHUB_HEAD_REF) { $env:GITHUB_HEAD_REF } else { $env:GITHUB_REF_NAME }
$wfRef = "${{ github.workflow_ref }}"
if ($wfRef -match "\.github/workflows/(?<file>[^@]+)@") { $wfFile = $matches.file } else { throw "Couldn't parse workflow file from workflow_ref" }
$uri = "https://api.github.com/repos/$ownerRepo/actions/workflows/$wfFile/runs?branch=$branch&per_page=1"
$headers = @{
Authorization = "Bearer $env:GH_TOKEN"
"X-GitHub-Api-Version" = "2022-11-28"
"User-Agent" = "branch-counter"
}
$resp = Invoke-RestMethod -Uri $uri -Headers $headers -Method GET
"number=$([int]$resp.total_count)" >> $env:GITHUB_OUTPUT
build-windows:
needs: compute-revision
runs-on: windows-latest
permissions:
packages: write
contents: read
strategy:
matrix:
platform: [x86, x64]
configuration: [Release]
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Add dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
- name: Setup NuGet
uses: NuGet/[email protected]
- uses: actions/cache@v4
with:
path: ${{ github.workspace }}\.nuget\packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Download and Setup VPinMAME
shell: pwsh
run: |
Invoke-WebRequest -Uri "https://github.com/freezy/dmd-extensions/files/4073824/VPinMAME31_Minimal.zip" -OutFile vpm.zip
Expand-Archive vpm.zip -DestinationPath vpm
cd vpm
regsvr32 /s VPinMAME.dll
cd ..
- name: Restore NuGet packages
run: nuget restore DmdExtensions.sln
- name: Restore DLLExport dependency
run: .\DllExport -action Restore -sln-file DmdExtensions.sln
- name: Compute per-branch build number
id: branch_build
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh
run: |
$ownerRepo = "${{ github.repository }}"
$branch = if ($env:GITHUB_HEAD_REF) { $env:GITHUB_HEAD_REF } else { $env:GITHUB_REF_NAME }
# Parse the workflow file name from workflow_ref: owner/repo/.github/workflows/<file>@<ref>
$wfRef = "${{ github.workflow_ref }}"
if ($wfRef -match "\.github/workflows/(?<file>[^@]+)@") { $wfFile = $matches.file } else { throw "Couldn't parse workflow file from workflow_ref" }
$uri = "https://api.github.com/repos/$ownerRepo/actions/workflows/$wfFile/runs?branch=$branch&per_page=1"
$headers = @{
Authorization = "Bearer $env:GH_TOKEN"
"X-GitHub-Api-Version" = "2022-11-28"
"User-Agent" = "branch-counter"
}
$resp = Invoke-RestMethod -Uri $uri -Headers $headers -Method GET
# total_count includes this current run, which is what we want (first run => 1)
$count = [int]$resp.total_count
"number=$count" >> $env:GITHUB_OUTPUT
- name: Update version info
id: set_version
shell: pwsh
run: |
[int]$revVal = 0
$ok = [int]::TryParse($env:BRANCH_BUILD, [ref]$revVal)
if (-not $ok -or $revVal -le 0) {
$revVal = [int]$env:GITHUB_RUN_NUMBER
}
$env:BRANCH_BUILD = "$revVal"
function replaceNumericVersion($name, $fileContent) {
# allow multi-digit segments; match the whole attribute
$pattern = '^[^/]*\[assembly:\s*' + [regex]::Escape($name) + '\("(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?"\)\s*$'
$re = [regex]::new($pattern)
foreach ($line in $fileContent) {
$m = $re.Match($line)
if ($m.Success) {
$major = [int]$m.Groups[1].Value
$minor = [int]$m.Groups[2].Value
$patch = [int]$m.Groups[3].Value
$new = "[assembly: $name(""$major.$minor.$patch.$($env:BRANCH_BUILD)"")]"
return $fileContent -replace $pattern, [System.Text.RegularExpressions.Regex]::Escape($new).Replace('\[','[').Replace('\]',']')
}
}
}
function replaceFullVersion($name, $fileContent) {
# use \d+ (not just \d) and capture optional -tag
$pattern = '[^/]*\[assembly:\s*' + [regex]::Escape($name) + '\("(\d+)\.(\d+)\.(\d+)(?:-([\w\W]+))?"\)\s*$'
$re = [regex]::new($pattern)
foreach ($line in $fileContent) {
$m = $re.Match($line)
if ($m.Success) {
$major = [int]$m.Groups[1].Value
$minor = [int]$m.Groups[2].Value
$patch = [int]$m.Groups[3].Value
$tag = $m.Groups[4].Value
$branch = if ($env:GITHUB_HEAD_REF) { $env:GITHUB_HEAD_REF } else { $env:GITHUB_REF_NAME }
if ($branch -eq "master" -or $branch -eq "main") {
$version = if ($tag) { "$major.$minor.$patch-$tag-r$($env:BRANCH_BUILD)" } else { "$major.$minor.$patch-r$($env:BRANCH_BUILD)" }
} else {
$version = "$major.$minor.$patch-$($branch.ToUpper())-r$($env:BRANCH_BUILD)"
}
"version=$version" >> $env:GITHUB_OUTPUT
$new = "[assembly: $name(""$version"")]"
return $fileContent -replace $pattern, [System.Text.RegularExpressions.Regex]::Escape($new).Replace('\[','[').Replace('\]',']')
}
}
}
function replaceAny($name, $replaceWith, $fileContent) {
$pattern = '^[^/]*\[assembly:\s*' + [regex]::Escape($name) + '\("[^"]*"\)\s*$'
$re = [regex]::new($pattern)
foreach ($line in $fileContent) {
if ($re.IsMatch($line)) {
$new = "[assembly: $name(""$replaceWith"")]"
return $fileContent -replace $pattern, [System.Text.RegularExpressions.Regex]::Escape($new).Replace('\[','[').Replace('\]',']')
}
}
}
- name: Build
run: msbuild -t:rebuild /p:Platform=${{ matrix.platform }} /p:Configuration=${{ matrix.configuration }} DmdExtensions.sln
- name: Build installer
run: msbuild /p:Platform=${{ matrix.platform }} /p:Configuration=${{ matrix.configuration }} /p:SolutionDir="$env:GITHUB_WORKSPACE\" .\Installer\Installer.wixproj
- name: Package portable bundle (folder)
shell: pwsh
run: |
$version = "${{ steps.set_version.outputs.version }}"
$outDir = "$env:GITHUB_WORKSPACE\Installer\Builds"
$bundleDir = Join-Path $outDir "dmdext-v$version-${{ matrix.platform }}"
New-Item -ItemType Directory -Force -Path $bundleDir | Out-Null
# Core binaries/config
Copy-Item "$env:GITHUB_WORKSPACE\Console\bin\${{ matrix.platform }}\${{ matrix.configuration }}\dmdext.exe" -Destination $bundleDir -Force
Copy-Item "$env:GITHUB_WORKSPACE\Console\bin\${{ matrix.platform }}\${{ matrix.configuration }}\dmdext.log.config" -Destination $bundleDir -Force
Copy-Item "$env:GITHUB_WORKSPACE\Console\ProPinballSlave.bat" -Destination $bundleDir -Force
# PinMAME device bits
$dllSuffix = if ('${{ matrix.platform }}' -eq 'x64') { '64' } else { '' }
Copy-Item "$env:GITHUB_WORKSPACE\PinMameDevice\bin\${{ matrix.platform }}\${{ matrix.configuration }}\DmdDevice$dllSuffix.dll" -Destination $bundleDir -Force
Copy-Item "$env:GITHUB_WORKSPACE\PinMameDevice\bin\${{ matrix.platform }}\${{ matrix.configuration }}\DmdDevice.log.config" -Destination $bundleDir -Force
# ini template as a folder
New-Item -ItemType Directory -Force -Path (Join-Path $bundleDir 'ini-template') | Out-Null
Copy-Item "$env:GITHUB_WORKSPACE\PinMameDevice\DmdDevice.ini" -Destination (Join-Path $bundleDir 'ini-template\DmdDevice.ini') -Force
# data folder contents under a 'dmdext' subfolder
New-Item -ItemType Directory -Force -Path (Join-Path $bundleDir 'dmdext') | Out-Null
Copy-Item "$env:GITHUB_WORKSPACE\PinMameDevice\data\*" -Destination (Join-Path $bundleDir 'dmdext') -Recurse -Force
- name: Rename MSI to versioned filename
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$version = "${{ steps.set_version.outputs.version }}"
$root = $env:GITHUB_WORKSPACE
$outDir = Join-Path $root 'Installer\Builds'
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
$searchRoots = @(
(Join-Path $root 'Installer\Builds'),
(Join-Path $root 'Installer\bin'),
(Join-Path $root 'Installer')
) | Get-Unique
$candidates = foreach ($dir in $searchRoots) {
if (Test-Path $dir) { Get-ChildItem -Path $dir -Filter *.msi -File -Recurse -ErrorAction SilentlyContinue }
}
if (-not $candidates) { throw "No MSI found under:`n - $($searchRoots -join "`n - ")" }
$msi = $candidates | Sort-Object LastWriteTimeUtc -Descending | Select-Object -First 1
$target = Join-Path $outDir "dmdext-v$version-${{ matrix.platform }}.msi"
if ($msi.FullName -ieq $target) { exit 0 }
Copy-Item $msi.FullName $target -Force
if ($msi.FullName -ne $target) { Remove-Item $msi.FullName -Force }
- name: Upload portable bundle (single zip by GitHub)
uses: actions/upload-artifact@v4
with:
name: dmdext-v${{ steps.set_version.outputs.version }}-${{ matrix.platform }}
path: ${{ github.workspace }}\Installer\Builds\dmdext-v${{ steps.set_version.outputs.version }}-${{ matrix.platform }}
retention-days: 90
if-no-files-found: error
- name: Upload MSI (wrapped by GitHub)
uses: actions/upload-artifact@v4
with:
name: dmdext-v${{ steps.set_version.outputs.version }}-${{ matrix.platform }}-msi
path: ${{ github.workspace }}\Installer\Builds\dmdext-v${{ steps.set_version.outputs.version }}-${{ matrix.platform }}.msi
retention-days: 90
if-no-files-found: error