ci: add weekly automated codegen workflow#228
Merged
Conversation
12ad2ce to
6dd1bca
Compare
✅MegaLinter analysis: Success
See detailed reports in MegaLinter artifacts MegaLinter is graciously provided by OX Security |
MattDevy
reviewed
Apr 23, 2026
MattDevy
reviewed
Apr 23, 2026
MattDevy
reviewed
Apr 23, 2026
Adds .github/workflows/codegen.yml which runs every Monday at 07:00 UTC (and on workflow_dispatch) to regenerate the auto-generated ES and Cloud API bindings from elastic/elastic-client-generator-js. When the diff is non-empty it opens a PR via peter-evans/create-pull-request. Introduces two package.json scripts, codegen:es and codegen:cloud, which wrap a small orchestrator (scripts/codegen.mjs) that clones the generator, runs its zod / cli-es / cli-cloud targets, and copies the outputs into src/es/apis, src/es/apis/schemas and src/cloud/apis. The orchestrator is a plain Node script with no new runtime or dev dependencies. Refs: #79
Switch from `secrets.CODEGEN_PR_TOKEN || secrets.GITHUB_TOKEN` to a GitHub App token issued via Vault OIDC, used both to clone the (private) elastic/elastic-client-generator-js repo and to open the codegen PR. The backing token policy is registered in elastic/catalog-info under resources/github-token-policies/token-policy-elastic-cli-codegen.yaml and scopes the token to contents:write + pull_requests:write on elastic/cli and elastic/elastic-client-generator-js. The clone step injects the token via a one-shot `git -c http...extraheader` so it never appears on the command line, and the extraheader is unset on the cloned repo immediately afterwards. Workflow-level permissions are tightened to `contents: read` + `id-token: write`; all write surface now lives on the ephemeral token.
48a0e0f to
0b49250
Compare
- Add `codegen:kibana` target invoking `npx tsx cli/kibana/index.ts` and copying `output/kibana/apis/*.ts` into `src/kb/apis/`. The hand-written lazy loader at `src/kb/apis.ts` is intentionally not overwritten. - Run `scripts/build-api-manifest.mjs` after ES codegen and `scripts/build-kb-manifest.mts` after Kibana codegen so the per-endpoint manifests stay in sync with the generated namespace files. - Stop copying `output/es/index.ts` over `src/es/apis.ts` (it became a hand-written lazy loader in #218). - Fix `build-kb-manifest.mts` to load definitions directly from each `src/kb/apis/*.ts` file (the previous `allKbApis` import was dead since the lazy-loader refactor in #266). Manifest regen also picks up the one endpoint that had been missing as a result. - Workflow: append the kibana step, expand diff-detection and `add-paths` to include `src/kb`, refresh the PR body to list the kibana outputs. - CONTRIBUTING: document the new target. Refs: #79
0b49250 to
48c532d
Compare
JoshMock
approved these changes
May 14, 2026
Member
JoshMock
left a comment
There was a problem hiding this comment.
LGTM! Let's give it a try this coming Monday and see what it does.
One other thing we could add (later) is an automatic linter --fix run. Adding that step leads to less noise from codegen PRs, just in case the generator is using inconsistent whitespace or generating extremely long one-liners.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.github/workflows/codegen.yml, a weekly (cron: 0 7 * * 1) +workflow_dispatchworkflow that regenerates the auto-generated ES, Cloud and Kibana API bindings fromelastic/elastic-client-generator-jsand opens a PR viapeter-evans/create-pull-requestwhen the diff is non-empty. Node 24, Actions pinned by SHA + version comment to match the repo's existing style.elastic/ci-gh-actions/fetch-github-token) and reuses it for both the clone and the PR creation — using a non-Actions identity for the PR also means downstream CI (e.g.ci.yml) fires on the weekly PR.codegen:es,codegen:cloud,codegen:kibana) that wrap a small orchestrator atscripts/codegen.mjs. The script clones the generator, installs its deps, runsnpm run zod/npm run cli-es/npm run cli-cloud/npx tsx cli/kibana/index.ts, and copies outputs intosrc/es/apis/,src/es/apis/schemas/,src/cloud/apis/andsrc/kb/apis/. After ES and Kibana it also rebuilds the lazy-loader manifests viascripts/build-api-manifest.mjsandscripts/build-kb-manifest.mts. The hand-writtensrc/es/apis.tsandsrc/kb/apis.tslazy loaders are intentionally not overwritten. No new runtime or dev dependencies — only Node, git and npm from the environment.scripts/build-kb-manifest.mts: it imported the deadallKbApissymbol (removed by the lazy-load refactor in perf(kb): lazy-load KB schemas per namespace/endpoint (#251) #266) and now loads eachsrc/kb/apis/*.tsdirectly. As a side-effect this picks up one endpoint (post-saved-objects-resolve-import-errors) that was missing fromsrc/kb/api-manifest.ts.CODEGEN_GENERATOR_DIRfor reusing a checkout).Refs: #79