Add actionlint to pre-commit

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-04-11 14:36:57 +01:00
parent 6eacf22f8a
commit 359a8e80f7
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF
4 changed files with 76 additions and 0 deletions

4
.github/actionlint.yaml vendored Normal file
View file

@ -0,0 +1,4 @@
self-hosted-runner:
# Labels of self-hosted runner in array of string
labels:
- repo-release

View file

@ -21,6 +21,19 @@ repos:
hooks:
- id: black
- repo: https://github.com/s0undt3ch/python-tools-scripts
rev: "0.12.0"
hooks:
- id: tools
alias: actionlint
name: Lint GitHub Actions Workflows
files: "^.github/workflows/"
types:
- yaml
args:
- pre-commit
- actionlint
- repo: local
hooks:
- id: generate-actions-workflow

8
tools/__init__.py Normal file
View file

@ -0,0 +1,8 @@
import logging
import ptscripts
ptscripts.register_tools_module("tools.pre_commit")
for name in ("boto3", "botocore", "urllib3"):
logging.getLogger(name).setLevel(logging.INFO)

51
tools/pre_commit.py Normal file
View file

@ -0,0 +1,51 @@
"""
These commands are used by pre-commit.
"""
# pylint: disable=resource-leakage,broad-except,3rd-party-module-not-gated
from __future__ import annotations
import logging
import shutil
from ptscripts import Context, command_group
log = logging.getLogger(__name__)
# Define the command group
cgroup = command_group(
name="pre-commit", help="Pre-Commit Related Commands", description=__doc__
)
@cgroup.command(
name="actionlint",
arguments={
"files": {
"help": "Files to run actionlint against",
"nargs": "*",
},
"no_color": {
"help": "Disable colors in output",
},
},
)
def actionlint(ctx: Context, files: list[str], no_color: bool = False):
"""
Run `actionlint`
"""
actionlint = shutil.which("actionlint")
if not actionlint:
ctx.warn("Could not find the 'actionlint' binary")
ctx.exit(0)
cmdline = [actionlint]
if no_color is False:
cmdline.append("-color")
shellcheck = shutil.which("shellcheck")
if shellcheck:
cmdline.append(f"-shellcheck={shellcheck}")
pyflakes = shutil.which("pyflakes")
if pyflakes:
cmdline.append(f"-pyflakes={pyflakes}")
ret = ctx.run(*cmdline, *files, check=False)
ctx.exit(ret.returncode)