Skip to content

Commit 7fd582f

Browse files
committed
Add GitHub Actions workflow for testing.
1 parent beb9c6a commit 7fd582f

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

.github/actions/test/action.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Test
2+
description: Setup .NET, install PowerShell modules and run all tests.
3+
4+
inputs:
5+
codecov_token:
6+
description: "Codecov token"
7+
required: false
8+
default: ""
9+
sarif_main_file:
10+
description: "SARIF file path for main project (empty = skip upload)"
11+
required: false
12+
default: ""
13+
sarif_test_file:
14+
description: "SARIF file path for test project (empty = skip upload)"
15+
required: false
16+
default: ""
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Setup .NET
22+
uses: actions/setup-dotnet@v5
23+
with:
24+
global-json-file: ./global.json
25+
- name: Install modules from PSGallery
26+
shell: pwsh
27+
run: |
28+
Set-PSResourceRepository PSGallery -Trusted
29+
Install-PSResource InvokeBuild, Pester, PSScriptAnalyzer -Quiet -Reinstall -Scope CurrentUser
30+
Install-PSResource Microsoft.PowerShell.PlatyPS -Prerelease -Quiet -Reinstall -Scope CurrentUser
31+
- name: Test release build
32+
shell: pwsh
33+
run: |
34+
./build.ps1 -Tasks Build -Configuration Release
35+
- name: Execute All Tests
36+
shell: pwsh
37+
run: |
38+
./build.ps1 -Tasks TestAll
39+
- name: Upload coverage reports to Codecov
40+
uses: codecov/codecov-action@v5
41+
if: runner.os == 'Linux' && inputs.codecov_token != ''
42+
with:
43+
files: ./coverage.cobertura.xml
44+
env:
45+
CODECOV_TOKEN: ${{ inputs.codecov_token }}
46+
# separate multiple SARIF uploads to add categories. see https://github.blog/changelog/2024-05-06-code-scanning-will-stop-combining-runs-from-a-single-upload/
47+
- name: Upload SARIF file for main project
48+
uses: github/codeql-action/upload-sarif@v4
49+
if: runner.os == 'Linux' && inputs.sarif_main_file != ''
50+
with:
51+
sarif_file: ${{ inputs.sarif_main_file }}
52+
category: Main
53+
- name: Upload SARIF file for test project
54+
uses: github/codeql-action/upload-sarif@v4
55+
if: runner.os == 'Linux' && inputs.sarif_test_file != ''
56+
with:
57+
sarif_file: ${{ inputs.sarif_test_file }}
58+
category: Test

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test main
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
permissions:
10+
contents: read
11+
security-events: write
12+
13+
jobs:
14+
test:
15+
strategy:
16+
# NOTE: Disable fail-fast to ensure tests run on all platforms.
17+
fail-fast: false
18+
matrix:
19+
os:
20+
- windows-latest
21+
- ubuntu-latest
22+
- macos-latest
23+
runs-on: ${{ matrix.os }}
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v6
27+
- name: Test
28+
uses: ./.github/actions/test
29+
with:
30+
codecov_token: ${{ secrets.CODECOV_TOKEN }}
31+
sarif_main_file: analysis/SampleModule-report.sarif
32+
sarif_test_file: analysis/SampleModule.Test-report.sarif

0 commit comments

Comments
 (0)