-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start using
actionlint
and shellcheck
to validate GH Actions work…
…flows Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
- Loading branch information
Showing
9 changed files
with
181 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
name: setup-actionlint | ||
description: Setup actionlint | ||
inputs: | ||
version: | ||
description: The version of actionlint | ||
default: 1.6.25 | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
|
||
- name: Cache actionlint Binary | ||
uses: actions/cache@v3 | ||
with: | ||
path: /usr/local/bin/actionlint | ||
key: ${{ runner.os }}|${{ runner.arch }}|actionlint|${{ inputs.version }} | ||
|
||
- name: Setup actionlint | ||
shell: bash | ||
run: | | ||
if ! command -v actionlint; then | ||
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) ${{ inputs.version }} | ||
mv ./actionlint /usr/local/bin/actionlint | ||
fi | ||
- name: Show actionlint Version | ||
shell: bash | ||
run: | | ||
actionlint --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
name: setup-shellcheck | ||
description: Setup shellcheck | ||
inputs: | ||
version: | ||
description: The version of shellcheck | ||
default: v0.9.0 | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
|
||
- name: Cache shellcheck Binary | ||
uses: actions/cache@v3 | ||
with: | ||
path: /usr/local/bin/shellcheck | ||
key: ${{ runner.os }}|${{ runner.arch }}|shellcheck|${{ inputs.version }} | ||
|
||
- name: Setup shellcheck | ||
shell: bash | ||
run: | | ||
if ! command -v shellcheck; then | ||
wget https://github.com/koalaman/shellcheck/releases/download/${{ inputs.version }}/shellcheck-${{ inputs.version }}.${{ runner.os }}.x86_64.tar.xz | ||
tar xf shellcheck-${{ inputs.version }}.${{ runner.os }}.x86_64.tar.xz | ||
mv shellcheck-${{ inputs.version }}/shellcheck /usr/local/bin/shellcheck | ||
rm -rf shellcheck-${{ inputs.version }}.${{ runner.os }}.x86_64.tar.xz shellcheck-${{ inputs.version }} | ||
fi | ||
- name: Show shellcheck Version | ||
shell: bash | ||
run: | | ||
shellcheck --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Start using actionlint and shellcheck to validate GH Actions workflows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python-tools-scripts >= 0.17.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
import ptscripts | ||
|
||
ptscripts.register_tools_module("tools.pre_commit") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
These commands are used by pre-commit. | ||
""" | ||
from __future__ import annotations | ||
|
||
import logging | ||
import shutil | ||
|
||
from ptscripts import Context | ||
from ptscripts import 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) |