Skip to content

Commit 83a2dad

Browse files
Add arca friendly make rule for generating CLI (#3297)
## Changes 1. Users can now run `make generate` from their arca instance to generate the CLI code. 2. It also moves CLI steps like tagging and generating pydabs code to the post_generate step in .codegen.json rather than having it live in Makefile. 3. The generate rule also enforces that universe be checked out to the same version as the openapi sha. ## Why This PR makes it easy to generate CLI both from arca and your local machine in a consistent and reproducible manner. ## Tests No diff when regenerating the CLI on the current commit. Generating with a new openapi spec correctly generates different files like the JSON schema, CLI files or PyDABs files.
1 parent 123770d commit 83a2dad

File tree

3 files changed

+50
-10
lines changed

3 files changed

+50
-10
lines changed

.codegen.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
"go"
1515
],
1616
"post_generate": [
17-
"go test -timeout 240s -run TestConsistentDatabricksSdkVersion github.com/databricks/cli/internal/build",
18-
"make schema",
19-
"make generate-validation"
17+
"./tools/post-generate.sh"
2018
]
2119
}
2220
}

Makefile

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,27 @@ integration-short:
101101
generate-validation:
102102
go run ./bundle/internal/validation/.
103103

104+
# Rule to generate the CLI from a new version of the OpenAPI spec.
105+
# I recommend running this rule from Arca because of faster build times
106+
# because of better caching and beefier machines, but it should also work
107+
# fine from your local mac.
108+
#
109+
# By default, this rule will use the universe directory in your home
110+
# directory. You can override this by setting the UNIVERSE_DIR
111+
# environment variable.
112+
#
113+
# Example:
114+
# UNIVERSE_DIR=/Users/shreyas.goenka/universe make generate
115+
UNIVERSE_DIR ?= $(HOME)/universe
116+
GENKIT_BINARY := $(UNIVERSE_DIR)/bazel-bin/openapi/genkit/genkit_/genkit
117+
104118
generate:
105-
genkit update-sdk
106-
[ ! -f tagging.py ] || mv tagging.py internal/genkit/tagging.py
107-
# tagging.yml is automatically synced by update-sdk command and contains a reference to tagging.py in root
108-
# since we move tagging.py to different folder, we need to update this reference here as well
109-
[ ! -f .github/workflows/tagging.yml ] || sed -i '' 's/python tagging.py/python internal\/genkit\/tagging.py/g' .github/workflows/tagging.yml
110-
[ ! -f .github/workflows/next-changelog.yml ] || rm .github/workflows/next-changelog.yml
111-
pushd experimental/python && make codegen
119+
@echo "Checking out universe at SHA: $$(cat .codegen/_openapi_sha)"
120+
cd $(UNIVERSE_DIR) && git checkout $$(cat $(PWD)/.codegen/_openapi_sha)
121+
@echo "Building genkit..."
122+
cd $(UNIVERSE_DIR) && bazel build //openapi/genkit
123+
@echo "Generating CLI code..."
124+
$(GENKIT_BINARY) update-sdk
125+
112126

113127
.PHONY: lint lintfull tidy lintcheck fmt fmtfull test cover showcover build snapshot schema integration integration-short acc-cover acc-showcover docs ws links checks test-update test-update-aws test-update-all generate-validation

tools/post-generate.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Ensure the SDK version is consistent with the OpenAPI SHA the CLI is generated from.
2+
go test -timeout 240s -run TestConsistentDatabricksSdkVersion github.com/databricks/cli/internal/build
3+
4+
# Generate the bundle JSON schema.
5+
make schema
6+
7+
# Generate bundle validation code for enuma and required fields.
8+
make generate-validation
9+
10+
# Remove the next-changelog.yml workflow.
11+
rm .github/workflows/next-changelog.yml
12+
13+
# Move the tagging.py file to the internal/genkit/tagging.py file. We do this to avoid
14+
# cluttering the root directory.
15+
mv tagging.py internal/genkit/tagging.py
16+
17+
# Update the tagging.yml workflow to use the new tagging.py file location.
18+
if [[ "$(uname)" == "Darwin" ]]; then
19+
# macOS (BSD sed) requires empty string after -i
20+
sed -i '' 's|python tagging.py|python internal/genkit/tagging.py|g' .github/workflows/tagging.yml
21+
else
22+
# Linux (GNU sed)
23+
sed -i 's|python tagging.py|python internal/genkit/tagging.py|g' .github/workflows/tagging.yml
24+
fi
25+
./tools/yamlfmt .github/workflows/tagging.yml
26+
27+
# Generate PyDABs code.
28+
make -C experimental/python codegen

0 commit comments

Comments
 (0)