Skip to content

Commit d5585c1

Browse files
committed
Fix CI branch and add fast checks
1 parent a7f9399 commit d5585c1

4 files changed

Lines changed: 99 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
pull_request:
55
push:
66
branches:
7-
- main
7+
- provider-repo-scaffold
88

99
permissions:
1010
contents: read
@@ -42,6 +42,12 @@ jobs:
4242
- name: Check Terraform examples
4343
run: terraform fmt -check -recursive examples
4444

45+
- name: Check Markdown links
46+
run: bash scripts/check-markdown-links.sh
47+
48+
- name: Validate Terraform examples
49+
run: bash scripts/check-examples.sh
50+
4551
- name: Test
4652
run: go test -short -timeout=2m ./...
4753

docs/release.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Use this checklist before publishing a Kernel Terraform provider version.
66

77
- Work from a clean checkout of the repository's canonical post-merge branch after the PR stack is merged. The current default branch is `provider-repo-scaffold`; confirm with `gh repo view --json defaultBranchRef` before tagging.
88
- Run `bash scripts/check-docs.sh`.
9+
- Run `bash scripts/check-markdown-links.sh`.
10+
- Run `bash scripts/check-examples.sh`.
911
- Run `terraform fmt -check -recursive examples`.
1012
- Run `go test -short -timeout=2m ./...`.
1113
- Run `go vet ./...`.

scripts/check-examples.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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-tfexamples.XXXXXX")"
6+
7+
cleanup() {
8+
rm -rf "$workdir"
9+
}
10+
trap cleanup EXIT
11+
12+
command -v terraform >/dev/null || {
13+
echo "terraform is required to validate examples" >&2
14+
exit 1
15+
}
16+
17+
mkdir -p "$workdir/plugins"
18+
19+
cd "$root"
20+
go build -o "$workdir/plugins/terraform-provider-kernel" ./cmd/terraform-provider-kernel
21+
22+
cat >"$workdir/terraformrc" <<EOF
23+
provider_installation {
24+
dev_overrides {
25+
"kernel/kernel" = "$workdir/plugins"
26+
}
27+
28+
direct {}
29+
}
30+
EOF
31+
32+
while IFS= read -r example; do
33+
echo "validating $example"
34+
(
35+
cd "$example"
36+
TF_CLI_CONFIG_FILE="$workdir/terraformrc" CHECKPOINT_DISABLE=1 \
37+
terraform validate -no-color
38+
)
39+
done < <(find examples -mindepth 1 -maxdepth 1 -type d -exec test -f '{}/main.tf' ';' -print | sort)

scripts/check-markdown-links.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
6+
cd "$root"
7+
8+
command -v python3 >/dev/null || {
9+
echo "python3 is required to check Markdown links" >&2
10+
exit 1
11+
}
12+
13+
python3 - <<'PY'
14+
import pathlib
15+
import re
16+
import subprocess
17+
import sys
18+
import urllib.parse
19+
20+
root = pathlib.Path.cwd()
21+
tracked_markdown = subprocess.check_output(["git", "ls-files", "*.md"], text=True)
22+
files = [pathlib.Path(p) for p in tracked_markdown.splitlines()]
23+
link_re = re.compile(r"(?<!\\!)\[[^\]]+\]\(([^)]+)\)")
24+
errors: list[str] = []
25+
26+
for path in files:
27+
text = path.read_text(encoding="utf-8")
28+
for match in link_re.finditer(text):
29+
target = match.group(1).strip()
30+
if not target or target.startswith(("#", "http://", "https://", "mailto:")):
31+
continue
32+
33+
target = target.split("#", 1)[0]
34+
target = urllib.parse.unquote(target)
35+
if not target:
36+
continue
37+
38+
resolved = (root / path.parent / target).resolve()
39+
try:
40+
resolved.relative_to(root)
41+
except ValueError:
42+
errors.append(f"{path}: link leaves repository: {target}")
43+
continue
44+
45+
if not resolved.exists():
46+
errors.append(f"{path}: missing link target: {target}")
47+
48+
if errors:
49+
print("\n".join(errors), file=sys.stderr)
50+
sys.exit(1)
51+
PY

0 commit comments

Comments
 (0)