From 1de133e655c8afb76887c21c9dece02791ab5a14 Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Fri, 25 Oct 2024 14:57:15 -0500 Subject: [PATCH 1/4] Consolidate PR validation into one file with multiple jobs (#2831) Both build-and-test and build-multitool-for-npm had jobs that were named "run". It turns out that job names must be globally unique. In some contexts, including branch protection and on the mobile github app, only the job name shows. So, you would see "Run" and not "Build and Test / Run" and "Build Multitool for npm / Run". Worse, you could not require both of these jobs to pass in branch protection. This change puts all of the required PR validation jobs together in one file to guarantee that future job names are unique and to encourage future jobs to be given equally good names. --- .github/workflows/build-and-test.yml | 24 --------- .github/workflows/build-multitool-for-npm.yml | 14 ------ .github/workflows/dotnet-format.yml | 24 --------- .github/workflows/validate-pr.yml | 50 +++++++++++++++++++ 4 files changed, 50 insertions(+), 62 deletions(-) delete mode 100644 .github/workflows/build-and-test.yml delete mode 100644 .github/workflows/build-multitool-for-npm.yml delete mode 100644 .github/workflows/dotnet-format.yml create mode 100644 .github/workflows/validate-pr.yml diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml deleted file mode 100644 index 04dcb2774..000000000 --- a/.github/workflows/build-and-test.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Build and Test - -on: - pull_request: - branches: [ "main" ] - -jobs: - build: - name: Run - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - with: - # GitHelper unit test requires full clone, not the shallow default of GitHub Actions - fetch-depth: 0 - - name: Setup dotnet - uses: actions/setup-dotnet@v4 - with: - dotnet-version: '3.1.x' - - name: Show dotnet info - run: dotnet --info - - name: Build and Test - # NoFormat because there is a separate format check action - run: ./BuildAndTest.cmd -NoFormat diff --git a/.github/workflows/build-multitool-for-npm.yml b/.github/workflows/build-multitool-for-npm.yml deleted file mode 100644 index 8347c3832..000000000 --- a/.github/workflows/build-multitool-for-npm.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Build Multitool for npm - -on: - pull_request: - branches: [ "main" ] - -jobs: - build: - name: Run - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - - name: Build Multitool for npm - run: ./scripts/BuildMultitoolForNpm.ps1 diff --git a/.github/workflows/dotnet-format.yml b/.github/workflows/dotnet-format.yml deleted file mode 100644 index c871bb2e0..000000000 --- a/.github/workflows/dotnet-format.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: dotnet format - -on: - pull_request: - branches: [ main ] - -jobs: - check-format: - runs-on: windows-latest - - steps: - - name: check out code - uses: actions/checkout@v2 - - - name: Setup .NET Core 3.1 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 3.1.x - - - name: Install format tool - run: dotnet tool install -g dotnet-format - - - name: dotnet format - run: dotnet-format --folder --check --exclude .\src\Sarif\Autogenerated\ diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml new file mode 100644 index 000000000..b709e76df --- /dev/null +++ b/.github/workflows/validate-pr.yml @@ -0,0 +1,50 @@ +name: Validate PR +on: + pull_request: + branches: [ "main" ] + +jobs: + ######################################################################### + build-and-test: + runs-on: windows-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + # GitHelper unit test requires full clone, not the shallow default of GitHub Actions + fetch-depth: 0 + + - name: Setup dotnet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '3.1.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 + + ######################################################################### + build-multitool-for-npm: + runs-on: windows-latest + steps: + - name: Checkout out code + uses: actions/checkout@v4 + + - name: Build Multitool for npm + run: ./scripts/BuildMultitoolForNpm.ps1 + + ######################################################################### + check-format: + runs-on: windows-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Install format tool + run: dotnet tool install -g dotnet-format + + - name: dotnet format + run: dotnet-format --folder --check --exclude .\src\Sarif\Autogenerated\ From d3e9e2f2988bcdd707b86e921fec6ed4e0368f7d Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Fri, 25 Oct 2024 15:32:03 -0500 Subject: [PATCH 2/4] devops: run same PR validation for landed commits (#2832) --- .github/workflows/{validate-pr.yml => validate.yml} | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename .github/workflows/{validate-pr.yml => validate.yml} (96%) diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate.yml similarity index 96% rename from .github/workflows/validate-pr.yml rename to .github/workflows/validate.yml index b709e76df..77e22a5f2 100644 --- a/.github/workflows/validate-pr.yml +++ b/.github/workflows/validate.yml @@ -1,5 +1,7 @@ -name: Validate PR +name: Validate on: + push: + branches: ["main"] pull_request: branches: [ "main" ] From 7b64c638e3ff9309fd1a5883593e25853cb2b970 Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Mon, 28 Oct 2024 12:02:12 -0500 Subject: [PATCH 3/4] devops: add linux and mac coverage to PR validation (#2833) * 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 --- .github/workflows/validate.yml | 11 ++++++++--- scripts/BuildAndTest.ps1 | 14 +++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 77e22a5f2..d2fba024b 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -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 @@ -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: diff --git a/scripts/BuildAndTest.ps1 b/scripts/BuildAndTest.ps1 index 48c74d3e5..cec7ada62 100644 --- a/scripts/BuildAndTest.ps1 +++ b/scripts/BuildAndTest.ps1 @@ -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)) @@ -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. @@ -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 @@ -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 @@ -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." } } From a4a0d6db73cff464b3ff7212c73f77b6ac9c9807 Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Fri, 1 Nov 2024 12:40:20 -0500 Subject: [PATCH 4/4] chore: use central package versions (#2825) The only actual package version changes are in test projects: - FluentAssertions: Unify to 6.12.0 - xunit: Unify to 2.4.2 - xunit.runner.console: Unify to 2.4.2 - xunit.runner.visualstudio: Unify to 2.4.5 NOTE: The xunit versions are slightly downgraded for Test.UnitTests.Sarif.Driver since upgrading xunit across the solution leads to issues: - New xunit analyzer errors - Dropped support for netcoreapp3.1 --- src/Directory.Packages.props | 45 +++++++++++++++++++ src/Sarif.Converters/Sarif.Converters.csproj | 18 ++++---- src/Sarif.Driver/Sarif.Driver.csproj | 18 ++++---- .../Sarif.Multitool.Library.csproj | 18 ++++---- src/Sarif.Multitool/Sarif.Multitool.csproj | 4 +- src/Sarif.WorkItems/Sarif.WorkItems.csproj | 2 +- src/Sarif/Sarif.csproj | 22 ++++----- .../Test.EndToEnd.Baselining.csproj | 2 +- .../Test.FunctionalTests.Sarif.csproj | 20 +++------ .../Test.UnitTests.Sarif.Converters.csproj | 20 +++------ .../Test.UnitTests.Sarif.Driver.csproj | 20 +++------ ...t.UnitTests.Sarif.Multitool.Library.csproj | 22 ++++----- .../Test.UnitTests.Sarif.Multitool.csproj | 16 +++---- .../Test.UnitTests.Sarif.WorkItems.csproj | 20 +++------ .../Test.UnitTests.Sarif.csproj | 26 +++++------ .../Test.UnitTests.WorkItems.csproj | 20 +++------ .../Test.Utilities.Sarif.csproj | 8 ++-- src/WorkItems/WorkItems.csproj | 30 ++++++------- 18 files changed, 164 insertions(+), 167 deletions(-) create mode 100644 src/Directory.Packages.props diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props new file mode 100644 index 000000000..868946073 --- /dev/null +++ b/src/Directory.Packages.props @@ -0,0 +1,45 @@ + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Sarif.Converters/Sarif.Converters.csproj b/src/Sarif.Converters/Sarif.Converters.csproj index 43db79750..348943f2e 100644 --- a/src/Sarif.Converters/Sarif.Converters.csproj +++ b/src/Sarif.Converters/Sarif.Converters.csproj @@ -42,27 +42,27 @@ - + - - + + - + - - - - - + + + + + diff --git a/src/Sarif.Driver/Sarif.Driver.csproj b/src/Sarif.Driver/Sarif.Driver.csproj index b32715e91..1d03cafc2 100644 --- a/src/Sarif.Driver/Sarif.Driver.csproj +++ b/src/Sarif.Driver/Sarif.Driver.csproj @@ -38,15 +38,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/Sarif.Multitool.Library/Sarif.Multitool.Library.csproj b/src/Sarif.Multitool.Library/Sarif.Multitool.Library.csproj index 17b0d56b7..c36741578 100644 --- a/src/Sarif.Multitool.Library/Sarif.Multitool.Library.csproj +++ b/src/Sarif.Multitool.Library/Sarif.Multitool.Library.csproj @@ -15,18 +15,18 @@ - - - - - - - - + + + + + + + + - + diff --git a/src/Sarif.Multitool/Sarif.Multitool.csproj b/src/Sarif.Multitool/Sarif.Multitool.csproj index e124bee9d..c28302bd1 100644 --- a/src/Sarif.Multitool/Sarif.Multitool.csproj +++ b/src/Sarif.Multitool/Sarif.Multitool.csproj @@ -37,8 +37,8 @@ - - + + diff --git a/src/Sarif.WorkItems/Sarif.WorkItems.csproj b/src/Sarif.WorkItems/Sarif.WorkItems.csproj index b6444d83c..8c628ce3d 100644 --- a/src/Sarif.WorkItems/Sarif.WorkItems.csproj +++ b/src/Sarif.WorkItems/Sarif.WorkItems.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/Sarif/Sarif.csproj b/src/Sarif/Sarif.csproj index e6795dd4a..97b74d894 100644 --- a/src/Sarif/Sarif.csproj +++ b/src/Sarif/Sarif.csproj @@ -33,14 +33,14 @@ - - + - + @@ -48,14 +48,14 @@ - - - - - - - - + + + + + + + + diff --git a/src/Test.EndToEnd.Baselining/Test.EndToEnd.Baselining.csproj b/src/Test.EndToEnd.Baselining/Test.EndToEnd.Baselining.csproj index 921bc6490..bd2c17021 100644 --- a/src/Test.EndToEnd.Baselining/Test.EndToEnd.Baselining.csproj +++ b/src/Test.EndToEnd.Baselining/Test.EndToEnd.Baselining.csproj @@ -1,7 +1,7 @@ - + diff --git a/src/Test.FunctionalTests.Sarif/Test.FunctionalTests.Sarif.csproj b/src/Test.FunctionalTests.Sarif/Test.FunctionalTests.Sarif.csproj index 0add3569b..95b694efa 100644 --- a/src/Test.FunctionalTests.Sarif/Test.FunctionalTests.Sarif.csproj +++ b/src/Test.FunctionalTests.Sarif/Test.FunctionalTests.Sarif.csproj @@ -47,19 +47,13 @@ - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + + diff --git a/src/Test.UnitTests.Sarif.Converters/Test.UnitTests.Sarif.Converters.csproj b/src/Test.UnitTests.Sarif.Converters/Test.UnitTests.Sarif.Converters.csproj index b17bb4ee8..07de3cd16 100644 --- a/src/Test.UnitTests.Sarif.Converters/Test.UnitTests.Sarif.Converters.csproj +++ b/src/Test.UnitTests.Sarif.Converters/Test.UnitTests.Sarif.Converters.csproj @@ -54,19 +54,13 @@ - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + + diff --git a/src/Test.UnitTests.Sarif.Driver/Test.UnitTests.Sarif.Driver.csproj b/src/Test.UnitTests.Sarif.Driver/Test.UnitTests.Sarif.Driver.csproj index c2f5dc8ca..932b56a95 100644 --- a/src/Test.UnitTests.Sarif.Driver/Test.UnitTests.Sarif.Driver.csproj +++ b/src/Test.UnitTests.Sarif.Driver/Test.UnitTests.Sarif.Driver.csproj @@ -30,19 +30,13 @@ - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + + diff --git a/src/Test.UnitTests.Sarif.Multitool.Library/Test.UnitTests.Sarif.Multitool.Library.csproj b/src/Test.UnitTests.Sarif.Multitool.Library/Test.UnitTests.Sarif.Multitool.Library.csproj index cbc27f175..41232298f 100644 --- a/src/Test.UnitTests.Sarif.Multitool.Library/Test.UnitTests.Sarif.Multitool.Library.csproj +++ b/src/Test.UnitTests.Sarif.Multitool.Library/Test.UnitTests.Sarif.Multitool.Library.csproj @@ -58,20 +58,14 @@ - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + + + diff --git a/src/Test.UnitTests.Sarif.Multitool/Test.UnitTests.Sarif.Multitool.csproj b/src/Test.UnitTests.Sarif.Multitool/Test.UnitTests.Sarif.Multitool.csproj index 899bb0338..9e6be5dd1 100644 --- a/src/Test.UnitTests.Sarif.Multitool/Test.UnitTests.Sarif.Multitool.csproj +++ b/src/Test.UnitTests.Sarif.Multitool/Test.UnitTests.Sarif.Multitool.csproj @@ -24,17 +24,11 @@ - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + diff --git a/src/Test.UnitTests.Sarif.WorkItems/Test.UnitTests.Sarif.WorkItems.csproj b/src/Test.UnitTests.Sarif.WorkItems/Test.UnitTests.Sarif.WorkItems.csproj index f4e63ce58..c297f5651 100644 --- a/src/Test.UnitTests.Sarif.WorkItems/Test.UnitTests.Sarif.WorkItems.csproj +++ b/src/Test.UnitTests.Sarif.WorkItems/Test.UnitTests.Sarif.WorkItems.csproj @@ -25,19 +25,13 @@ - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + + diff --git a/src/Test.UnitTests.Sarif/Test.UnitTests.Sarif.csproj b/src/Test.UnitTests.Sarif/Test.UnitTests.Sarif.csproj index 54abd927c..211a40a93 100644 --- a/src/Test.UnitTests.Sarif/Test.UnitTests.Sarif.csproj +++ b/src/Test.UnitTests.Sarif/Test.UnitTests.Sarif.csproj @@ -164,22 +164,16 @@ - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + + + + + diff --git a/src/Test.UnitTests.WorkItems/Test.UnitTests.WorkItems.csproj b/src/Test.UnitTests.WorkItems/Test.UnitTests.WorkItems.csproj index 8fd213dbf..6ad776b2b 100644 --- a/src/Test.UnitTests.WorkItems/Test.UnitTests.WorkItems.csproj +++ b/src/Test.UnitTests.WorkItems/Test.UnitTests.WorkItems.csproj @@ -16,19 +16,13 @@ - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + + diff --git a/src/Test.Utilities.Sarif/Test.Utilities.Sarif.csproj b/src/Test.Utilities.Sarif/Test.Utilities.Sarif.csproj index 316459193..931f7a810 100644 --- a/src/Test.Utilities.Sarif/Test.Utilities.Sarif.csproj +++ b/src/Test.Utilities.Sarif/Test.Utilities.Sarif.csproj @@ -9,11 +9,11 @@ to demonstrate we can bind to it and run successfuly. * We have to ship pre-patch versions of NewtonSoft for VisualStudio SDK, and mitigate risk by limiting nesting depth. --> - + - - - + + + diff --git a/src/WorkItems/WorkItems.csproj b/src/WorkItems/WorkItems.csproj index c2e15da96..1ae8e3ff6 100644 --- a/src/WorkItems/WorkItems.csproj +++ b/src/WorkItems/WorkItems.csproj @@ -25,24 +25,24 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + - +