Skip to content

Commit 9c77e1e

Browse files
committed
Add actions-linters
1 parent 8327c8f commit 9c77e1e

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

actions-linters/action.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: "GitHub Actions linters"
2+
description: "A set of linters for GitHub Actions workflows"
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: actionlint
8+
if: ${{ !cancelled() }}
9+
shell: bash -euo pipefail {0}
10+
env:
11+
# SC2046 - Quote this to prevent word splitting. - https://www.shellcheck.net/wiki/SC2046
12+
# SC2086 - Double quote to prevent globbing and word splitting. - https://www.shellcheck.net/wiki/SC2086
13+
SHELLCHECK_OPTS: --exclude=SC2046,SC2086
14+
run: |
15+
echo "::group::actionlint"
16+
echo "::add-matcher::${GITHUB_ACTION_PATH}/actionlint-matcher.json"
17+
actionlint || actionlint_exit_code=$?
18+
echo "::remove-matcher owner=actionlint::"
19+
echo "::endgroup::"
20+
21+
exit ${actionlint_exit_code:-0}
22+
23+
- name: zizmor
24+
if: ${{ !cancelled() }}
25+
shell: bash -euo pipefail {0}
26+
run: |
27+
echo "::group::zizmor"
28+
zizmor --format json . > zizmor.json || zizmor_exit_code=$?
29+
jq --raw-output --arg GITHUB_WORKSPACE "$(pwd)" '
30+
.[] as $item
31+
| $item.locations[]
32+
| select(.symbolic.annotation != "this step")
33+
| "::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)"
34+
' zizmor.json
35+
36+
# Run `zizmor` one more time to get output in the console,
37+
# in case of any bugs in json parsing above
38+
zizmor --no-exit-codes .
39+
40+
echo "::endgroup::"
41+
42+
exit ${zizmor_exit_code:-0}
43+
44+
- name: Disallow '*-latest' runners
45+
if: ${{ !cancelled() }}
46+
shell: bash -euo pipefail {0}
47+
run: |
48+
echo "::group::runs-on: *-latest"
49+
PAT='^\s*runs-on:.*-latest'
50+
if grep -ERq $PAT .github/workflows; then
51+
grep -ERl $PAT .github/workflows |\
52+
while read -r f; do
53+
l=$(grep -nE $PAT $f | awk -F: '{print $1}' | head -1)
54+
echo "::error file=$f,line=$l::Use verioned runner (like 'ubuntu-22.04' / 'macos-15') instead of '*-latest'"
55+
done
56+
57+
exit_code=1
58+
fi
59+
echo "::endgroup::"
60+
61+
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)