Skip to content

Commit 32d6724

Browse files
committed
Add CI checks
1 parent fcd6018 commit 32d6724

3 files changed

Lines changed: 135 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
name: Go and docs
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 10
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v6
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v6
24+
with:
25+
go-version-file: go.mod
26+
cache: true
27+
28+
- name: Set up Terraform
29+
uses: hashicorp/setup-terraform@v4
30+
with:
31+
terraform_version: "1.15.5"
32+
terraform_wrapper: false
33+
34+
- name: Check Go formatting
35+
run: |
36+
files="$(gofmt -l cmd internal)"
37+
if [ -n "$files" ]; then
38+
echo "$files"
39+
exit 1
40+
fi
41+
42+
- name: Check Terraform examples
43+
run: terraform fmt -check -recursive examples
44+
45+
- name: Test
46+
run: go test -short -timeout=2m ./...
47+
48+
- name: Vet
49+
run: go vet ./...
50+
51+
- name: Check generated docs
52+
run: bash scripts/check-docs.sh

docs/teach.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ This repo's provider entrypoint lives in `cmd/terraform-provider-kernel`, so the
207207

208208
`terraform providers schema -json` emits the full provider address `registry.terraform.io/kernel/kernel`. `tfplugindocs` expects the short provider name for rendering stable file names, so the temporary schema key is normalized to `kernel` before docs generation. That is a docs-tool adapter only; it does not change provider registration or Terraform runtime behavior.
209209

210+
### PR12a CI Lesson
211+
212+
CI should run the same boring checks a maintainer can run locally. ELI5: GitHub Actions is not a separate source of truth; it just repeats Go formatting, short Go tests, Go vet, Terraform example formatting, and generated-docs drift checks on every PR.
213+
214+
The eblog-style fast-test boundary is explicit: PR CI runs `go test -short -timeout=2m ./...`; real Kernel acceptance tests stay behind `TF_ACC=1` and `KERNEL_ACC=1`. The docs check builds a temporary provider binary, asks Terraform for the provider schema, regenerates docs with `tfplugindocs`, validates the rendered docs, and then fails if generated docs changed or new generated docs appeared.
215+
216+
The eblog-style Docker boundary is also explicit: this provider repo does not build a Docker image in CI because it ships a Go plugin binary, not a container. The docs check uses the runner's normal Go caches instead of forcing a throwaway cache, keeping the feedback path closer to Dockerfast's least-work/reuse-cache principle.
217+
210218
## Reviewer Learning Targets
211219

212220
- Terraform state represents durable desired config, not temporary Kernel runtime state.

scripts/check-docs.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
workdir="$(mktemp -d "${TMPDIR:-/tmp}/kernel-tfdocs.XXXXXX")"
6+
tfplugindocs_version="${TFPLUGINDOCS_VERSION:-v0.25.0}"
7+
8+
cleanup() {
9+
rm -rf "$workdir"
10+
}
11+
trap cleanup EXIT
12+
13+
command -v terraform >/dev/null || {
14+
echo "terraform is required to check generated docs" >&2
15+
exit 1
16+
}
17+
18+
command -v jq >/dev/null || {
19+
echo "jq is required to normalize the provider schema for tfplugindocs" >&2
20+
exit 1
21+
}
22+
23+
mkdir -p "$workdir/plugins" "$workdir/work"
24+
25+
cd "$root"
26+
go build -o "$workdir/plugins/terraform-provider-kernel" ./cmd/terraform-provider-kernel
27+
28+
cat >"$workdir/work/main.tf" <<'EOF'
29+
terraform {
30+
required_providers {
31+
kernel = {
32+
source = "kernel/kernel"
33+
}
34+
}
35+
}
36+
37+
provider "kernel" {
38+
api_key = "placeholder"
39+
}
40+
EOF
41+
42+
cat >"$workdir/terraformrc" <<EOF
43+
provider_installation {
44+
dev_overrides {
45+
"kernel/kernel" = "$workdir/plugins"
46+
}
47+
48+
direct {}
49+
}
50+
EOF
51+
52+
(
53+
cd "$workdir/work"
54+
TMPDIR="$workdir" TF_CLI_CONFIG_FILE="$workdir/terraformrc" CHECKPOINT_DISABLE=1 \
55+
terraform providers schema -json >"$workdir/schema.json"
56+
)
57+
58+
jq '.provider_schemas.kernel = .provider_schemas["registry.terraform.io/kernel/kernel"] | del(.provider_schemas["registry.terraform.io/kernel/kernel"])' \
59+
"$workdir/schema.json" >"$workdir/schema-tfplugindocs.json"
60+
61+
go run "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@${tfplugindocs_version}" generate \
62+
--provider-name kernel \
63+
--rendered-provider-name Kernel \
64+
--providers-schema "$workdir/schema-tfplugindocs.json"
65+
66+
go run "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@${tfplugindocs_version}" validate \
67+
--provider-name kernel \
68+
--providers-schema "$workdir/schema-tfplugindocs.json"
69+
70+
doc_status="$(git status --porcelain -- docs/index.md docs/resources docs/data-sources)"
71+
if [ -n "$doc_status" ]; then
72+
echo "$doc_status"
73+
git diff -- docs/index.md docs/resources docs/data-sources
74+
exit 1
75+
fi

0 commit comments

Comments
 (0)