From e36d82c20b0ed7737e49b53dea540a89cab137cb Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:44:46 -0700 Subject: [PATCH] Setup GitHub Actions CI (#2018) And CFS. --- .github/workflows/ci-test.yml | 53 +++++++++++++++++++++++++++++++++++ NuGet.Config | 4 +-- build.psm1 | 3 +- tools/installPSResources.ps1 | 13 +++++++++ 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ci-test.yml create mode 100644 tools/installPSResources.ps1 diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml new file mode 100644 index 000000000..e3252aae0 --- /dev/null +++ b/.github/workflows/ci-test.yml @@ -0,0 +1,53 @@ +name: CI Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + ci: + name: pester + strategy: + matrix: + os: [ windows-latest, macos-latest, ubuntu-latest ] + runs-on: ${{ matrix.os }} + env: + DOTNET_NOLOGO: true + DOTNET_GENERATE_ASPNET_CERTIFICATE: false + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install dotnet + uses: actions/setup-dotnet@v4 + with: + cache: true + cache-dependency-path: '**/*.csproj' + + - name: Install PSResources + run: ./tools/installPSResources.ps1 + shell: pwsh + + - name: Build + run: ./build.ps1 -Configuration Release -All + shell: pwsh + + - name: Test + run: ./build.ps1 -Test + shell: pwsh + + - name: Test Windows PowerShell + run: | + Install-Module Pester -Scope CurrentUser -Force -SkipPublisherCheck + ./build.ps1 -Test + if: matrix.os == 'windows-latest' + shell: powershell + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: PSScriptAnalyzer-tests-${{ matrix.os }} + path: testResults.xml diff --git a/NuGet.Config b/NuGet.Config index 80f5bd7fc..f003b0fbd 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@ - + - + diff --git a/build.psm1 b/build.psm1 index 86dfbd763..22dc9ee5e 100644 --- a/build.psm1 +++ b/build.psm1 @@ -386,7 +386,6 @@ function Test-ScriptAnalyzer else { $testModulePath = Join-Path "${projectRoot}" -ChildPath out } - $testResultsFile = "'$(Join-Path ${projectRoot} -childPath TestResults.xml)'" $testScripts = "'${projectRoot}\Tests\Build','${projectRoot}\Tests\Engine','${projectRoot}\Tests\Rules','${projectRoot}\Tests\Documentation'" try { if ( $major -lt 5 ) { @@ -395,7 +394,7 @@ function Test-ScriptAnalyzer $savedModulePath = $env:PSModulePath $env:PSModulePath = "${testModulePath}{0}${env:PSModulePath}" -f [System.IO.Path]::PathSeparator $analyzerPsd1Path = Join-Path -Path $script:destinationDir -ChildPath "$analyzerName.psd1" - $scriptBlock = [scriptblock]::Create("Import-Module '$analyzerPsd1Path'; Invoke-Pester -Path $testScripts") + $scriptBlock = [scriptblock]::Create("Import-Module '$analyzerPsd1Path'; Invoke-Pester -Path $testScripts -CI") if ( $InProcess ) { & $scriptBlock } diff --git a/tools/installPSResources.ps1 b/tools/installPSResources.ps1 new file mode 100644 index 000000000..08532b8fe --- /dev/null +++ b/tools/installPSResources.ps1 @@ -0,0 +1,13 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$ErrorActionPreference = 'Stop' + +Set-PSRepository -Name PSGallery -InstallationPolicy Trusted | Out-Null +if ($PSVersionTable.PSVersion.Major -lt 6) { + throw "The build script requires PowerShell 7!" +} + +# TODO: Switch to Install-PSResource when CI uses PowerShell 7.4 +Install-Module -Name platyPS -Scope CurrentUser +Install-Module -Name Pester -Scope CurrentUser