From ad3a90139b0152d1cbb1ec5b49face1c89dbf80c Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Sun, 8 Dec 2024 21:37:09 -0800 Subject: [PATCH 1/2] 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 From e89e9aaccf823f7940addf13add5109f72afbd58 Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Sun, 8 Dec 2024 21:53:59 -0800 Subject: [PATCH 2/2] ci: skip hook generate-hatch-matrix in pre-commit.ci --- .pre-commit-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9abd8c4..25bf531 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,5 +57,6 @@ ci: # autoupdate_branch: '' # autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate' autoupdate_schedule: monthly - # skip: [] + skip: + - generate-hatch-matrix # submodules: false