Skip to content

Commit 914ac15

Browse files
committed
Add actions-linters
1 parent 3a07646 commit 914ac15

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

actions-linters/action.yml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: "GitHub Actions linters"
2+
description: "A set of linters for GitHub Actions workflows"
3+
4+
inputs:
5+
enable-actionlint:
6+
description: "Enable actionlint"
7+
required: false
8+
default: "true"
9+
type: "string"
10+
enable-zizmor:
11+
description: "Enable zizmor"
12+
required: false
13+
default: "true"
14+
type: "string"
15+
enable-disallow-latest:
16+
description: "Enable disallowing *-latest runners"
17+
required: false
18+
default: "true"
19+
type: "string"
20+
21+
runs:
22+
using: "composite"
23+
steps:
24+
- name: actionlint
25+
if: inputs.enable-actionlint == "true" && !cancelled()
26+
shell: bash -euo pipefail {0}
27+
env:
28+
# SC2046 - Quote this to prevent word splitting. - https://www.shellcheck.net/wiki/SC2046
29+
# SC2086 - Double quote to prevent globbing and word splitting. - https://www.shellcheck.net/wiki/SC2086
30+
SHELLCHECK_OPTS: --exclude=SC2046,SC2086
31+
run: |
32+
echo "::group::actionlint"
33+
echo "::add-matcher::${GITHUB_ACTION_PATH}/actionlint-matcher.json"
34+
actionlint || actionlint_exit_code=$?
35+
echo "::remove-matcher owner=actionlint::"
36+
echo "::endgroup::"
37+
38+
exit ${actionlint_exit_code:-0}
39+
40+
- name: zizmor
41+
if: inputs.enable-zizmor == "true" && !cancelled()
42+
shell: bash -euo pipefail {0}
43+
run: |
44+
echo "::group::zizmor"
45+
zizmor --format json . > zizmor.json || zizmor_exit_code=$?
46+
jq --raw-output --arg GITHUB_WORKSPACE "$(pwd)" '
47+
.[] as $item
48+
| $item.locations[]
49+
| select(.symbolic.annotation != "this step")
50+
| "::error file=\(.symbolic.key.Local.path | sub("^" + $GITHUB_WORKSPACE; "")),line=\(.concrete.location.start_point.row),endLine=\(.concrete.location.end_point.row),title=\($item.determinations.severity): \($item.desc)::\(.symbolic.annotation) - \($item.url)"
51+
' zizmor.json
52+
53+
# Run `zizmor` one more time to get output in the console,
54+
# in case of any bugs in json parsing above
55+
zizmor --no-exit-codes .
56+
57+
echo "::endgroup::"
58+
59+
exit ${zizmor_exit_code:-0}
60+
61+
- name: Disallow *-latest runners
62+
if: inputs.enable-disallow-latest == "true" && !cancelled()
63+
shell: bash -euo pipefail {0}
64+
run: |
65+
echo "::group::runs-on: *-latest"
66+
PATTERN='^\s*runs-on:.*-latest'
67+
if grep -ERq $PATTERN .github/workflows; then
68+
grep -ERl $PATTERN .github/workflows |\
69+
while read -r f; do
70+
l=$(grep -nE $PATTERN $f | awk -F: '{print $1}' | head -1)
71+
echo "::error file=$f,line=$l::Use verioned runner (like 'ubuntu-22.04' / 'macos-15') instead of '*-latest'"
72+
done
73+
74+
exit_code=1
75+
fi
76+
echo "::endgroup::"
77+
78+
exit ${exit_code:-0}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "actionlint",
5+
"pattern": [
6+
{
7+
"regexp": "^(?:\\x1b\\[\\d+m)?(.+?)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*: (?:\\x1b\\[\\d+m)*(.+?)(?:\\x1b\\[\\d+m)* \\[(.+?)\\]$",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"message": 4,
12+
"code": 5
13+
}
14+
]
15+
}
16+
]
17+
}

0 commit comments

Comments
 (0)