Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add actions-linters #4

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions actions-linters/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "GitHub Actions linters"
description: "A set of linters for GitHub Actions workflows"

runs:
using: "composite"
steps:
- name: actionlint
if: ${{ !cancelled() }}
shell: bash -euo pipefail {0}
env:
# SC2046 - Quote this to prevent word splitting. - https://www.shellcheck.net/wiki/SC2046
# SC2086 - Double quote to prevent globbing and word splitting. - https://www.shellcheck.net/wiki/SC2086
SHELLCHECK_OPTS: --exclude=SC2046,SC2086
run: |
echo "::group::actionlint"
echo "::add-matcher::${GITHUB_ACTION_PATH}/actionlint-matcher.json"
actionlint || actionlint_exit_code=$?
echo "::remove-matcher owner=actionlint::"
echo "::endgroup::"

exit ${actionlint_exit_code:-0}

- name: zizmor
if: ${{ !cancelled() }}
shell: bash -euo pipefail {0}
run: |
echo "::group::zizmor"
zizmor --format json . > zizmor.json || zizmor_exit_code=$?
jq --raw-output --arg GITHUB_WORKSPACE "$(pwd)" '
.[] as $item
| $item.locations[]
| select(.symbolic.annotation != "this step")
| "::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)"
' zizmor.json

# Run `zizmor` one more time to get output in the console,
# in case of any bugs in json parsing above
zizmor --no-exit-codes .

echo "::endgroup::"

exit ${zizmor_exit_code:-0}

- name: Disallow '*-latest' runners
if: ${{ !cancelled() }}
shell: bash -euo pipefail {0}
run: |
echo "::group::runs-on: *-latest"
PAT='^\s*runs-on:.*-latest'
if grep -ERq $PAT .github/workflows; then
grep -ERl $PAT .github/workflows |\
while read -r f; do
l=$(grep -nE $PAT $f | awk -F: '{print $1}' | head -1)
echo "::error file=$f,line=$l::Use verioned runner (like 'ubuntu-22.04' / 'macos-15') instead of '*-latest'"
done

exit_code=1
fi
echo "::endgroup::"

exit ${exit_code:-0}
17 changes: 17 additions & 0 deletions actions-linters/actionlint-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "actionlint",
"pattern": [
{
"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)* \\[(.+?)\\]$",
"file": 1,
"line": 2,
"column": 3,
"message": 4,
"code": 5
}
]
}
]
}