Skip to content

Commit ba60b19

Browse files
Add CI checks for stale generated docs and proto files (#9199)
* Add CI checks for stale generated docs and proto files * Self review * Review * Fix * Fix * Fix * Fix * nits
1 parent 3227c82 commit ba60b19

7 files changed

Lines changed: 91 additions & 45 deletions

File tree

.github/workflows/docs-check.yml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,33 @@ on:
44
pull_request:
55
paths:
66
- ".github/workflows/docs-check.yml"
7-
- "docs/**"
87
- "cli/**"
8+
- "docs/**"
9+
- "runtime/parser/schema/**"
910
env:
1011
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
1112
NETLIFY_SITE_ID: 23baf08e-2d3e-44db-8bd4-938e54467a29
1213

1314
jobs:
15+
check:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: 1.25
25+
26+
- name: Generate docs
27+
run: make docs.generate
28+
29+
- name: Check for uncommitted changes
30+
run: |
31+
git diff --exit-code || (echo "Generated docs are out of date. Please run 'make docs.generate' locally and commit the changes." && exit 1)
32+
test -z "$(git status --porcelain)" || (echo "Generated docs are out of date. Please run 'make docs.generate' locally and commit the changes." && git status --porcelain && exit 1)
33+
1434
build:
1535
runs-on: ubuntu-latest
1636
steps:
@@ -23,20 +43,6 @@ jobs:
2343
node-version-file: '.nvmrc'
2444
cache: 'npm'
2545

26-
# - name: Filter modified codepaths
27-
# uses: dorny/paths-filter@v3
28-
# id: filter
29-
# with:
30-
# filters: |
31-
# cli:
32-
# - "cli/**"
33-
34-
# - name: Check if new files were created
35-
# if: ${{ steps.filter.outputs.cli == 'true' }}
36-
# run: |
37-
# make docs.generate
38-
# git diff --exit-code || (echo "New files were created, please run 'make docs.generate' locally and commit the changes" && exit 0)
39-
4046
- name: Build docs
4147
run: |-
4248
npm ci -w docs

.github/workflows/proto-check.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ name: Check .proto files
22
on:
33
pull_request:
44
paths:
5+
- ".github/workflows/proto-check.yml"
56
- "proto/**"
7+
- "scripts/convert-openapi-v2-to-v3/**"
8+
- "web-admin/src/client/**"
9+
- "web-common/src/proto/**"
10+
- "web-common/src/runtime-client/**"
611
jobs:
712
check:
813
runs-on: ubuntu-latest
@@ -12,3 +17,33 @@ jobs:
1217
- uses: bufbuild/buf-lint-action@v1
1318
with:
1419
input: "proto"
20+
21+
generate:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Go
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version: 1.25
31+
32+
- name: Set up buf
33+
uses: bufbuild/buf-setup-action@v1
34+
35+
- name: Set up NodeJS
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version-file: '.nvmrc'
39+
cache: 'npm'
40+
41+
- name: Generate proto
42+
run: make proto.generate
43+
env:
44+
HUSKY: 0
45+
46+
- name: Check for uncommitted changes
47+
run: |
48+
git diff --exit-code || (echo "Generated proto files are out of date. Please run 'make proto.generate' locally and commit the changes." && exit 1)
49+
test -z "$(git status --porcelain)" || (echo "Generated proto files are out of date. Please run 'make proto.generate' locally and commit the changes." && git status --porcelain && exit 1)

Makefile

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,8 @@ cli-only:
1010
cli: cli.prepare
1111
go build -o rill cli/main.go
1212

13-
KEEP_DIRS := rill-openrtb-prog-ads rill-github-analytics rill-cost-monitoring
14-
1513
.PHONY: cli.prepare
16-
cli.prepare:
17-
@set -e; \
18-
rm -rf runtime/pkg/examples/embed/dist || true; \
19-
mkdir -p runtime/pkg/examples/embed/dist; \
20-
# Create a temp dir (GNU mktemp first, then BSD/macOS fallback)
21-
TMP_CLONE_DIR=$$(mktemp -d 2>/dev/null || mktemp -d -t rill-examples); \
22-
trap 'rm -rf "$$TMP_CLONE_DIR"' EXIT; \
23-
git clone --quiet --depth=1 https://github.com/rilldata/rill-examples.git "$$TMP_CLONE_DIR"; \
24-
for d in $(KEEP_DIRS); do \
25-
cp -R "$$TMP_CLONE_DIR/$$d" runtime/pkg/examples/embed/dist/; \
26-
done
14+
cli.prepare: runtime.examples.embed
2715
npm install
2816
npm run build
2917
rm -rf cli/pkg/web/embed/dist || true
@@ -42,13 +30,15 @@ coverage.go:
4230
go tool cover -func coverage/go.out
4331

4432
.PHONY: docs.generate
45-
docs.generate:
33+
docs.generate: runtime.examples.embed
4634
# Temporarily replaces ~/.rill/config.yaml to avoid including user-defined defaults in generated docs.
47-
# Sets version to the latest tag to simulate a production build, where certain commands are hidden.
35+
#
36+
# Sets main.Version to a fixed tag to simulate a production build, where certain commands are hidden.
37+
# Not using scripts/versiontag.sh since the actual version should not be emitted to the generated files as it would go stale on the next release.
4838
rm -rf docs/docs/reference/cli/*.md docs/docs/reference/project-files/*.md
4939
if [ -f ~/.rill/config.yaml ]; then mv ~/.rill/config.yaml ~/.rill/config.yaml.tmp; fi;
50-
go run -ldflags="-X main.Version=$(shell scripts/versiontag.sh)" ./cli docs generate-cli docs/docs/reference/cli/
51-
go run -ldflags="-X main.Version=$(shell scripts/versiontag.sh)" ./cli docs generate-project docs/docs/reference/project-files/
40+
RILL_DOCS_GENERATE=true go run -ldflags="-X main.Version=1.0.0" ./cli docs generate-cli docs/docs/reference/cli/
41+
RILL_DOCS_GENERATE=true go run -ldflags="-X main.Version=1.0.0" ./cli docs generate-project docs/docs/reference/project-files/
5242
if [ -f ~/.rill/config.yaml.tmp ]; then mv ~/.rill/config.yaml.tmp ~/.rill/config.yaml; fi;
5343

5444
.PHONY: proto.generate
@@ -59,12 +49,25 @@ proto.generate:
5949
cd proto && buf generate --template buf.gen.runtime.yaml --path rill/runtime
6050
cd proto && buf generate --template buf.gen.local.yaml --path rill/local
6151
cd proto && buf generate --template buf.gen.ui.yaml
62-
go run -ldflags="-X main.Version=$(shell scripts/versiontag.sh)" \
63-
scripts/convert-openapi-v2-to-v3/convert.go --force \
52+
go run scripts/convert-openapi-v2-to-v3/convert.go --force \
6453
proto/gen/rill/admin/v1/admin.swagger.yaml proto/gen/rill/admin/v1/openapi.yaml
65-
go run -ldflags="-X main.Version=$(shell scripts/versiontag.sh)" \
66-
scripts/convert-openapi-v2-to-v3/convert.go --force --public-only \
54+
go run scripts/convert-openapi-v2-to-v3/convert.go --force --public-only \
6755
proto/gen/rill/admin/v1/admin.swagger.yaml proto/gen/rill/admin/v1/public.openapi.yaml
56+
npm install
6857
npm run generate:runtime-client -w web-common
6958
npm run generate:client -w web-admin
70-
59+
60+
KEEP_EXAMPLES := rill-openrtb-prog-ads rill-github-analytics rill-cost-monitoring
61+
62+
.PHONY: runtime.examples.embed
63+
runtime.examples.embed:
64+
@set -e; \
65+
rm -rf runtime/pkg/examples/embed/dist || true; \
66+
mkdir -p runtime/pkg/examples/embed/dist; \
67+
# Create a temp dir (GNU mktemp first, then BSD/macOS fallback)
68+
TMP_CLONE_DIR=$$(mktemp -d 2>/dev/null || mktemp -d -t rill-examples); \
69+
trap 'rm -rf "$$TMP_CLONE_DIR"' EXIT; \
70+
git clone --quiet --depth=1 https://github.com/rilldata/rill-examples.git "$$TMP_CLONE_DIR"; \
71+
for d in $(KEEP_EXAMPLES); do \
72+
cp -R "$$TMP_CLONE_DIR/$$d" runtime/pkg/examples/embed/dist/; \
73+
done

cli/pkg/cmdutil/helper.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,12 @@ func hashStr(ss ...string) string {
694694
}
695695

696696
// isTerminal reports whether both stdin and stdout are connected to an interactive terminal.
697+
// It can be overridden by setting RILL_DOCS_GENERATE=true (used in CI for docs generation).
697698
func isTerminal() bool {
699+
if os.Getenv("RILL_DOCS_GENERATE") == "true" {
700+
// Used for generating docs with `make docs.generate`.
701+
// This ensures --interactive defaults to "true", which makes the generated docs appear the way the CLI help menus appear to a real user (e.g. strips agent instructions).
702+
return true
703+
}
698704
return term.IsTerminal(int(os.Stdin.Fd())) && term.IsTerminal(int(os.Stdout.Fd()))
699705
}

proto/gen/rill/admin/v1/openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,7 @@ externalDocs:
23212321
info:
23222322
description: Rill Admin API enables programmatic management of Rill Cloud resources, including organizations, projects, and user access. It provides endpoints for creating, updating, and deleting these resources, as well as managing authentication and permissions.
23232323
title: Rill Admin API
2324-
version: v0.84.4
2324+
version: 1.0.0
23252325
openapi: 3.0.3
23262326
paths:
23272327
/v1/ai/complete:

proto/gen/rill/admin/v1/public.openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,7 @@ externalDocs:
23212321
info:
23222322
description: Rill Admin API enables programmatic management of Rill Cloud resources, including organizations, projects, and user access. It provides endpoints for creating, updating, and deleting these resources, as well as managing authentication and permissions.
23232323
title: Rill Admin API
2324-
version: v0.84.4
2324+
version: 1.0.0
23252325
openapi: 3.0.3
23262326
paths:
23272327
/v1/ai/complete: {}

scripts/convert-openapi-v2-to-v3/convert.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"gopkg.in/yaml.v3"
1515
)
1616

17-
var Version string
18-
1917
func main() {
2018
var force bool
2119
var publicOnly bool
@@ -100,10 +98,8 @@ func convertOpenAPIDocs(input, output string, force, publicOnly bool) error {
10098
// Prune to only keep public visibility
10199
prunePublicOnly(convertedDocs, publicOnly)
102100

103-
// Inject version if set
104-
if Version != "" {
105-
convertedDocs.Info.Version = Version
106-
}
101+
// Use a fixed version for the OpenAPI spec to avoid patch releases causing changes to the generated document
102+
convertedDocs.Info.Version = "1.0.0"
107103

108104
if err = os.MkdirAll(filepath.Dir(output), 0o755); err != nil {
109105
return fmt.Errorf("unable to create output directory: %w", err)

0 commit comments

Comments
 (0)