-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellcheck.dang
More file actions
91 lines (82 loc) · 1.92 KB
/
shellcheck.dang
File metadata and controls
91 lines (82 loc) · 1.92 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
A linter for shell scripts, powered by shellcheck
"""
type Shellcheck {
"""
Shell script paths to exclude from checking
"""
pub exclude: [String!]
"""
Run shellcheck on all shell scripts in the workspace
"""
pub check(ws: Workspace!): Void @check {
let layers = scripts(ws).reduce(directory) { layers, script =>
layers.withDirectory("", script.checkLayer)
}
layers.sync
null
}
"""
Find all .sh files in the workspace and return them as Script objects
"""
pub scripts(ws: Workspace!): [Script!] {
ws
.directory(".", include: ["**/*.sh"])
.glob("**/*.sh")
.map { wsPath =>
Script(
file: ws.file(wsPath),
path: wsPath,
base: base,
)
}
}
"""
The base container with shellcheck installed
"""
pub base: Container! {
container
.from("koalaman/shellcheck-alpine")
.withoutEntrypoint
.withWorkdir("/ws")
}
}
type Script {
"""
The shell script file to check
"""
let file: File!
"""
The path of the script relative to the workspace root
"""
pub path: String!
"""
The base container used to run shellcheck
"""
let base: Container!
"""
Run shellcheck on this script
"""
pub check: Void @check {
execCheck.sync
null
}
"""
Execute shellcheck on the script and return the resulting container.
Exposed separately so checkLayer can wrap it for parallel execution.
Can be inlined into check() once the engine supports parallel sub-checks.
"""
let execCheck: Container! {
base
.withMountedFile(path, file)
.withExec(["shellcheck", path])
}
"""
Wraps the check result as a directory layer, so Shellcheck.check() can
run all checks in parallel via directory merging. Temporary workaround
until the engine supports parallel sub-checks natively.
"""
let checkLayer: Directory! {
directory.withFile(path, execCheck.file(path))
}
}