Skip to content

Commit 3fdfd68

Browse files
committed
feat: combine add-repo.sh and CI generator from #434 and #505
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.
1 parent 8a32020 commit 3fdfd68

7 files changed

Lines changed: 816 additions & 774 deletions

File tree

.github/path-filters.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# This file is generated by scripts/update-gha-workflows.ts
2+
#
3+
# To regenerate: npm run refresh-gh-workflow
4+
15
# The `&global` anchor defines a set of common paths to include by reference in the other filters.
26
global: &global
37
- ".github/path-filters.yml"
@@ -14,9 +18,6 @@ any-workspace:
1418
task-herder:
1519
- *global
1620
- "packages/task-herder/**"
17-
scratch-media-lib-scripts:
18-
- *global
19-
- "packages/scratch-media-lib-scripts/**"
2021
scratch-svg-renderer:
2122
- *global
2223
- "packages/scratch-svg-renderer/**"
@@ -35,3 +36,6 @@ scratch-gui:
3536
- "packages/scratch-render/**"
3637
- "packages/scratch-svg-renderer/**"
3738
- "packages/scratch-vm/**"
39+
scratch-media-lib-scripts:
40+
- *global
41+
- "packages/scratch-media-lib-scripts/**"

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# build-monorepo.sh
2-
/monorepo.out
3-
/monorepo.tmp
4-
/monorepo.cache
1+
# add-repo.sh
2+
/add-repo.tmp
3+
/add-repo.errors.log
54

65
# Logs
76
logs

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
],
2525
"scripts": {
2626
"build": "cross-env NODE_ENV=production npm run --workspaces build",
27-
"build-monorepo": "cross-env-shell ./scripts/build-monorepo.sh",
2827
"clean": "npm run --workspaces clean",
2928
"prepare": "husky install",
30-
"refresh-gh-workflow": "ts-node scripts/build-gha-workflows.ts",
29+
"refresh-gh-workflow": "ts-node scripts/update-gha-workflows.ts",
3130
"start": "npm --workspace @scratch/scratch-gui start",
3231
"test": "npm test --workspaces",
3332
"update-legal": "npm --workspaces exec -c 'rm -f ./{LICENSE,TRADEMARK} && cp -f ../../{LICENSE,TRADEMARK} .'",

0 commit comments

Comments
 (0)