From 14f7e4685fbb89c41d7efde0f76373f533c5ad2e Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Sun, 8 Dec 2024 21:37:09 -0800 Subject: [PATCH] ci: add script to generate hatch matrix, integrate pre-commit --- .github/workflows/generate-hatch-matrix.sh | 9 +++++++++ .pre-commit-config.yaml | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 .github/workflows/generate-hatch-matrix.sh diff --git a/.github/workflows/generate-hatch-matrix.sh b/.github/workflows/generate-hatch-matrix.sh new file mode 100644 index 0000000..1085a68 --- /dev/null +++ b/.github/workflows/generate-hatch-matrix.sh @@ -0,0 +1,9 @@ +set -u +outfile=$1 +hatch env show --json | jq 'to_entries | map(select(.key | startswith("test")))' | jq '{include: map({"hatch-env-name": .key, "python-version": .value.python})}' > $outfile + +git diff --exit-code $outfile +if [ $? -ne 0 ]; then + echo "Hatch environment matrix has changed. Please commit ${outfile}." + exit 1 +fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5970dc1..9abd8c4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,6 +33,21 @@ repos: - id: conventional-pre-commit stages: [commit-msg] + - repo: local + hooks: + - id: generate-hatch-matrix + name: generate-hatch-matrix + language: system + entry: bash .github/workflows/generate-hatch-matrix.sh + files: | + (?x)^( + .github/workflows/generate-hatch-matrix.sh| + .github/workflows/hatch-matrix.json + )$ + args: [".github/workflows/hatch-matrix.json"] + pass_filenames: false + types: [file] + ci: # autofix_commit_msg: | # [pre-commit.ci] auto fixes from pre-commit.com hooks