Skip to content

Commit

Permalink
devops: add linux and mac coverage to PR validation (#2833)
Browse files Browse the repository at this point in the history
* Add macos-13 and ubuntu-latest to build-and-test matrix
  * macos-13 not macos-latest because build currently fails on arm64
* Make code that checks if the build is running on windows clearer
* Make dotnet publish step check exit code
* Stop running dotnet publish and dotnet pack on non-windows where they failed with scary messages but confusingly allowed CI to pass since exit code was not checked
  • Loading branch information
nguerrera authored Oct 28, 2024
1 parent d3e9e2f commit 7b64c63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ on:
jobs:
#########################################################################
build-and-test:
runs-on: windows-latest
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-13]
runs-on: ${{matrix.os}}
steps:
- name: Check out code
uses: actions/checkout@v4
Expand All @@ -19,14 +22,16 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '3.1.x'
dotnet-version: |
3.1.x
6.0.x
- name: Show dotnet info
run: dotnet --info

- name: Build and Test
# NoFormat because there is a separate format check action below
run: ./BuildAndTest.cmd -NoFormat
run: pwsh ./scripts/BuildAndTest.ps1 -NoFormat

#########################################################################
build-multitool-for-npm:
Expand Down
14 changes: 9 additions & 5 deletions scripts/BuildAndTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ param(
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$InformationPreference = "Continue"
$OnWindows = $Env:OS -eq 'Windows_NT'
$NonWindowsOptions = @{}

$ScriptName = $([io.Path]::GetFileNameWithoutExtension($PSCommandPath))
Expand All @@ -106,6 +107,9 @@ function Invoke-DotNetBuild($solutionFileRelativePath) {
function Publish-Application($project, $framework) {
Write-Information "Publishing $project for $framework ..."
dotnet publish $SourceRoot\$project\$project.csproj --no-build --configuration $Configuration --framework $framework
if ($LASTEXITCODE -ne 0) {
Exit-WithFailureMessage $ScriptName "Publish failed."
}
}

# Create a directory populated with the binaries that need to be signed.
Expand Down Expand Up @@ -216,13 +220,13 @@ if (-not $?) {

if (-not $NoBuild) {
Invoke-DotNetBuild $SolutionFile
if ($ENV:OS) {
if ($OnWindows) {
Invoke-DotNetBuild $sampleSolutionFile
}
}

if (-not $NoTest) {
if (-not $ENV:OS) {
if (-not $OnWindows) {
$NonWindowsOptions = @{ "-filter" = "WindowsOnly!=true" }
}
& dotnet test $SourceRoot\$SolutionFile --no-build --configuration $Configuration @NonWindowsOptions
Expand All @@ -231,7 +235,7 @@ if (-not $NoTest) {
}
}

if (-not $NoPublish) {
if (-not $NoPublish -and $OnWindows) { # Can't publish on non-windows due to not building net4x assets
foreach ($project in $Projects.Applications) {
foreach ($framework in $Frameworks.Application) {
Publish-Application $project $framework
Expand All @@ -243,9 +247,9 @@ if (-not $NoSigningDirectory) {
New-SigningDirectory
}

if (-not $NoPackage) {
if (-not $NoPackage -and $OnWindows) { # Can't package on non-windows due to not building net4x assets
& dotnet pack $SourceRoot\$SolutionFile --no-build --configuration $Configuration
if ($ENV:OS -and $LASTEXITCODE -ne 0) {
if ($LASTEXITCODE -ne 0) {
Exit-WithFailureMessage $ScriptName "Package failed."
}
}
Expand Down

0 comments on commit 7b64c63

Please sign in to comment.