Skip to content

Commit bf8fd5b

Browse files
trouzeclaude
andauthored
ci: consolidate PR workflows into single ci.yml + add act support (#34)
- Rewrites ci.yml with 6 jobs: validate, module-tests, docs, schema-drift, yaml-validate, mkdocs-build - Deletes test.yml, schema-drift.yml, validate.yml (content merged in) - Removes pull_request trigger from deploy_docs.yml (build-only check now lives in ci.yml mkdocs-build job) - Adds scripts/gen-docs.sh to centralize terraform-docs generation - Adds .actrc for local act runs (linux/amd64, catthehacker image, offline mode) - Adds .secrets to .gitignore for local integration test credentials - Deletes Makefile (all targets replaced by pre-commit hooks and act) Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 8b9ea35 commit bf8fd5b

9 files changed

Lines changed: 192 additions & 257 deletions

File tree

.actrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--container-architecture linux/amd64
2+
-P ubuntu-latest=catthehacker/ubuntu:act-latest
3+
--action-offline-mode
4+
--pull=false
5+
--secret-file .secrets

.github/workflows/ci.yml

Lines changed: 171 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,34 @@ on:
44
pull_request:
55
paths:
66
- "**.tf"
7+
- "modules/**"
78
- "tests/**"
89
- "schemas/**"
9-
- "docs/reference/**"
10+
- "scripts/**"
11+
- "validate/**"
12+
- "docs/**"
13+
- "mkdocs.yml"
1014
- ".terraform-docs.yml"
15+
- ".terraform.lock.hcl"
1116
- ".github/workflows/ci.yml"
1217
- "!topologies/**"
1318
push:
1419
branches: [main]
1520
paths:
1621
- "**.tf"
22+
- "modules/**"
1723
- "tests/**"
1824
- "schemas/**"
19-
- "docs/reference/**"
25+
- "scripts/**"
26+
- "validate/**"
27+
- "docs/**"
28+
- "mkdocs.yml"
2029
- ".terraform-docs.yml"
30+
- ".terraform.lock.hcl"
31+
- ".github/workflows/ci.yml"
2132
- "!topologies/**"
33+
schedule:
34+
- cron: "0 8 * * 1"
2235

2336
permissions:
2437
contents: read
@@ -61,6 +74,42 @@ jobs:
6174
- name: Test (mock providers)
6275
run: terraform test
6376

77+
module-tests:
78+
name: Module Tests (${{ matrix.module }})
79+
runs-on: ubuntu-latest
80+
strategy:
81+
matrix:
82+
module:
83+
- project
84+
- environments
85+
- jobs
86+
- credentials
87+
- repository
88+
89+
steps:
90+
- name: Checkout
91+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
92+
93+
- name: Setup Terraform
94+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
95+
with:
96+
terraform_version_file: .terraform-version
97+
98+
- name: Cache Terraform providers
99+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
100+
with:
101+
path: .terraform
102+
key: terraform-${{ hashFiles('.terraform.lock.hcl') }}
103+
restore-keys: terraform-
104+
105+
- name: Terraform Init
106+
working-directory: modules/${{ matrix.module }}
107+
run: terraform init -backend=false
108+
109+
- name: Terraform Test
110+
working-directory: modules/${{ matrix.module }}
111+
run: terraform test -verbose
112+
64113
docs:
65114
name: Docs up to date
66115
runs-on: ubuntu-latest
@@ -78,12 +127,130 @@ jobs:
78127
chmod +x /usr/local/bin/terraform-docs
79128
80129
- name: Regenerate docs
81-
run: make docs
130+
run: bash scripts/gen-docs.sh
82131

83132
- name: Check for drift
84133
run: |
85134
if ! git diff --exit-code docs/reference/; then
86135
echo ""
87-
echo "Docs are out of date. Run 'make docs' locally and commit the result."
136+
echo "Docs are out of date. Run 'bash scripts/gen-docs.sh' locally and commit the result."
137+
exit 1
138+
fi
139+
140+
schema-drift:
141+
name: Schema Drift Check
142+
runs-on: ubuntu-latest
143+
144+
steps:
145+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
146+
147+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
148+
with:
149+
terraform_version_file: .terraform-version
150+
151+
- name: Cache Terraform providers
152+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
153+
with:
154+
path: .terraform
155+
key: terraform-${{ hashFiles('.terraform.lock.hcl') }}
156+
restore-keys: terraform-
157+
158+
- name: Init
159+
run: terraform init -backend=false
160+
161+
- name: Install uv
162+
uses: astral-sh/setup-uv@v5
163+
164+
- name: Check schema drift
165+
run: |
166+
uv run --with PyYAML scripts/check_schema_drift.py \
167+
--mapping scripts/resource_mapping.yml \
168+
--schema schemas/v1.json \
169+
--terraform-dir .
170+
171+
- name: Annotate PR on failure
172+
if: failure() && github.event_name == 'pull_request'
173+
run: |
174+
echo "::error::Schema drift detected. Run 'uv run --with PyYAML scripts/check_schema_drift.py --mapping scripts/resource_mapping.yml --schema schemas/v1.json --terraform-dir .' locally and classify any UNMAPPED fields in scripts/resource_mapping.yml. Add MISSING_FROM_SCHEMA fields to schemas/v1.json."
175+
176+
yaml-validate:
177+
name: YAML Validate Action
178+
runs-on: ubuntu-latest
179+
180+
steps:
181+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
182+
183+
- name: Valid YAML passes
184+
uses: ./validate
185+
with:
186+
file: validate/tests/valid.yml
187+
188+
- name: Invalid YAML is rejected
189+
id: validate-invalid
190+
uses: ./validate
191+
with:
192+
file: validate/tests/invalid.yml
193+
continue-on-error: true
194+
195+
- name: Assert validation failed
196+
run: |
197+
if [ "${{ steps.validate-invalid.outcome }}" != "failure" ]; then
198+
echo "Expected validation to fail for invalid.yml, but it did not."
88199
exit 1
89200
fi
201+
echo "Validation correctly rejected invalid.yml."
202+
203+
mkdocs-build:
204+
name: MkDocs Build
205+
runs-on: ubuntu-latest
206+
env:
207+
TERRAFORM_DOCS_VERSION: v0.20.0
208+
209+
steps:
210+
- name: Checkout
211+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
212+
with:
213+
fetch-depth: 0
214+
215+
- name: Setup Python
216+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
217+
with:
218+
python-version: "3.12"
219+
cache: "pip"
220+
cache-dependency-path: "docs/requirements.txt"
221+
222+
- name: Install MkDocs and dependencies
223+
run: pip install -r docs/requirements.txt
224+
225+
- name: Install terraform-docs
226+
run: |
227+
wget -O /tmp/terraform-docs.tar.gz \
228+
https://github.com/terraform-docs/terraform-docs/releases/download/${TERRAFORM_DOCS_VERSION}/terraform-docs-${TERRAFORM_DOCS_VERSION}-linux-amd64.tar.gz
229+
tar -xzf /tmp/terraform-docs.tar.gz -C /tmp
230+
sudo mv /tmp/terraform-docs /usr/local/bin/
231+
chmod +x /usr/local/bin/terraform-docs
232+
233+
- name: Generate Terraform documentation
234+
run: bash scripts/gen-docs.sh
235+
236+
- name: Setup Pages
237+
id: pages
238+
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5
239+
240+
- name: Set MkDocs site_url for GitHub Pages
241+
run: |
242+
SITE_URL="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/"
243+
python3 -c "
244+
import re, pathlib, sys
245+
site_url = sys.argv[1]
246+
path = pathlib.Path('mkdocs.yml')
247+
text = path.read_text()
248+
text, n = re.subn(r'(?m)^site_url:.*$', f'site_url: {site_url}', text, count=1)
249+
if n != 1:
250+
sys.exit('Expected exactly one site_url line in mkdocs.yml')
251+
path.write_text(text)
252+
print(f'site_url -> {site_url}')
253+
" "$SITE_URL"
254+
255+
- name: Build with MkDocs
256+
run: mkdocs build --strict --site-dir ./site

.github/workflows/deploy_docs.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ on:
1515
- 'schemas/**'
1616
- 'topologies/**'
1717
- '.github/workflows/deploy_docs.yml'
18-
19-
pull_request:
20-
types: [opened, synchronize]
21-
paths:
22-
- 'docs/**'
23-
- 'mkdocs.yml'
24-
- '*.tf'
25-
- 'modules/**'
26-
- 'schemas/**'
27-
- 'topologies/**'
2818

2919
# Allows you to run this workflow manually from the Actions tab
3020
workflow_dispatch:
@@ -77,7 +67,7 @@ jobs:
7767
terraform-docs --version
7868
7969
- name: Generate Terraform documentation
80-
run: make docs
70+
run: bash scripts/gen-docs.sh
8171

8272
- name: Setup Pages
8373
id: pages
@@ -109,7 +99,7 @@ jobs:
10999

110100
# Deployment job
111101
deploy:
112-
if: github.event_name == 'push' || github.event.pull_request.merged == true
102+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
113103
environment:
114104
name: github-pages
115105
url: ${{ steps.deployment.outputs.page_url }}

.github/workflows/schema-drift.yml

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

.github/workflows/test.yml

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

0 commit comments

Comments
 (0)