-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathps-analyzer.dang
More file actions
61 lines (54 loc) · 1.79 KB
/
ps-analyzer.dang
File metadata and controls
61 lines (54 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
A linter for PowerShell scripts, powered by PSScriptAnalyzer
"""
type PsAnalyzer {
"""
PSScriptAnalyzer version to install
"""
pub version: String! = "1.22.0"
"""
PowerShell script paths to exclude from checking
"""
pub exclude: [String!]
"""
Extra non-PowerShell file paths to include for scripts that need project context
"""
pub includeExtraFiles: [String!]! = []
"""
Run PSScriptAnalyzer on all PowerShell scripts in the workspace
"""
pub check(ws: Workspace!): Void @check {
let include = ["**/*.ps1", "**/*.psm1", "**/*.psd1"] + includeExtraFiles
let source = ws.directory(".", include: include, exclude: exclude)
let analyze = """
$ErrorActionPreference = 'Stop'
Invoke-ScriptAnalyzer -Path . -Recurse -EnableExit
"""
base
.withDirectory(".", source)
.withExec([
"pwsh",
"-NoLogo", # Skip the PowerShell startup banner.
"-NoProfile", # Avoid loading user or system profile scripts.
"-NonInteractive", # Fail instead of prompting for input.
"-Command", # Execute the following PowerShell command string.
analyze,
])
.sync
null
}
"""
The base container with PSScriptAnalyzer installed
"""
pub base: Container! {
let modulesPath = "/root/.local/share/powershell/Modules"
let packageUrl = "https://github.com/PowerShell/PSScriptAnalyzer/releases/download/" + version + "/PSScriptAnalyzer." + version + ".nupkg"
container
.from("alpine")
.withExec(["apk", "add", "--no-cache", "powershell", "unzip"])
.withMountedFile("/PSScriptAnalyzer.nupkg", http(packageUrl))
.withExec(["mkdir", "-p", modulesPath])
.withExec(["unzip", "-q", "/PSScriptAnalyzer.nupkg", "-d", modulesPath + "/PSScriptAnalyzer"])
.withWorkdir("/ws")
}
}