feat: automate frontend API regeneration during live development - #1291
feat: automate frontend API regeneration during live development#1291prakharsingh-74 wants to merge 5 commits into
Conversation
Signed-off-by: prakharsingh-74 <prakharsingh7014@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
cc: @andyatmiami |
|
@andreyvelich sir, can you review this PR if you're free. |
christian-heusel
left a comment
There was a problem hiding this comment.
Thanks a lot for your contribution, I have left a few review comments below 🤗
A few general notes:
- Did you use AI in any capacity while creating this contribution? I see that your commit does not carry a
Assisted-By: <...>tag, so I wanted to make sure that you're aware of the Kubeflow AI Policy. 🤗 🤖 - Please do not ping external maintainers for your PR, it's okay to make a bit of noise if a PR goes without review, however for example Andrey does not know anything about the codebase here and will not be available to review your changes.
- This is more of a preference thing, but if you rebase your changes against
notebooks-v2instead of merging this keeps the history more clean.
| "build:clean": "rimraf ./dist", | ||
| "build:prod": "webpack --config ./config/webpack.prod.js", | ||
| "generate:api": "./scripts/generate-api.sh && npm run prettier", | ||
| "generate:api": "bash ./scripts/generate-api.sh && npm run prettier", |
There was a problem hiding this comment.
Why do we need to explicitly execute this script with bash? 🤔
The script already has this as shebang, so my intuition would be that this can be dropped 🤔
| if [[ "$SWAGGER_JSON_PATH" =~ ^https?:// ]]; then | ||
| node -e "fetch('$SWAGGER_JSON_PATH').then(r => { if (!r.ok) throw new Error('status ' + r.status); return r.text(); }).then(t => process.stdout.write(t)).catch(e => { console.error(e); process.exit(1); })" > "$TMP_SWAGGER" |
There was a problem hiding this comment.
IMO this is not the right approach to the issue we're fixing, why are we fetching this file from a remote endpoint instead of just using the one on disk or regenerating it in a temporary directory? 🤔
| HASH_FILE="./scripts/swagger.version" | ||
| SWAGGER_COMMIT_HASH=$(cat "$HASH_FILE") | ||
| SWAGGER_JSON_PATH="../backend/openapi/swagger.json" | ||
| SWAGGER_COMMIT_HASH=$(tr -d '\r\n' < "$HASH_FILE") |
There was a problem hiding this comment.
The line ending here is not guaranteed to be \r\n, on linux this will just be \n. Probably we should also fix this in .gitattributes so it is predictable accross both os types.
closes: #857
Description
Currently, the
swagger.versionGit-hash mechanism prevents the core benefit of Tilt—live iterative development across backend and frontend components—from working when backend API changes are introduced. Uncommitted backend changes are not captured by the Git history, causing local API client generation (npm run generate:api) to fail or fetch outdated schemas.Automatic Generation in Tilt:
backend-swaggerlocal_resourcein theTiltfilethat watches backend Go files and automatically runsmake swagon the host to update the localopenapi/swagger.json.frontend-api-generatelocal_resourcein theTiltfilethat watchesopenapi/swagger.jsonand runsnpm run generate:apion the host.Conditional Local Swagger Generation:
generate-api.shto check forUSE_LOCAL_SWAGGER=trueorDEV_ENV=tilt. When active, it directly reads the localswagger.jsonpath or fetches it from a running container URL (using Node.js's built-infetchto keep container dependencies lean) rather than querying git history.generate:apinpm script command withbashfor native Windows execution compatibility.Documentation:
DEVELOPMENT_GUIDE.md.How to Verify
Verify Local Generation on Host:
$env:USE_LOCAL_SWAGGER="true"; npm run generate:api(Windows PowerShell) orUSE_LOCAL_SWAGGER=true npm run generate:api(macOS/Linux/Git Bash) insideworkspaces/frontend. Verify it generates types using the localswagger.json.Verify Git-Based Generation (CI/Production Mode):
npm run generate:apiwithout setting the environment variable. Verify it falls back to the original git-hash-based generation.Verify Tilt E2E Loop:
make tilt-upindeveloping/.make swaglocally.generate-api.shto update the TypeScript types insrc/generated/.