Skip to content

Commit 34d755c

Browse files
authored
Merge pull request #18 from krymtkts:feature/ci
Add GitHub Actions workflow for testing module.
2 parents b2fa909 + 919e127 commit 34d755c

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

.github/workflows/test.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test module
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Install modules from PSGallery (pwsh)
19+
shell: pwsh
20+
run: |
21+
Set-PSResourceRepository PSGallery -Trusted
22+
Install-PSResource Psake,Pester,PSScriptAnalyzer -Quiet -Reinstall -Scope CurrentUser
23+
- name: Execute All Tests
24+
shell: pwsh
25+
run: |
26+
Invoke-Psake -taskList TestAll
27+
if (-not $psake.build_success) { exit 1 }

PSScriptAnalyzerSettings.psd1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Based on the `CodeFormatting.psd1` settings for PSScriptAnalyzer 1.23.0.
2+
# https://github.com/PowerShell/PSScriptAnalyzer/blob/1.21.0/Engine/Settings/CodeFormatting.psd1
3+
@{
4+
IncludeRules = @(
5+
'PSPlaceOpenBrace',
6+
'PSPlaceCloseBrace',
7+
'PSUseConsistentWhitespace',
8+
'PSUseConsistentIndentation',
9+
'PSAlignAssignmentStatement',
10+
'PSUseCorrectCasing'
11+
)
12+
13+
Rules = @{
14+
PSPlaceOpenBrace = @{
15+
Enable = $true
16+
OnSameLine = $true
17+
NewLineAfter = $true
18+
IgnoreOneLineBlock = $true
19+
}
20+
21+
PSPlaceCloseBrace = @{
22+
Enable = $true
23+
NewLineAfter = $true
24+
IgnoreOneLineBlock = $true
25+
NoEmptyLineBefore = $false
26+
}
27+
28+
PSUseConsistentIndentation = @{
29+
Enable = $true
30+
Kind = 'space'
31+
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
32+
IndentationSize = 4
33+
}
34+
35+
PSUseConsistentWhitespace = @{
36+
Enable = $true
37+
CheckInnerBrace = $true
38+
CheckOpenBrace = $true
39+
CheckOpenParen = $true
40+
CheckOperator = $true
41+
CheckPipe = $true
42+
CheckPipeForRedundantWhitespace = $false
43+
CheckSeparator = $true
44+
CheckParameter = $false
45+
IgnoreAssignmentOperatorInsideHashTable = $true
46+
}
47+
48+
PSAlignAssignmentStatement = @{
49+
Enable = $false
50+
CheckHashtable = $true
51+
}
52+
53+
PSUseCorrectCasing = @{
54+
Enable = $true
55+
}
56+
}
57+
}

psakefile.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'ModuleName')]
2+
param()
3+
Properties {
4+
$ModuleName = Get-ChildItem -File -Path ./ -Recurse -Name '*.psm1' | Split-Path -Parent
5+
}
6+
7+
Task default -Depends TestAll
8+
9+
Task TestAll -Depends Lint, Test
10+
11+
Task Lint {
12+
$warn = Invoke-ScriptAnalyzer -Path "./${ModuleName}" -Settings PSScriptAnalyzerSettings.psd1
13+
if ($warn) {
14+
$warn
15+
throw 'Invoke-ScriptAnalyzer for {ModuleName} failed.'
16+
}
17+
$warn = Invoke-ScriptAnalyzer -Path ./*.ps1 -Settings PSScriptAnalyzerSettings.psd1
18+
if ($warn) {
19+
$warn
20+
throw 'Invoke-ScriptAnalyzer for ops scripts failed.'
21+
}
22+
}
23+
24+
Task Test {
25+
'Test is running!'
26+
# TODO: add Pester tests
27+
}

0 commit comments

Comments
 (0)