mirror of
https://github.com/saltstack/salt-bootstrap.git
synced 2025-04-17 10:10:25 +00:00
Add actionlint to pre-commit
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
6eacf22f8a
commit
359a8e80f7
4 changed files with 76 additions and 0 deletions
4
.github/actionlint.yaml
vendored
Normal file
4
.github/actionlint.yaml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
self-hosted-runner:
|
||||||
|
# Labels of self-hosted runner in array of string
|
||||||
|
labels:
|
||||||
|
- repo-release
|
|
@ -21,6 +21,19 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- 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
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
- id: generate-actions-workflow
|
- id: generate-actions-workflow
|
||||||
|
|
8
tools/__init__.py
Normal file
8
tools/__init__.py
Normal 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
51
tools/pre_commit.py
Normal 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)
|
Loading…
Add table
Reference in a new issue