Skip to content

Commit 0b1e851

Browse files
committed
Attempt a github workflow
1 parent 5bde9fb commit 0b1e851

File tree

3 files changed

+150
-46
lines changed

3 files changed

+150
-46
lines changed

.github/workflows/build.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build on push
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: windows-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v2
11+
- name: GitVersion
12+
id: gitversion
13+
uses: PoshCode/Actions/gitversion@v1
14+
- name: Install-RequiredModules
15+
uses: PoshCode/Actions/install-requiredmodules@v1
16+
- name: Build Module
17+
id: build
18+
uses: PoshCode/actions/build-module@v1
19+
with:
20+
path: ${{github.workspace}}/Source
21+
version: ${{ steps.gitversion.outputs.LegacySemVerPadded }}
22+
destination: ${{github.workspace}}/output
23+
- name: Upload Build Output
24+
uses: actions/upload-artifact@v2
25+
with:
26+
name: Modules
27+
path: ${{github.workspace}}/output
28+
- name: Upload Tests
29+
uses: actions/upload-artifact@v2
30+
with:
31+
name: PesterTests
32+
path: ${{github.workspace}}/Specs
33+
- name: Upload RequiredModules.psd1
34+
uses: actions/upload-artifact@v2
35+
with:
36+
name: RequiredModules
37+
path: ${{github.workspace}}/RequiredModules.psd1
38+
- name: Upload PSScriptAnalyzerSettings.psd1
39+
uses: actions/upload-artifact@v2
40+
with:
41+
name: ScriptAnalyzer
42+
path: ${{github.workspace}}/PSScriptAnalyzerSettings.psd1
43+
test:
44+
runs-on: ${{ matrix.os }}
45+
strategy:
46+
matrix:
47+
os: [ubuntu-16.04, ubuntu-18.04, windows-2016, windows-latest, macos-latest]
48+
needs: build
49+
steps:
50+
- name: Download Build Output
51+
uses: actions/download-artifact@v2
52+
- uses: PoshCode/Actions/install-requiredmodules@v1
53+
- uses: PoshCode/Actions/pester@v1
54+
with:
55+
codeCoveragePath: Modules/ModuleBuilder
56+
moduleUnderTest: ModuleBuilder
57+
additionalModulePaths: ${{github.workspace}}/Modules
58+
- name: Publish Test Results
59+
uses: zyborg/dotnet-tests-report@v1
60+
with:
61+
test_results_path: results.xml
62+
- name: Upload Results
63+
uses: actions/upload-artifact@v2
64+
with:
65+
name: Pester Results
66+
path: ${{github.workspace}}/*.xml

Tests/ScriptAnalyzer.Tests.ps1

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
[CmdletBinding()]
2+
param(
3+
# The path to the folder where your code to analyze is
4+
[string]$Path = $((Get-Module ModuleBuilder).ModuleBase),
5+
6+
# Runs Script Analyzer on the files in the Path directory and all subdirectories recursively.
7+
[string]$Recurse,
8+
9+
# The name (or path) of a settings file to be used.
10+
[string]$Settings = "..\PSScriptAnalyzerSettings.psd1"
11+
)
12+
13+
if ($ModulesToImport) {
14+
Write-Verbose "Import-Module $ModulesToImport" -Verbose
15+
Import-Module $ModulesToImport
16+
$null = $PSBoundParameters.Remove("ModulesToImport")
17+
}
18+
$ExcludeRules = @()
19+
$CustomRulePath = @{}
20+
$RecurseCustomRulePath = $false
21+
if ($Settings) {
22+
Write-Verbose "Resolve settings '$Settings'" -Verbose
23+
if (Test-Path $Settings) {
24+
$Settings = Resolve-Path $Settings
25+
} else {
26+
Push-Location
27+
foreach($directory in Get-ChildItem -Directory) {
28+
Set-Location $directory
29+
if (Test-Path $Settings) {
30+
$Settings = Resolve-Path $Settings
31+
}
32+
}
33+
Pop-Location
34+
}
35+
if (!(Test-Path $Settings)) {
36+
Write-Warning "Could not resolve settings '$Settings'"
37+
Remove-Variable Settings
38+
$null = $PSBoundParameters.Remove("Settings")
39+
} else {
40+
$Config = Import-LocalizedData -BaseDirectory $pwd -FileName PSScriptAnalyzerSettings
41+
$ExcludeRules = @($Config.ExcludeRules)
42+
$CustomRulePath = @{
43+
CustomRulePath = @($Config.CustomRulePath)
44+
RecurseCustomRulePath = [bool]$Config.RecurseCustomRulePath
45+
}
46+
}
47+
}
48+
49+
Describe "ScriptAnalyzer" {
50+
$ScriptAnalyzer = @{
51+
Config = @{} + $PSBoundParameters
52+
Rules = Get-ScriptAnalyzerRule | Where-Object RuleName -notin $ExcludeRules
53+
}
54+
55+
if ($CustomRulePath) {
56+
$CustomRulePath | Should Exist
57+
if ($CustomRules = Get-ScriptAnalyzerRule @CustomRulePath) {
58+
$ScriptAnalyzer.Rules += $CustomRules
59+
}
60+
}
61+
62+
It "Does not throw while running Script Analyzer" {
63+
$Config = $ScriptAnalyzer.Config
64+
try {
65+
$ScriptAnalyzer.Results = Invoke-ScriptAnalyzer @Config
66+
} catch {
67+
Write-Warning "Exception running script analyzer on $($_.TargetObject)"
68+
Write-Warning $($_.Exception.StackTrace)
69+
throw
70+
}
71+
}
72+
73+
forEach ($Rule in $ScriptAnalyzer.Rules.RuleName) {
74+
It "Passes $Rule" {
75+
if ($Failures = $ScriptAnalyzer.Results.Where( {$_.RuleName -like "*$Rule"})) {
76+
throw ([Management.Automation.ErrorRecord]::new(
77+
([Exception]::new(($Failures.ForEach{$_.ScriptName + ":" + $_.Line + " " + $_.Message} -join "`n"))),
78+
"ScriptAnalyzerViolation",
79+
"SyntaxError",
80+
$Failures))
81+
}
82+
}
83+
}
84+
}

azure-pipelines.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)