Skip to content

[No QA] Migrate GitHub Action bundling from ncc to esbuild - #95257

Merged
roryabraham merged 46 commits into
mainfrom
rory-gh-actions-esbuild
Aug 21, 2026
Merged

roryabraham merged 46 commits into
mainfrom
rory-gh-actions-esbuild

Conversation

@roryabraham

@roryabraham roryabraham commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

This PR replaces @vercel/ncc with esbuild for bundling our JavaScript GitHub Actions, and switches the compiled bundles from CommonJS to native ESM.

Why

  • esbuild is ~18x faster than ncc (see benchmarks below).
  • esbuild is more actively maintained.
  • it lets us drop the two custom patches we carry for ncc, rather than adding a third.
  • switching to ESM output lets us upgrade @actions/core/@actions/github past their CJS-only majors (both are ESM-only as of the versions used here), and fixes a real import.meta.url crash in checkSVGCompression (its svgo/css-tree dependency is pure ESM and can't be safely bundled into CJS).

What changed:

Bundler swap

  • Replaced .github/scripts/buildActions.sh with .github/scripts/buildActions.ts, run directly via bun. The script ends up much simpler — no manual background-PID juggling to get parallelism.
  • Fully removed @vercel/ncc: uninstalled the dependency, deleted patches/@vercel+ncc/ (both patches plus details.md), removed it from knip.json, and scrubbed the remaining references in verifyActions.sh and the workflows README.
  • Added an esbuild devDependency plus an overrides pin, and a lefthook gh-actions-build pre-commit hook — now that the build takes under a second, it's cheap enough to run on every commit that touches .github/**/*.ts.
  • buildActions.ts builds 24 actions. buildActions.sh listed only 23 — it was missing generateHelpPreviewComment, so that action's committed bundle was never being rebuilt.
  • Replaced googleapis with @googleapis/androidpublisher in the two Android actions. googleapis carries every Google API (212 MB unpacked) and is CJS, so esbuild can't tree-shake it; those two actions need only google.auth.GoogleAuth and google.androidpublisher v3. The per-API package is 2.5 MB unpacked and its auth export is the same AuthPlus instance, so the call sites are otherwise unchanged. checkAndroidStatus drops from 771,910 lines to 52,874 (-93%) and getAndroidRolloutPercentage from 764,891 to 45,855 (-94%) — both were large enough to break GitHub's diff viewer.

ESM output

  • Switched esbuild's output format from cjs to esm, scoped via a new .github/actions/javascript/package.json ({"type": "module"}) so it applies to the bundles and nothing else.
  • Added a createRequire banner so bundled CJS dependencies (googleapis, lodash, semver, @babel/parser, @babel/traverse — none of which ship an ESM build) can still call require() on Node builtins.
  • Marked svgo external (not bundled) for checkSVGCompression only, so Node's own ESM resolution gives its css-tree dependency a real import.meta.url instead of esbuild's CJS-mode stub — this was crashing with ERR_INVALID_ARG_VALUE before.
  • Converted all 18 action-level if (require.main === module) entry guards (plus scripts/createOrUpdateDeployChecklist.ts) to the ESM idiom (import.meta.url === pathToFileURL(process.argv.at(1) ?? '').href).
  • Added a no-restricted-globals ESLint rule over .github/actions/** and .github/libs/** — the sources esbuild bundles — banning module, __dirname and __filename. esbuild leaves these identifiers untouched instead of failing, so a CJS idiom in a bundled source builds fine and then throws ReferenceError: module is not defined in ES module scope when the action runs in CI. proposalPoliceComment landed on main after this branch's original guard conversion and hit exactly this — its bundle threw on load, so the action would have been dead in CI. The rule is there to catch the next one at lint time. .github/scripts/ is excluded — it runs directly under Bun, which does provide these.
  • Fixed a bug this surfaced: checkSVGCompression.ts/scripts/compressSvg.ts and bumpVersion.ts/scripts/bumpVersion.ts each had their own if (require.main === module) guard, but esbuild flattens bundled files into one shared module scope, so both guards fired in each other's bundles — for bumpVersion this silently executed scripts/bumpVersion.ts's real version-bump logic as a side effect of building/testing checkSVGCompression, and vice versa (confirmed via isolated repro, unrelated to CJS vs ESM). Fixed by splitting both into guard-free libraries (imported by their action + tests) plus new, never-imported scripts/compressSvg-cli.ts / scripts/bumpVersion-cli.ts entry points for CLI use. This pattern is now documented in the workflows README.

Dependency upgrades

  • @actions/core 1.10.0 → 3.0.1, @actions/github 5.1.1 → 9.1.1, and the @octokit/* chain aligned with what @actions/github v9 bundles: core ^7, plugin-paginate-rest ^14, plugin-throttling ^11, request-error ^7, webhooks-types ^7.6.1, plus plugin-rest-endpoint-methods ^17 now declared explicitly.
  • No breaking changes to getInput/setOutput/setFailed/getOctokit/context. The API breakages were:
    • @octokit/plugin-throttling's onAbuseLimit renamed to onSecondaryRateLimit, with retryCount moving from options.request.retryCount to its own handler argument (GithubUtils.ts, scripts/aggregateGitHubDataFromUpwork.ts).
    • @octokit/plugin-rest-endpoint-methods no longer exports RestEndpointMethods directly, only Api (which wraps it as {rest: RestEndpointMethods}), so it's derived as Api['rest'] (GithubUtils.ts, isTeamMember.ts).
  • Stopped importing @octokit/openapi-types directly in GithubUtils.ts/DeployChecklistUtils.ts. It's only a transitive dependency, so the bare specifier resolved to whatever npm hoisted (v28) rather than the copy the endpoint methods were generated against (v27) — which made otherwise identical types mutually unassignable (issue.id is number in one and number | bigint in the other). These aliases now derive from RestEndpointMethodTypes, which always matches the installed endpoint methods.

Test adaptations for @octokit v7
These are the reason the dependency upgrade couldn't just be a version bump. All of these tests pass on main and broke silently on the upgrade — they kept passing type checks while firing real HTTP requests at api.github.com.

  • @octokit/plugin-rest-endpoint-methods v17 exposes each REST namespace (octokit.rest.issues, .pulls, .actions, .teams, .repos) as a Proxy that creates endpoint methods on first access. Bun's jest.spyOn silently no-ops on a Proxy-backed property — it returns a mock, but the property keeps its original value — so mocks never intercepted. That showed up as HttpError: Bad credentials (401) in several files, and as an outright hang in DeployChecklistUtils once the real retry backoff started running. Added tests/utils/materializeOctokitNamespace.ts to copy a namespace into a plain object first, and applied it at each spy site.
  • @octokit/request v10 reads a response body with text() and parses it itself rather than calling json(), so postOrReplaceComment's stubbed Response returned no comments. It now stubs text().

Also in here

  • newComponentCategory.ts derives WebhookPayload from context.payload: @actions/github v9 dropped the ./lib/interfaces deep import path from its exports map, so the type can't be imported directly any more.

Benchmarks

Measured back to back on the same machine today, so the two columns are directly comparable (main at 0932767 for the ncc baseline, this branch for esbuild):

Metric ncc (main) esbuild (this PR) Delta
Median wall time (5 runs) 13.34s 0.45s -96.6% (~30x faster)
Best run (min) 13.13s 0.31s -97.6%
Worst run (max) 14.20s 0.56s -96.1%
Actions built 23 24 +1 (generateHelpPreviewComment)
Total index.js size 83.57 MB 29.88 MB -64.2%
Largest single bundle 771,910 lines 69,843 lines -91.0%
Machine macOS arm64, Apple M5 Max, Node 26.5.0 (same)

Most of the size and a good chunk of the time come from dropping the googleapis mega-package rather than from the bundler swap itself. On esbuild with googleapis still in place the totals were 83.13 MB and 0.75s median, so the bundler change alone is roughly size-neutral against ncc; the per-API import is what makes it smaller.

Two notes on reading this table honestly: esbuild builds one more action than ncc did, which very slightly flatters it; and rebuilding with ncc on main leaves isDeployChecklistLocked/index.js and proposalPoliceComment/index.js dirty, i.e. those two committed bundles are already stale on main today. Neither affects the conclusion.

Fixed Issues

$
PROPOSAL:

Tests

Requires Node 26.5.0 / npm 11.17.0 (per engines).

  1. Run npm install in a clean checkout.
  2. Run npm run gh-actions-build and confirm all 24 actions build without error in well under two seconds.
  3. Run ./.github/scripts/verifyActions.sh and confirm it reports "Github Actions are up to date!".
  4. Confirm every directory under .github/actions/javascript/ contains exactly one index.js and no extra chunk files:
    find .github/actions/javascript -mindepth 2 -name '*.js' ! -name index.js   # expect no output
  5. Confirm no bundle throws at module scope (this is the failure mode a stray CJS idiom causes — the action dies before run() is ever reached):
    for d in .github/actions/javascript/*/; do
        out=$(env -u GITHUB_TOKEN -u SEMVER_LEVEL node "$d/index.js" 2>&1)
        echo "$out" | grep -qE 'ReferenceError|SyntaxError|ERR_MODULE_NOT_FOUND|ERR_INVALID_ARG_VALUE' && echo "FAIL: $d"
    done
    Expect no FAIL: lines. Each action should instead fail on a missing input, which means it loaded and ran.
  6. Confirm node .github/actions/javascript/checkSVGCompression/index.js with no GITHUB_TOKEN set fails with Error: Input required and not supplied: GITHUB_TOKEN (not a crash).
  7. Confirm node .github/actions/javascript/bumpVersion/index.js with no SEMVER_LEVEL set fails with Error: Input required and not supplied: SEMVER_LEVEL, and that git status shows no unexpected file changes afterwards (i.e. it didn't actually bump the version as a side effect).
  8. Run npm run compress-svg and confirm it runs to completion and reports compression results (rather than erroring or silently doing nothing).
  9. Run npm run test:bun and confirm it passes. The tests/tooling/ portion is what covers .github/ and scripts/; note these files depend on per-file isolation, so run them via that script (--parallel) rather than pointing bun test at the directory yourself.
  10. Run npm run typecheck and npx eslint .github/ scripts/ tests/tooling/ and confirm both are clean.
  11. Confirm the new ESLint guard works: append if (require.main === module) { run(); } to any file under .github/actions/javascript/, run npx eslint on it, and confirm it reports a no-restricted-globals error pointing at the ESM idiom. Revert afterwards.

Note that several of these bundled actions are exercised on this PR itself before merge, at least:

  • isAuthorizedContributor
  • verifySignedCommits
  • authorChecklist

and Validate GitHub Actions runs the build step in CI.

  • Verify that no errors appear in the JS console

Offline tests

N/A - this PR only changes the GitHub Actions build tooling, not app code.

QA Steps

N/A - this PR only changes internal CI/build tooling; there is no end-user-facing or staging/production behavior to QA.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native

N/A - build tooling change only, no app UI affected.

Android: mWeb Chrome

N/A - build tooling change only, no app UI affected.

iOS: Native

N/A - build tooling change only, no app UI affected.

iOS: mWeb Safari

N/A - build tooling change only, no app UI affected.

MacOS: Chrome / Safari

N/A - build tooling change only, no app UI affected.

roryabraham and others added 5 commits July 2, 2026 23:27
Replace buildActions.sh (npx ncc) with .github/scripts/buildActions.ts,
run directly via bun. esbuild's native single-file bundling (splitting:
false) and tsconfig.json paths support remove the need for ncc's
custom patches.

Committed index.js bundles are intentionally not regenerated in this
commit; that happens next.

Co-authored-by: Cursor <cursoragent@cursor.com>
Regenerate all 24 committed index.js bundles using the new esbuild
build script. Bundle contents differ from the ncc output (different
minifier/module wrapper), but each action's runtime behavior is
unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel/ncc was only used for GitHub Action bundling, which now runs
on esbuild. Fully remove it so no traces remain:

- Drop the devDependency and regenerate package-lock.json
- Delete patches/@vercel+ncc/ (both patches + details.md) - esbuild's
  native single-file bundling and tsconfig.json paths support make
  both patches unnecessary
- Remove @vercel/ncc from knip.json's ignoreDependencies
- Drop the "npx ncc cache clean" hint from verifyActions.sh
- Reword the ncc-compiled comment in bumpVersion.ts

Removing @vercel/ncc changed dependency hoisting, so esbuild now
resolves to the top-level ^0.28.1 (previously a deduped transitive
0.27.2) when npm install ran. Rebuilding the actions with that version
picks up a small esbuild runtime helper change (safer __esm/__commonJS
error handling); included here rather than as a separate commit since
it's a direct consequence of the ncc removal + reinstall.

Co-authored-by: Cursor <cursoragent@cursor.com>
Document the esbuild + buildActions.ts build process in place of the
old ncc + buildActions.sh references.

Co-authored-by: Cursor <cursoragent@cursor.com>
Add the blank line Prettier expects after a shebang line.

Co-authored-by: Cursor <cursoragent@cursor.com>
@melvin-bot

melvin-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

npm has a package.json file and a package-lock.json file. It seems you updated one without the other, which is usually a sign of a mistake. If you are updating a package make sure that you update the version in package.json then run npm install

roryabraham and others added 2 commits July 2, 2026 23:43
The root tsconfig.json (used by npm run typecheck) includes
.github/**/* but doesn't declare Bun's global types, so tsc failed
with "Cannot find name 'Bun'". Use Node's fs/promises instead of
Bun.file()/Bun.write() - functionally identical here and avoids
needing Bun-specific types in the root tsconfig.

Co-authored-by: Cursor <cursoragent@cursor.com>
storybook@10.1.10 (esbuild ^0.18.0-^0.27.0) and tsx (esbuild ~0.27.0)
both cap below our devDependency's ^0.28.1, so npm couldn't dedupe
them onto our version. It instead nested separate copies at the
latest version satisfying their ranges (0.27.7), which falls inside
the SNYK-JS-ESBUILD-17750815 directory traversal vulnerability range
(>=0.27.3 <0.28.1). Previously, without our explicit devDependency,
everything shared a single hoisted esbuild@0.27.2, which happened to
be just below the vulnerable range.

Add esbuild to the existing "overrides" block (already used for other
transitively-vulnerable packages like ws, json5, follow-redirects) to
force every consumer, including storybook and tsx, onto the patched
0.28.1+ line. Verified npx tsx and npx storybook --version still work,
and npm run gh-actions-build produces identical bundles.

Co-authored-by: Cursor <cursoragent@cursor.com>
@roryabraham roryabraham changed the title POC: Migrate GitHub Action bundling from ncc to esbuild [No QA] Migrate GitHub Action bundling from ncc to esbuild Jul 3, 2026
roryabraham and others added 3 commits July 3, 2026 00:07
- Rename NOTE_DONT_EDIT to COMPILED_FILE_BANNER (rulesdir/no-negated-variables
  flagged "DONT" as a negation; the compiled banner text itself is unchanged)
- Move each action's error handling into buildAction() and have it return a
  boolean instead of indexing parallel results/GITHUB_ACTIONS arrays by
  position, which avoids the rulesdir/prefer-at violations without
  introducing possibly-undefined array access

Co-authored-by: Cursor <cursoragent@cursor.com>
Run npm run gh-actions-build after oxfmt (via explicit priority, since
lefthook only guarantees ordering between non-parallel commands when
priority is set) whenever a staged .ts file under .github/ changes, so
the rebuilt action bundles are committed alongside their source
instead of relying solely on CI's verifyActions.sh to catch stale
bundles. Rebuilt index.js files are staged with an explicit
`git add` in the command itself, since stage_fixed's `files` option
gates whether the command runs at all (it skips when the pre-run diff
is empty), which would prevent the build from ever executing.

Co-authored-by: Cursor <cursoragent@cursor.com>
@codecov

codecov Bot commented Jul 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
see 11 files with indirect coverage changes

roryabraham and others added 2 commits July 3, 2026 00:43
By default, lefthook's generated hook shim silently no-ops (exits 0)
if it can't find a runnable lefthook binary - it prints "Can't find
lefthook in PATH" but lets the commit through with zero checks run
(not just gh-actions-build, but oxfmt too). This is a real risk with
worktree-based development: a brand-new worktree has no node_modules
until `npm install` runs, and it's easy to make a quick edit and try
to commit before that.

Setting the top-level assert_lefthook_installed option changes the
generated shim's failure branch to exit 1 with a clear message instead
of silently passing, so a missing lefthook now blocks the commit
(escape hatches --no-verify / LEFTHOOK=0 still work) rather than
silently skipping formatting and the bundle rebuild. This only affects
the already-failing path, so it has no cost when lefthook is present
and working normally.

Verified by hiding node_modules/lefthook* and confirming `git commit`
now aborts with exit 1 instead of succeeding silently, then restoring
it and confirming normal commits still auto-format and rebuild bundles
as expected.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@roryabraham
roryabraham requested a review from Julesssss July 3, 2026 07:47
@roryabraham
roryabraham marked this pull request as ready for review July 3, 2026 07:48
@roryabraham
roryabraham requested a review from a team as a code owner July 3, 2026 07:48
@melvin-bot
melvin-bot Bot requested review from MonilBhavsar and removed request for a team July 3, 2026 07:49
@melvin-bot

melvin-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

@MonilBhavsar Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@chatgpt-codex-connector

This comment has been minimized.

@roryabraham
roryabraham marked this pull request as draft July 3, 2026 17:16
@roryabraham

Copy link
Copy Markdown
Contributor Author

converting to draft while I look into the codex comment

roryabraham and others added 4 commits July 3, 2026 15:35
… and Octokit chain

@actions/core (v3+) and @actions/github (v9+) are ESM-only, so scope the
compiled actions to ESM via package.json "type": "module". Upgrade the
Octokit plugin chain to the versions @actions/github v9 bundles, and fix
the one breaking change in that chain: @octokit/plugin-throttling's
onAbuseLimit callback was renamed onSecondaryRateLimit, with retryCount
moving to its own handler argument.

Co-authored-by: Cursor <cursoragent@cursor.com>
…y points

esbuild flattens bundled files into one shared module scope, so
checkSVGCompression/compressSvg and bumpVersion's action wrapper each
having their own require.main === module guard meant both guards fired
whichever bundle they ended up in -- for bumpVersion this silently
executed the real version-bump logic as a side effect of building or
testing checkSVGCompression, and vice versa.

Fix by making compressSvg.ts (renamed .mts, since it needs unambiguous
ESM to statically import svgo under ts-node) and bumpVersion.ts guard-free
pure libraries, and moving CLI-invocation logic to new, never-imported
compressSvg-cli.mts / bumpVersion-cli.ts entry points. Add
runTsNodeEsm.mjs, a bootstrap needed to run a single .mts file as real
ESM under ts-node (Node 20 throws ERR_REQUIRE_CYCLE_MODULE otherwise).

Also convert the action wrappers' own require.main guards to the ESM
idiom, since real ESM has no require.main.

Co-authored-by: Cursor <cursoragent@cursor.com>
….exports

Real ESM has no require.main, so convert the remaining 16 action-level
if (require.main === module) guards to the equivalent ESM idiom:
import.meta.url === pathToFileURL(process.argv.at(1) ?? '').href.

Also remove markPullRequestsAsDeployed.ts's leftover module.exports = run
(a CJS-only artifact; export default run already exists), and update its
test to import the default export instead.

Co-authored-by: Cursor <cursoragent@cursor.com>
@actions/core v3 and @actions/github v9 (and their @octokit/* and
transitive deps) ship pure ESM, but Jest runs everything through
babel-jest to CommonJS:

- transformIgnorePatterns: stop treating @actions/@octokit and their
  ESM-only transitive deps (before-after-hook, json-with-bigint,
  universal-user-agent) as already-CJS node_modules.
- New jest/esmExportsResolver.js: these packages only expose an "import"
  condition in their package.json exports maps, which Jest's default
  resolver doesn't request; add it for @actions/*/@octokit/* only.
- babel-plugin-transform-import-meta: rewrites the action guards' bare
  import.meta.url (a syntax error once babel-jest transpiles the
  surrounding module to CJS) to a CJS-safe equivalent.
- jest/setupGlobalPolyfills.ts: @actions/http-client reads the global
  TextEncoder at import time, earlier than jest/setup.ts's own
  (now-redundant) polyfill could run.
- moduleNameMapper: strip explicit ".js" specifiers on relative imports
  (required by Node's ESM resolution in .github/libs, now real ESM) so
  Jest's resolver still finds the .ts source behind them.

Also document the ESM output and the library/CLI split pattern in
.github/workflows/README.md.

Co-authored-by: Cursor <cursoragent@cursor.com>
This action landed on main after this branch converted the other 17 guards, so
it still used `require.main === module`. esbuild leaves both identifiers
untouched rather than failing the build, and `module` doesn't exist in an ES
module, so the bundle threw `ReferenceError: module is not defined in ES module
scope` on load — the action would have been dead in CI.

Added a `no-restricted-globals` rule over `.github/actions/**` and
`.github/libs/**` (the sources esbuild bundles) for `module`, `__dirname` and
`__filename`, so the next one is caught by the ESLint check instead of at
runtime. `.github/scripts/` is excluded: it runs directly under Bun, which
provides these.
knip's "compare against main" check flagged it as unlisted. The extracted
detectReactComponent uses `isIdentifier`/`isMemberExpression` from @babel/types
in place of the hand-rolled `SuperClassType` and its unsafe assertion, so the
import is real and the dependency should be declared alongside @babel/parser and
@babel/traverse. It was already installed transitively via @babel/traverse, so
this adds no install weight.

knip now reports no new findings (net -1: declaring
@octokit/plugin-rest-endpoint-methods explicitly also resolved a pre-existing
unlisted finding in failureNotifier.ts).
`React Compiler Compliance` failed on this PR with:

    HttpError: Server Error: Sorry, this diff is taking too long to generate.
    {"resource":"PullRequest","field":"diff","code":"not_available"} - 422

GitHub builds every file's patch to answer `pulls.listFiles`, and gives up when
one page holds too much content. This PR rewrites 24 action bundles, each a few
MB of diff, which is enough to trip it. Measured against this PR: per_page=40
succeeds, per_page=50 and above return 422 — and it is deterministic, not a
transient hiccup, so retrying does not help.

Two changes:

- Request 30 files per page instead of 100. That resolves this PR (81 files over
  3 pages), but the margin is thin enough that it can't be the only mitigation.
- Fall back to `git diff --name-status -M` when the API can't answer at all,
  rather than failing the check. That compares the two trees directly, so it
  needs only those two commits and not the history between them, which is what
  makes it safe in CI's shallow checkout where a merge-base diff would not be.
  It resolves against `fromRef` rather than the merge base, so it can report
  files changed only on the base branch — too many files rather than too few,
  which is the safe direction for the checks built on this.
@roryabraham

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 3ad8ad5e3b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Reverted three things that were only needed while this code still ran under
ts-node/Jest CJS, verifying in each case that nothing depends on them:

- The detectReactComponent extraction. It existed so the test could import the
  AST logic without pulling an @actions-importing module into scope, which stopped
  mattering once the tests moved to bun:test. newComponentCategory.ts keeps only
  the change the upgrade forces: @actions/github v9 dropped the
  "./lib/interfaces" deep import path, so WebhookPayload is derived from
  context.payload instead. This also drops the @babel/types dependency.
- The getMergedPR extraction from failureNotifier.ts, for the same reason. Only
  the ESM entry-guard conversion remains.
- The scripts/compressSvg .mts rename and its '.mjs' import specifiers, which
  existed to force unambiguous ESM for Node/ts-node. Bun and esbuild both resolve
  plain .ts fine, so this also removes buildActions.ts's resolveExtensions
  override, the knip {mts,cts} globs, and the eslint **/*.mts,**/*.cts entry.
  Verified the case the rename was for: checkSVGCompression still fails on a
  missing token rather than crashing in css-tree, and compress-svg still runs.
- The **/*.tsbuildinfo gitignore entry, redundant with main's existing
  **/tsconfig.tsgo.tsbuildinfo.

Kept, having confirmed each is still load-bearing:

- The compressSvg/bumpVersion lib+CLI split. Re-tested the double-fire directly:
  adding a guard back to compressSvg.ts makes it fire when checkSVGCompression's
  bundle runs, because esbuild flattens every bundled file into one module scope
  where they all share the entry point's import.meta.url.
- Git.ts's maxBuffer. `git diff -U0` over this branch is 171 MB against Node's
  1 MB default.

tests/tooling: 396 pass, 0 fail. 51 non-generated files changed, down from 56,
and 7 files no longer touched at all.
`googleapis` is a mega-package containing every Google API (212 MB unpacked),
and esbuild has no way to tree-shake it because it is CJS. The two actions that
use it need exactly `google.auth.GoogleAuth` and `google.androidpublisher` v3,
so they now import `@googleapis/androidpublisher` (2.5 MB unpacked) directly.
Its `auth` export is the same AuthPlus instance the mega-package exposes as
`google.auth`, so the call sites are otherwise unchanged.

    bundle                        before      after    change
    checkAndroidStatus           771,910     52,874      -93%
    getAndroidRolloutPercentage  764,891     45,855      -94%
    all 24 bundles, total       83.13 MB   29.88 MB      -64%
    build wall time (median)       0.75s      0.45s      -40%

The largest bundle is now authorChecklist at 69,843 lines, so nothing is in the
range that was breaking GitHub's diff viewer.

The createRequire banner still has to stay: googleapis-common and the rest of
the CJS dependency chain call require() on Node builtins, and all 24 bundles
still reference it.
Cutting googleapis down to @googleapis/androidpublisher shrank this PR's diff
from ~4.1M to ~2.8M lines, which is enough for GitHub to generate the PR file
list again: pulls.listFiles now succeeds at the default per_page=100, verified
stable over five consecutive calls. So the per_page reduction and the local
git-diff fallback are both unnecessary here, and scripts/utils/Git.ts goes back
to main apart from one line.

maxBuffer stays. `git diff -U0` over this branch is still 116.9 MB against
Node's 1 MB default, so Git.diff would throw ENOBUFS locally without it.

Worth noting the underlying fragility is real and outlives this PR: any PR whose
diff GitHub can't generate will fail React Compiler Compliance with a confusing
422 rather than degrading gracefully. That deserves its own PR rather than
riding along in a bundler migration.
@roryabraham

Copy link
Copy Markdown
Contributor Author

@Julesssss opening this up for review.

Comment thread .github/scripts/buildActions.ts Resolved

@Julesssss Julesssss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good improvement, some minor comments

Node 24 exposes import.meta.main, so we can drop the
pathToFileURL(process.argv) comparison. Actions already run
on node24.
Scan .github/actions/javascript/*/<name>.ts instead of
keeping a hard-coded list that new actions can miss.
@roryabraham
roryabraham requested a review from Julesssss August 21, 2026 21:59
@roryabraham
roryabraham merged commit 0d180ef into main Aug 21, 2026
52 of 59 checks passed
@roryabraham
roryabraham deleted the rory-gh-actions-esbuild branch August 21, 2026 22:17
@github-actions

Copy link
Copy Markdown
Contributor

🚧 roryabraham has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify OSBotify mentioned this pull request Aug 22, 2026
61 tasks done
@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/roryabraham in version: 9.4.59-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/AndrewGable in version: 9.4.59-5 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants