Skip to content

Commit 6b74b16

Browse files
authored
ci: sync canonical pre-commit config (#11)
## Summary - generate and ignore the canonical pre-commit config instead of tracking a stale copy - refresh it atomically on every make test - install pre-commit and commit-msg hooks - add full-tree Gitleaks scanning configuration ## Validation - make test - canonical pre-commit run --all-files
1 parent 57e0170 commit 6b74b16

5 files changed

Lines changed: 38 additions & 69 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414

1515
# Plan output
1616
plan-output.txt
17+
18+
# Generated pre-commit configuration
19+
/.pre-commit-config.yaml
20+
/.pre-commit-config.yaml.tmp

.gitleaks.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[extend]
2+
useDefault = true
3+
4+
[[allowlists]]
5+
description = "Generated OpenTofu working data is ignored and never committed"
6+
paths = ['''(^|/)\.terraform(?:/.*)?$''']

.pre-commit-config.yaml

Lines changed: 0 additions & 49 deletions
This file was deleted.

AGENTS.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,34 @@ requested.
1313

1414
## Pre-commit Configuration
1515

16-
Pre-commit configuration is **centralized** in `makeitworkcloud/images/tfroot-runner/pre-commit-config.yaml`. The CI workflow fetches this config at runtime.
17-
18-
**Do not** create or modify `.pre-commit-config.yaml` in this repository.
16+
Pre-commit configuration is centralized at
17+
`https://raw.githubusercontent.com/makeitworkcloud/images/main/tfroot-runner/pre-commit-config.yaml`. The root
18+
`.pre-commit-config.yaml` is generated and ignored; do not edit it.
1919

2020
For local development, run:
2121
```bash
2222
make test
2323
```
2424

25-
This automatically fetches the canonical config if not present.
25+
This refreshes the generated config from the canonical source on every run and
26+
replaces it only when the content changed.
2627

2728
## CI/CD
2829

2930
This repo uses the shared `opentofu.yml` workflow from `shared-workflows`. Jobs
3031
run natively on `arc-tf`; the runner pod already uses the `tfroot-runner` image,
31-
so the workflow does not start a nested container.
32+
so the workflow does not start a nested container. The shared workflow fetches
33+
the canonical pre-commit config at runtime; this repository does not provide a
34+
tracked copy.
3235

3336
### Failure Modes
3437

3538
**"manifest unknown" error:** The `tfroot-runner:latest` image doesn't exist in GHCR. Check if the `images` repo Build workflow succeeded.
3639

37-
**Pre-commit failures:** If hooks fail unexpectedly, the canonical config may have changed. Delete `.pre-commit-config.yaml` locally and re-run `make test` to fetch the latest.
40+
**Pre-commit failures:** If hooks fail unexpectedly, the canonical config may
41+
have changed. Re-run `make test` to refresh it and run the checks.
3842

3943
## Related Repositories
4044

4145
- `images` - Contains tfroot-runner image and canonical pre-commit config
42-
- `shared-workflows` - Contains the reusable OpenTofu workflow and canonical pre-commit config
46+
- `shared-workflows` - Contains the reusable OpenTofu workflow

Makefile

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
SHELL := /bin/bash
22
TERRAFORM := $(shell which tofu)
3-
S3_REGION := $(shell sops decrypt secrets/secrets.yaml | grep ^s3_region | cut -d ' ' -f 2)
4-
S3_BUCKET := $(shell sops decrypt secrets/secrets.yaml | grep ^s3_bucket | cut -d ' ' -f 2)
5-
S3_KEY := $(shell sops decrypt secrets/secrets.yaml | grep ^s3_key | cut -d ' ' -f 2)
6-
S3_ACCESS_KEY := $(shell sops decrypt secrets/secrets.yaml | grep ^s3_access_key | cut -d ' ' -f 2)
7-
S3_SECRET_KEY := $(shell sops decrypt secrets/secrets.yaml | grep ^s3_secret_key | cut -d ' ' -f 2)
3+
S3_REGION = $(shell sops decrypt secrets/secrets.yaml | grep ^s3_region | cut -d ' ' -f 2)
4+
S3_BUCKET = $(shell sops decrypt secrets/secrets.yaml | grep ^s3_bucket | cut -d ' ' -f 2)
5+
S3_KEY = $(shell sops decrypt secrets/secrets.yaml | grep ^s3_key | cut -d ' ' -f 2)
6+
S3_ACCESS_KEY = $(shell sops decrypt secrets/secrets.yaml | grep ^s3_access_key | cut -d ' ' -f 2)
7+
S3_SECRET_KEY = $(shell sops decrypt secrets/secrets.yaml | grep ^s3_secret_key | cut -d ' ' -f 2)
88

9-
.PHONY: help init plan apply migrate test pre-commit-check-deps pre-commit-install-hooks argcd-login
9+
.PHONY: help init plan apply migrate test pre-commit-config pre-commit-check-deps pre-commit-install-hooks argcd-login
1010

1111
help:
1212
@echo "General targets"
@@ -55,12 +55,18 @@ migrate:
5555
@echo "First use -make init- using the old S3 backend, then run -make migrate- to use the new one."
5656
@${TERRAFORM} init -migrate-state -backend-config="key=${S3_KEY}" -backend-config="bucket=${S3_BUCKET}" -backend-config="region=${S3_REGION}" -backend-config="access_key=${S3_ACCESS_KEY}" -backend-config="secret_key=${S3_SECRET_KEY}"
5757

58-
test: .pre-commit-config.yaml .git/hooks/pre-commit
58+
test: pre-commit-config pre-commit-install-hooks
5959
@pre-commit run -a
6060

61-
.pre-commit-config.yaml:
62-
@curl -sSL -o .pre-commit-config.yaml \
61+
pre-commit-config:
62+
@curl --fail --silent --show-error --location \
63+
--output .pre-commit-config.yaml.tmp \
6364
https://raw.githubusercontent.com/makeitworkcloud/images/main/tfroot-runner/pre-commit-config.yaml
65+
@if cmp -s .pre-commit-config.yaml.tmp .pre-commit-config.yaml; then \
66+
rm -f .pre-commit-config.yaml.tmp; \
67+
else \
68+
mv .pre-commit-config.yaml.tmp .pre-commit-config.yaml; \
69+
fi
6470

6571
DEPS_PRE_COMMIT=$(shell which pre-commit || echo "pre-commit not found")
6672
DEPS_TERRAFORM_DOCS=$(shell which terraform-docs || echo "terraform-docs not found")
@@ -76,7 +82,5 @@ pre-commit-check-deps:
7682
@echo " jq: ${DEPS_JQ}"
7783
@echo ""
7884

79-
pre-commit-install-hooks: .git/hooks/pre-commit
80-
81-
.git/hooks/pre-commit: pre-commit-check-deps
82-
@pre-commit install --install-hooks
85+
pre-commit-install-hooks: pre-commit-config pre-commit-check-deps
86+
@pre-commit install --install-hooks --hook-type pre-commit --hook-type commit-msg

0 commit comments

Comments
 (0)