Skip to content

Commit 916a6d3

Browse files
authored
Add a GH test to verify the generated code is clean (#206)
* Add --no-update-api-spec to neptune_api_codegen.cli * Add a GH test to verify the generated code is clean * Install pre-commit hooks in the install pre-commit phase * --help update
1 parent 883f8f4 commit 916a6d3

File tree

3 files changed

+73
-15
lines changed

3 files changed

+73
-15
lines changed

.github/workflows/tests-e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717
- 'tests/e2e/**'
1818
- 'dev_requirements.txt'
1919
- 'pyproject.toml'
20-
- '.github/workflows/tests-e2e.yml'
20+
- '.github/**'
2121

2222
jobs:
2323
test:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Verify generated neptune_api code is clean
2+
3+
permissions:
4+
checks: write
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches:
10+
- main
11+
- dev/.*
12+
pull_request:
13+
paths:
14+
- 'src/**'
15+
- 'tests/e2e/**'
16+
- 'dev_requirements.txt'
17+
- 'pyproject.toml'
18+
- '.github/**'
19+
20+
jobs:
21+
test:
22+
runs-on: tools-gha-runners
23+
timeout-minutes: 5
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Install Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: "3.10"
32+
33+
- name: Install pre-commit
34+
run: |
35+
python -m pip install pre-commit &&
36+
pre-commit install-hooks
37+
38+
- name: Run codegen and verify no changes
39+
run: |
40+
cd src &&
41+
python -m neptune_api_codegen.cli --no-update-api-spec --update &&
42+
( pre-commit run --all-files >/dev/null || true ; ) &&
43+
pre-commit run --all-files &&
44+
[ -z "$(git status --porcelain)" ] &&
45+
echo "✅ Repository is clean after regenerating neptune_api code"

src/neptune_api_codegen/cli.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ def build_parser() -> argparse.ArgumentParser:
4848
help="Path to the neptune backend repository. If not specified, it will be auto-detected.",
4949
default=None,
5050
)
51+
parser.add_argument(
52+
"--no-update-api-spec",
53+
action="store_true",
54+
help="Do not fetch new API spec files (swagger, proto) from Neptune repo.",
55+
default=False,
56+
)
5157
parser.add_argument(
5258
"--update",
5359
action="store_true",
@@ -140,14 +146,17 @@ def main() -> None:
140146
# Project root
141147
project_root = find_project_root()
142148

143-
# Neptune repo path
144-
if args.neptune_repo_path is None:
145-
args.neptune_repo_path = find_neptune_repo(project_root)
146-
elif not is_neptune_repo(args.neptune_repo_path):
147-
raise RuntimeError(
148-
f"The specified neptune repo path {args.neptune_repo_path} is not a valid neptune backend repository."
149-
)
150-
print_err(f"Using neptune backend repository at: {rel(args.neptune_repo_path)}")
149+
update_api_spec = not args.no_update_api_spec
150+
151+
if update_api_spec:
152+
# Neptune repo path
153+
if args.neptune_repo_path is None:
154+
args.neptune_repo_path = find_neptune_repo(project_root)
155+
elif not is_neptune_repo(args.neptune_repo_path):
156+
raise RuntimeError(
157+
f"The specified neptune repo path {args.neptune_repo_path} is not a valid neptune backend repository."
158+
)
159+
print_err(f"Using neptune backend repository at: {rel(args.neptune_repo_path)}")
151160

152161
# Target and backup dirs
153162
rand_bit = int(random() * 1e4)
@@ -174,12 +183,16 @@ def main() -> None:
174183
apispec_dir.mkdir()
175184
generated_py_dir.mkdir()
176185

177-
print_err(f"Copying proto directories and swagger files to: {rel(apispec_dir)}")
178-
copy_swagger_files(
179-
neptune_repo_path=args.neptune_repo_path,
180-
target_dir=apispec_dir,
181-
verbose=args.verbose,
182-
)
186+
if update_api_spec:
187+
print_err(f"Copying proto directories and swagger files to: {rel(apispec_dir)}")
188+
copy_swagger_files(
189+
neptune_repo_path=args.neptune_repo_path,
190+
target_dir=apispec_dir,
191+
verbose=args.verbose,
192+
)
193+
else:
194+
print_err(f"Using proto directories and swagger files from: {rel(target_apispec)}")
195+
shutil.copytree(target_apispec, apispec_dir, dirs_exist_ok=True)
183196

184197
print_err(f"Generating OpenAPI clients in: {rel(generated_py_dir)}")
185198
run_in_docker(

0 commit comments

Comments
 (0)