From 1880aba6950ec7ea6b726d89c4e420b7fd2b278c Mon Sep 17 00:00:00 2001 From: Jorge Martinez Date: Wed, 11 Jun 2025 15:25:41 +0200 Subject: [PATCH 1/6] ci(pre-commit): add shellcheck hook --- .pre-commit-config.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f7d9e1fd5..bb9cf843c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,12 @@ repos: +- repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.10.0.1 + hooks: + - id: shellcheck + entry: python shellcheck.py + language: python + - repo: https://github.com/psf/black rev: 25.1.0 hooks: @@ -39,4 +46,4 @@ repos: files: '/.*\.(yml)$' args: - --start_year=2022 - exclude: '^(.github|doc)/.*' \ No newline at end of file + exclude: '^(.github|doc)/.*' From 5d6eeb56f6db3570cd728fcf3f808d5d33d2a68a Mon Sep 17 00:00:00 2001 From: Jorge Martinez Date: Wed, 11 Jun 2025 15:33:50 +0200 Subject: [PATCH 2/6] ci(pre-commit): add shellcheck hook --- .pre-commit-config.yaml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bb9cf843c..fd5f87cd6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,17 @@ repos: -- repo: https://github.com/shellcheck-py/shellcheck-py - rev: v0.10.0.1 +#- repo: https://github.com/shellcheck-py/shellcheck-py +# rev: v0.10.0.1 +# hooks: +# - id: shellcheck + +- repo: local hooks: - - id: shellcheck + - id: style + name: custom-script entry: python shellcheck.py language: python + additional_dependencies: [shellcheck-py, pyyaml] - repo: https://github.com/psf/black rev: 25.1.0 From 0aac69770675ae025380f3bf31b134c46516d5a9 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Date: Wed, 11 Jun 2025 15:43:13 +0200 Subject: [PATCH 3/6] ci(bin): move scripts to common folder --- .pre-commit-config.yaml | 11 +++-------- bin/shellcheck | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 bin/shellcheck diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fd5f87cd6..311f4b46d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,15 +1,10 @@ repos: -#- repo: https://github.com/shellcheck-py/shellcheck-py -# rev: v0.10.0.1 -# hooks: -# - id: shellcheck - - repo: local hooks: - - id: style - name: custom-script - entry: python shellcheck.py + - id: shellcheck + name: shellcheck + entry: python bin/shellcheck language: python additional_dependencies: [shellcheck-py, pyyaml] diff --git a/bin/shellcheck b/bin/shellcheck new file mode 100644 index 000000000..fe3c9cf43 --- /dev/null +++ b/bin/shellcheck @@ -0,0 +1,36 @@ +import pathlib +import subprocess + +import yaml + +ACTIONS_DIRECTORY = pathlib.Path(__file__).parent.resolve() + +for actionfile in ACTIONS_DIRECTORY.glob("**/*.yml"): + if any(substring in str(actionfile) for substring in [".venv", "doc", ".github"]): + continue + + print(f"Reading {actionfile}", flush=True) + + try: + action = yaml.safe_load(actionfile.read_text(encoding="utf-8")) + except yaml.YAMLError as e: + print(f"YAML parse error in {actionfile}: {e}", flush=True) + continue + + # Check for existence of "runs" and "steps" + runs = action.get("runs", {}) + steps = runs.get("steps", []) + + for step in steps: + if step.get("shell") != "bash": + continue + if "run" not in step: + continue + + run_content = "#!/bin/bash\n" + step["run"] + result = subprocess.run( + ["shellcheck", "-"], + input=run_content, + capture_output=True, + text=True, + ) From 0227f887d276a13508add9a23ff16297080f4259 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Date: Wed, 11 Jun 2025 16:59:53 +0200 Subject: [PATCH 4/6] fix(labels): use the right name --- .github/labeler.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index eb199b92b..f1bcda698 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -16,7 +16,7 @@ - all-globs-to-all-files: ['!doc/styles/**', '!doc/.vale.ini'] ## -- Other labels ------------------------------------------------------------ -'code-style': +'style': - any: - changed-files: - any-glob-to-any-file: ['.pre-commit-config.yaml', 'doc/.vale.ini'] @@ -38,4 +38,4 @@ 'deploy-pr-doc': - all: - changed-files: - - all-globs-to-all-files: ['THIS-NEVER-MATCHES-A-FILE'] \ No newline at end of file + - all-globs-to-all-files: ['THIS-NEVER-MATCHES-A-FILE'] From 0c25388c903fffafc3dda6b6db44d56d53df7caf Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Wed, 11 Jun 2025 15:01:08 +0000 Subject: [PATCH 5/6] chore: adding changelog file 906.maintenance.md [dependabot-skip] --- doc/source/changelog/906.maintenance.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/source/changelog/906.maintenance.md diff --git a/doc/source/changelog/906.maintenance.md b/doc/source/changelog/906.maintenance.md new file mode 100644 index 000000000..db53a7fa3 --- /dev/null +++ b/doc/source/changelog/906.maintenance.md @@ -0,0 +1 @@ +Add shellcheck hook \ No newline at end of file From f6b285d057c5338437c2871da491a5881bd7458a Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Wed, 10 Sep 2025 13:27:46 +0000 Subject: [PATCH 6/6] chore: adding changelog file 906.maintenance.md [dependabot-skip] --- doc/source/changelog/906.maintenance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/changelog/906.maintenance.md b/doc/source/changelog/906.maintenance.md index db53a7fa3..d126eeff9 100644 --- a/doc/source/changelog/906.maintenance.md +++ b/doc/source/changelog/906.maintenance.md @@ -1 +1 @@ -Add shellcheck hook \ No newline at end of file +Add shellcheck hook