Skip to content

Commit b4cccd5

Browse files
committed
Add CI checks
1 parent 7a7c362 commit b4cccd5

2 files changed

Lines changed: 127 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

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)