Skip to content

CI

CI #221

Workflow file for this run

name: CI
on:
push:
pull_request:
schedule:
- cron: "0 10 * * 1" # At 10:00 on Monday.
defaults:
run:
shell: pwsh
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Test with Pester
run: ./test.ps1
- name: Invoke action
env:
TEMP: ${{ runner.temp }}
run: |
$env:PWSH_SCRIPT_ACTION_TEXT = 'Write-Host "ok"; return "value"'
$output = pwsh -file ./action.ps1
if ($LASTEXITCODE -ne 0) {
Write-Host "::error::Action exited with exit code $LASTEXITCODE and outputted: $output"
throw
}
$diff = Compare-Object @('ok') $output -CaseSensitive
if ($diff) {
$diff | Format-Table | Write-Host
Write-Host "::error::Action output differed from the expected, see above."
throw "Action output differed from the expected"
}
$outFile = Get-Content $env:GITHUB_OUTPUT
$diff = Compare-Object @('result=value') $outFile
if ($diff) {
$diff | Format-Table | Write-Host
Write-Host "::error::Action output file differed from the expected, see above."
throw "Action output file differed from the expected"
}
build-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build module docs
uses: ./
with:
script: |
./build-docs.ps1 -Clean
git status --porcelain || $(throw "Documentation isn't up to date. Run 'build-docs.ps1' and commit changes.")
self-testing:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
# return string result
- name: Test that returned result string is not json serialized (act)
uses: ./
id: test-result-string
with:
script: return "testmsg"
- name: Test that returned result string is not json serialized (assert)
run: |
$result = '${{ steps.test-result-string.outputs.result }}'
if ($result -cne 'testmsg') {
Write-Host "::error::unexpected - Return string test failed: invalid result.`n$result"
exit 1
}
# return object result
- name: Test that returned result object is json serialized (act)
uses: ./
id: test-result-object
with:
script: return [ordered]@{ a = 1; b = "c" }
- name: Test that returned result object is json serialized (assert)
run: |
$result = '${{ steps.test-result-object.outputs.result }}'
if ($result -cne '{"a":1,"b":"c"}') {
Write-Host "::error::unexpected - Return object test failed: invalid result.`n$result"
exit 1
}
# throw
- name: Test that throwing causes action to fail (act)
uses: ./
id: test-throwing-fails-action
continue-on-error: true
with:
script: 'throw "expected: test error message"'
- name: Test that throwing causes action to fail (assert)
run: |
$outcome = '${{ steps.test-throwing-fails-action.outcome }}'
if ($outcome -cne 'failure') {
Write-Host "::error::unexpected - Throwing test failed: invalid outcome.`n$outcome"
exit 1
}
$errMsg = '${{ steps.test-throwing-fails-action.outputs.error }}'
if ($errMsg -cne 'expected: test error message') {
Write-Host "::error::unexpected - Throwing test failed: invalid error output.`n$errMsg"
exit 1
}
# check access to contexts
- name: Test that workflow contexts are available
uses: ./
with:
script: |
function Test-Value ($expression, $expected) {
$actual = Invoke-Expression $expression
if ($actual -cne $expected) {
throw "unexpected: Failed assertion:'$expression' evaluated to '$actual', expected '$expected'."
}
}
Test-Value '$github.token' '${{ github.token }}'
Test-Value '$job.status' '${{ job.status }}'
Test-Value '$runner.os' '${{ runner.os }}'
Test-Value '$strategy."fail-fast"' ([bool]'${{ strategy.fail-fast }}')
Test-Value '$matrix.os' '${{ matrix.os }}'
# Get-ActionInput
# Get-ActionInput isn't really testable in a script
- name: Get-ActionInput test
if: "false"
uses: ./
with:
custom-input: "test"
script: |
$script = Get-ActionInput script
if ($script -notlike '$script = Get-ActionInput script*') {
throw "unexpected: Get-ActionInput for 'script' failed.`n$script"
}
$custom = Get-ActionInput custom-input
if ($custom -cne 'test') {
throw "unexpected: Get-ActionInput for 'custom-input' failed.`n$custom"
}
# Set-ActionOutput
- name: Set-ActionOutput test (act)
id: Set-ActionOutput
run: |
Import-Module ./lib/GitHubActionsCore -Force
Set-ActionOutput testout testval
Set-ActionOutput testout-multiline "testval`n new line `n 3rd line"
Get-Content $env:GITHUB_OUTPUT -Raw | Write-Host
- name: Set-ActionOutput test (assert)
uses: ./
env:
testout_output: ${{ steps.Set-ActionOutput.outputs.testout }}
testout_multiline_output: ${{ steps.Set-ActionOutput.outputs.testout-multiline }}
with:
script: |
$output = $env:testout_output
if ($output -cne 'testval') {
throw "unexpected: Set-ActionOutput failed.`n$output"
}
$output = $env:testout_multiline_output
if ($output -cne "testval`n new line `n 3rd line") {
throw "unexpected: Set-ActionOutput failed.`n$output"
}
# Add-ActionPath
- name: Add-ActionPath test (act)
uses: ./
with:
script: Add-ActionPath 'testing add-path'
- name: Add-ActionPath test (assert)
uses: ./
with:
script: |
if ($env:PATH -notlike "*testing add-path$([System.IO.Path]::PathSeparator)*") {
throw "unexpected: Add-ActionPath failed.`n$env:PATH"
}
# Add-ActionSecret
- name: Add-ActionSecret test (manual check whether host-sent value is masked)
uses: ./
with:
script: |
$secret = [System.Guid]::NewGuid()
Add-ActionSecret $secret
Write-Host $secret
# Set-ActionVariable
- name: Set-ActionVariable test (act and first assert)
uses: ./
with:
script: |
$props = [ordered]@{ a = 1; b = 'c' }
Set-ActionVariable testvar $props
Set-ActionVariable testvar_multiline "line1`nline2`nline3"
Get-Content $env:GITHUB_ENV -Raw | Write-Host
if ($env:testvar -cne '{"a":1,"b":"c"}') {
throw "unexpected: Set-ActionVariable failed.`n$env:testvar"
}
- name: Set-ActionVariable test (second assert)
uses: ./
with:
script: |
if ($env:testvar -cne '{"a":1,"b":"c"}') {
throw "unexpected: Set-ActionVariable failed.`n$env:testvar"
}
if ($env:testvar_multiline -cne "line1`nline2`nline3") {
throw "unexpected: Set-ActionVariable failed.`n$env:testvar_multiline"
}
# Set-ActionCommandEcho
- name: Set-ActionCommandEcho test (manual check whether commands are shown in log)
uses: ./
with:
script: |
Set-ActionCommandEcho $false
Set-ActionOutput echo-off "unexpected to show up" # shouldn't show up in logs
Set-ActionCommandEcho $true
Set-ActionOutput echo-on "expected to show up" # should show up in logs
Set-ActionCommandEcho $false
# Set-ActionFailed
- name: Set-ActionFailed test (act)
uses: ./
id: Set-ActionFailed
continue-on-error: true
with:
script: |
Set-ActionFailed "expected: test error (this action should have exit code 1 in logs)"
- name: Set-ActionFailed test (assert)
uses: ./
with:
script: |
$result = '${{ steps.Set-ActionFailed.outcome }}'
if ($result -cne 'failure') {
throw "unexpected: Set-ActionFailed failed.`n$result"
}
# Get-ActionIsDebug
- name: Get-ActionIsDebug test
uses: ./
with:
script: |
$result = Get-ActionIsDebug
if ($result -ne ($env:RUNNER_DEBUG -eq '1')) {
throw "unexpected: Get-ActionIsDebug failed.`n$result"
}
# Invoke-ActionNoCommandsBlock
- name: Invoke-ActionNoCommandsBlock test (manual check)
id: Invoke-ActionNoCommandsBlock
run: |
Import-Module ./lib/GitHubActionsCore -Force
Invoke-ActionNoCommandsBlock -GenerateToken {
Write-ActionError "unexpected: this should not be visible as error"
}
# Write-Action -Debug, -Info, -Warning, -Error and Grouping are not testable in any sensible manner
- name: Write-Action... and Group... sample runs (manual check)
uses: ./
continue-on-error: true # since we're printing errors
with:
script: |
Enter-ActionOutputGroup 'testing log levels'
Write-ActionDebug "dbg msg"
Write-ActionInfo "expected: info msg"
Write-ActionWarning "expected: wrn msg"
Write-ActionError "expected: err msg"
Exit-ActionOutputGroup
Invoke-ActionGroup "Invoke-ActionGroup group" {
Write-Host "expected: output within Invoke-ActionGroup"
}