Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/actions/run-pre-commit/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Run selected pre-commit hooks
description: Run formatting, validation, or unit-test hooks from the shared configuration
inputs:
category:
description: Hook category (formatting, validation, or tests)
required: true
from-ref:
description: Optional base revision for changed-file checks
default: ""
to-ref:
description: Optional head revision for changed-file checks
default: ""
runs:
using: composite
steps:
- name: Install pre-commit
shell: bash
run: python -m pip install pre-commit

- name: Select and run hooks
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
shell: bash
env:
HOOK_CATEGORY: ${{ inputs.category }}
FROM_REF: ${{ inputs.from-ref }}
TO_REF: ${{ inputs.to-ref }}
run: |
config=$(mktemp "$RUNNER_TEMP/pre-commit.XXXXXX.yaml")
trap 'rm -f "$config"' EXIT
python - "$config" <<'PY'
import os
import sys

import yaml

formatting = {
"trailing-whitespace", "end-of-file-fixer", "mixed-line-ending",
"clang-format", "gersemi", "fix-header-guards", "jsonnet-format",
"markdownlint-cli2", "ruff", "ruff-format", "prettier",
}
tests = {"scripts-unit-tests"}
category = os.environ["HOOK_CATEGORY"]
if category not in {"formatting", "validation", "tests"}:
raise SystemExit(f"Unknown hook category: {category}")
with open(".pre-commit-config.yaml") as source:
config = yaml.safe_load(source)
configured = {hook["id"] for repo in config["repos"] for hook in repo["hooks"]}
missing = (formatting | tests) - configured
if missing:
raise SystemExit(f"Missing configured hooks: {sorted(missing)}")
selected = {
"formatting": formatting,
"validation": configured - formatting - tests,
"tests": tests,
}[category]
repos = []
for repo in config["repos"]:
hooks = [hook for hook in repo["hooks"] if hook["id"] in selected]
for hook in hooks:
if hook["id"] == "mypy":
hook["args"] = [*hook.get("args", []), "."]
hook["pass_filenames"] = False
hook["always_run"] = True
elif hook["id"] == "scripts-unit-tests":
hook["additional_dependencies"] = [
*hook.get("additional_dependencies", []), "pytest-cov",
]
hook["args"] = [
*hook.get("args", []),
"--cov=scripts", "--cov=ci", "--cov=.devcontainer",
"--cov-report=xml:coverage-scripts.xml", "--cov-report=term-missing",
]
if hooks:
repos.append({**repo, "hooks": hooks})
config["repos"] = repos
with open(sys.argv[1], "w") as destination:
yaml.safe_dump(config, destination)
PY
args=(--all-files)
if [[ -n "$FROM_REF" && -n "$TO_REF" ]]; then
args=(--from-ref "$FROM_REF" --to-ref "$TO_REF")
elif [[ -n "$FROM_REF" || -n "$TO_REF" ]]; then
echo "::error::Both from-ref and to-ref are required for changed-file checks"
exit 1
fi
python -m pre_commit run --config "$config" "${args[@]}" --show-diff-on-failure
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
22 changes: 11 additions & 11 deletions .github/workflows/actionlint-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ jobs:
uses: Framework-R-D/action-workflow-setup@f73307dd8c13cb66c2565c9ace32571517b1cea8 # v1
with:
include-globs: |
.pre-commit-config.yaml
.github/actionlint.yaml
.github/workflows/**/*.yml
.github/workflows/**/*.yaml
.github/actions/**/*.yml
Expand Down Expand Up @@ -93,21 +95,19 @@ jobs:
needs.setup.outputs.repo }}
persist-credentials: false

- name: Announce actionlint check
run: echo "➡️ Running actionlint check..."
- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.12"

- name: Install pre-commit
run: python -m pip install pre-commit

- name: Run actionlint
id: lint
continue-on-error: true
env:
CHECKOUT_PATH: ${{ needs.setup.outputs.checkout_path }}
ACTIONLINT_IMAGE_URL: "rhysd/actionlint@sha256:7ef0d156288b43c3bd5ee96bac787a28aae53275e88e4f9476a64bc0c19195c9" # v1.7.12
run: |
docker run --rm \
-v "$GITHUB_WORKSPACE/${CHECKOUT_PATH}:/work" \
-w /work \
"${ACTIONLINT_IMAGE_URL}" \
-config-file .github/actionlint.yaml
working-directory: ${{ needs.setup.outputs.checkout_path }}
run: python -m pre_commit run actionlint --all-files --show-diff-on-failure

- name: Evaluate actionlint result
if: always() && steps.lint.outcome != 'skipped'
Expand Down
117 changes: 0 additions & 117 deletions .github/workflows/clang-format-check.yaml

This file was deleted.

124 changes: 0 additions & 124 deletions .github/workflows/clang-format-fix.yaml

This file was deleted.

Loading
Loading