Skip to content

[UEPR-535] Combine add-repo.sh and CI generator scripts from #434 and #505#571

Open
cwillisf wants to merge 2 commits into
developfrom
feat/canonical-add-repo-script
Open

[UEPR-535] Combine add-repo.sh and CI generator scripts from #434 and #505#571
cwillisf wants to merge 2 commits into
developfrom
feat/canonical-add-repo-script

Conversation

@cwillisf
Copy link
Copy Markdown
Contributor

@cwillisf cwillisf commented May 14, 2026

Resolves

UEPR-535 (script work)

Proposed Changes

  • Add scripts/add-repo.sh, a single canonical script for adding a scratchfoundation repository into the monorepo. Combines add-to-monorepo.sh from Add scratch-storage to the monorepo #434 and add-repo.sh from Feat/uepr 535 introduce script for migrating packages to monorepo #505.
  • Add scripts/update-gha-workflows.ts from Feat/uepr 535 introduce script for migrating packages to monorepo #505 to regenerate .github/path-filters.yml and incrementally update .github/workflows/publish.yml. Remove the CircleCI-era scripts/build-gha-workflows.ts and scripts/workspace-template.yml. Update package.json's refresh-gh-workflow to point at the new file.
  • Address the open review comments on Feat/uepr 535 introduce script for migrating packages to monorepo #505:
    • sed -i portability: in-place rewrites now use perl -pi -e, which works on macOS, NixOS, Ubuntu, Debian, Arch, and WSL.
    • Argument parser rejects flag values that are themselves flags (e.g. --source-branch --org foo).
    • npm install failures hard-fail by default. --continue-on-error opts into the prior log-and-continue behavior. Failures are still recorded in add-repo.errors.log.
    • The submodules-aware path in move_repository_subdirectory carries a TODO noting it has never been exercised against a real submodules-bearing repo.
  • Rewire cross-workspace dependencies in the new package whether they are declared by bare name or already with the @scratch/ prefix. Pin to the current monorepo version, matching the existing convention in scratch-gui, scratch-vm, and scratch-render. (workspace:* would be the ideal here, but npm/cli#8845 reports EUNSUPPORTEDPROTOCOL at install time.)
  • Insert the new package into the root workspaces array right after the latest existing workspace it depends on, so npm run --workspaces build builds dependencies first.
  • bash 3.2 compatibility for macOS: replace mapfile (bash 4+) with a while IFS= read -r loop.

Reason for Changes

#434 and #505 each had real strengths and an opposite cross-platform bug. Neither merged. Combining them now produces a single tool that is strictly better than either alone, before the next monorepo addition is attempted.

This PR supersedes the script work in both #434 and #505. It does not include #434's scratch-storage merge; that can be re-done on top of this PR using the canonical script.

Test Coverage

Local end-to-end runs on Linux (NixOS) and macOS with scratch-paint as the import target:

  • Script ran to completion on both platforms.
  • packages/scratch-paint inserted into root workspaces after scratch-svg-renderer (correct build order).
  • npm ls reports no invalid: entries; all cross-workspace deps dedupe to workspace versions.
  • npm run build succeeds for scratch-svg-renderer.
  • npm run lint --workspace=@scratch/scratch-paint reports 0 errors (155 warnings are pre-existing in scratch-paint's source).
  • npm run build does not currently succeed for scratch-paint. Target repositories may need preparation work in their own toolchains before being added to the monorepo; in scratch-paint's case the webpack/babel configuration needs to be updated to handle modern JS in built workspace dependencies. Other target repos may need different preparation. This is upstream of the script's job.

Local dogfood state was discarded after verification; this PR contains script-only changes.

Pure rename, no content changes. Preserves git blame for the shared helpers
across the upcoming rewrite that adapts this script from "build the whole
monorepo" to "add one repo at a time".
@cwillisf cwillisf requested a review from a team as a code owner May 14, 2026 17:52
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

Test Results

    8 files  ±0  1 114 suites  ±0   11m 53s ⏱️ - 1m 15s
2 845 tests ±0  2 837 ✅ ±0   8 💤 ±0  0 ❌ ±0 
6 471 runs  ±0  6 432 ✅ ±0  39 💤 ±0  0 ❌ ±0 

Results for commit 3fdfd68. ± Comparison against base commit e715417.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR consolidates legacy monorepo-import and CI-generation tooling into a single canonical repo-import script plus a new GitHub Actions workflow updater, removing the prior CircleCI-era generator and templates.

Changes:

  • Add scripts/add-repo.sh to import an external Scratch Foundation repo into packages/<repo>/, rewire workspace deps, update root workspaces order, and optionally regenerate CI files.
  • Add scripts/update-gha-workflows.ts to regenerate .github/path-filters.yml and incrementally extend .github/workflows/publish.yml with missing workspace publish steps.
  • Remove obsolete scripts/templates (scripts/build-monorepo.sh, scripts/build-gha-workflows.ts, scripts/workspace-template.yml) and rewire npm run refresh-gh-workflow accordingly.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
scripts/add-repo.sh New canonical script for importing a repo into the monorepo and performing dependency/workspace/CI fixups.
scripts/update-gha-workflows.ts New generator/updater for path filters and incremental publish workflow step insertion.
package.json Points refresh-gh-workflow to the new generator; removes legacy script entry.
.github/path-filters.yml Updates generated header and workspace ordering to match new generator output.
.gitignore Replaces legacy monorepo tmp artifacts with add-repo tmp/error outputs.
scripts/build-monorepo.sh Removed legacy monorepo build/import script.
scripts/build-gha-workflows.ts Removed CircleCI-era workflow generator.
scripts/workspace-template.yml Removed template used by the old generator.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/add-repo.sh Outdated
Comment thread scripts/add-repo.sh
Comment thread scripts/add-repo.sh Outdated
Comment thread scripts/update-gha-workflows.ts
Comment thread scripts/update-gha-workflows.ts Outdated
@cwillisf cwillisf force-pushed the feat/canonical-add-repo-script branch from 9232234 to abfdab8 Compare May 14, 2026 18:23
@cwillisf cwillisf requested a review from Copilot May 14, 2026 18:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Comment thread scripts/add-repo.sh
Comment thread scripts/add-repo.sh Outdated
Comment thread scripts/update-gha-workflows.ts
Replaces the script work of two prior PRs that independently solved
"add an existing scratchfoundation repo to the monorepo":

scripts/add-repo.sh — collapses add-to-monorepo.sh (#434) and add-repo.sh
(#505) into a single canonical entry point. Takes the CLI shape and
auto-CI-regen from #505 and the source-branch auto-detect (develop ->
main -> master), normalization (sort-package-json), and clean-tree
pre-flight from #434.

scripts/update-gha-workflows.ts — replaces the CircleCI-era
build-gha-workflows.ts and workspace-template.yml. Regenerates
.github/path-filters.yml and incrementally updates publish.yml.

Open review comments on #505 are addressed:

- sed -i portability bug: rewrites now use perl -pi -e (works on macOS,
  NixOS, Ubuntu/Debian/Arch, WSL). Perl is added to the explicit prereq
  check next to git-filter-repo, sponge, and jq.
- Arg parser now rejects flag-stealing: --source-branch --org foo errors
  instead of silently using --org as the branch name.
- npm-install failures hard-fail by default. --continue-on-error opts
  into the prior soft-fail behavior; failures are still logged to
  add-repo.errors.log when continuing. Scoped to per-dep package.json
  rewrite failures in the rewire step; the final lockfile install
  always hard-fails by design.
- The submodules-aware branch in move_repository_subdirectory keeps a
  TODO comment marking that it has never been exercised against a real
  submodules-bearing repo and should be run carefully when one lands.

Cross-workspace dep handling: rewires both bare-name and already-prefixed
@scratch/<name> deps in the new package to exact-pinned current monorepo
versions. Matches the existing convention in scratch-gui/scratch-vm/
scratch-render. npm's workspace: protocol would be the ideal here but
npm does not actually support it (npm/cli#8845 - EUNSUPPORTEDPROTOCOL
at install time).

Workspaces array ordering: the new package is inserted just after the
latest existing workspace it depends on, so 'npm run --workspaces build'
builds its deps first. Falls back to position 0 (prepend) when the new
package has no monorepo deps. This is a "last dep wins" heuristic, not
a full topological sort; it relies on the existing workspaces array
already being in valid build order. A real topo sort can be added later
(e.g. by extending update-gha-workflows.ts) if it ever becomes necessary.

bash 3.2 compatibility: macOS ships bash 3.2 at /bin/bash, which lacks
the 'mapfile' builtin. The find/grep output is collected via a 'while
IFS= read -r' loop so the script runs on macOS as well as Linux.

Bare-clone alternates path: bare clones store the alternates file at
objects/info/alternates, not .git/objects/info/alternates. The previous
path was a no-op; the working disconnection comes from --dissociate in
the clone command. Path corrected so the line is defensive belt-and-
braces rather than dead code.

update-gha-workflows.ts: throws with a clear error if npm query returns
a workspace not present in the root "workspaces" array (previously
would silently misorder via indexOf returning -1). The comment in
resolveWorkspaces is corrected to reflect that the function returns
Map insertion order, with the caller re-sorting into declared order.
The npm query exec call now requests a 64 MiB maxBuffer; Node's
default 1 MiB is fine for the current repo size but would silently
truncate as the monorepo grows.

Path anchoring: BUILD_TMP, BUILD_CACHE, and any user-supplied
--cache-dir value are resolved to absolute paths up front. A
CWD-relative default would have put add-repo.tmp outside the repo
(and outside the .gitignore pattern) if the script were run from a
subdirectory of the monorepo.

No repo additions are included; this PR is script-tooling only.
@cwillisf cwillisf force-pushed the feat/canonical-add-repo-script branch from abfdab8 to 3fdfd68 Compare May 14, 2026 19:12
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.

2 participants