Don't fail if the actionlint binary cannot be found

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-01-31 05:26:32 +00:00
parent 326f091904
commit 736a7ca16f
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF
2 changed files with 43 additions and 5 deletions

View file

@ -4,11 +4,6 @@ default_language_version:
exclude: ^(doc/_static/.*|doc/_themes/.*)$
repos:
- repo: https://github.com/rhysd/actionlint
rev: v1.6.23
hooks:
- id: actionlint
- repo: https://github.com/s0undt3ch/python-tools-scripts
rev: "0.10.1"
hooks:
@ -24,6 +19,15 @@ repos:
- boto3==1.21.46
- pyyaml==6.0
- jinja2==3.1.2
- id: tools
alias: actionlint
name: Lint GitHub Actions Workflows
files: "^.github/workflows/"
types:
- yaml
args:
- pre-commit
- actionlint
- repo: https://github.com/saltstack/pip-tools-compile-impersonate
rev: "4.6"

View file

@ -6,6 +6,7 @@ from __future__ import annotations
import logging
import pathlib
import shutil
from jinja2 import Environment, FileSystemLoader
from ptscripts import Context, command_group
@ -69,3 +70,36 @@ def generate_workflows(ctx: Context):
loaded_template = env.get_template(f"{template}.j2")
rendered_template = loaded_template.render(**context)
workflow_path.write_text(rendered_template.rstrip() + "\n")
@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)