Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup GitHub Actions CI #2018

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="PowerShellCore_PublicPackages" value="https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v3/index.json" />
</packageSources>
</configuration>
3 changes: 1 addition & 2 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions tools/installPSResources.ps1
Original file line number Diff line number Diff line change
@@ -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