Skip to content

Commit cebacc3

Browse files
committed
ci: support commit SHAs and surface spawn errors in ecosystem-ci
Switch from `git clone --branch` to `git init` + `git fetch --depth 1` so the workflow's `ref` input accepts commit SHAs (as the description already advertises), and include `result.error` / `result.signal` in the thrown message so spawn failures are diagnosable. Addresses Copilot review on #23.
1 parent 5ace78d commit cebacc3

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

scripts/ecosystem-ci.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ function prepareClone(ref: string): void {
8787
if (existsSync(devtoolsDir))
8888
rmSync(devtoolsDir, { recursive: true, force: true })
8989

90-
run('git', ['clone', '--depth', '1', '--branch', ref, REPO_URL, devtoolsDir])
90+
// Use init + fetch instead of `clone --branch` so any ref works — tag,
91+
// branch, or commit SHA. GitHub allows fetching reachable SHAs by default.
92+
mkdirSync(devtoolsDir, { recursive: true })
93+
run('git', ['init', '--quiet'], devtoolsDir)
94+
run('git', ['remote', 'add', 'origin', REPO_URL], devtoolsDir)
95+
run('git', ['fetch', '--depth', '1', 'origin', ref], devtoolsDir)
96+
run('git', ['checkout', '--quiet', 'FETCH_HEAD'], devtoolsDir)
9197
}
9298

9399
function patchPackageJson(repoDir: string, tarball: string): void {
@@ -106,11 +112,12 @@ function readManifest(file: string): PackageManifest {
106112
function run(cmd: string, args: string[], cwd: string = rootDir): void {
107113
log(`$ ${cmd} ${args.join(' ')} (in ${cwd})`)
108114
const result = spawnSync(cmd, args, { cwd, stdio: 'inherit', shell: false })
109-
if (result.status !== 0) {
110-
throw new Error(
111-
`Command failed (exit ${result.status ?? 'unknown'}): ${cmd} ${args.join(' ')}`,
112-
)
113-
}
115+
if (result.error)
116+
throw new Error(`Command failed to spawn: ${cmd} ${args.join(' ')}: ${result.error.message}`)
117+
if (result.signal)
118+
throw new Error(`Command terminated by signal ${result.signal}: ${cmd} ${args.join(' ')}`)
119+
if (result.status !== 0)
120+
throw new Error(`Command failed (exit ${result.status ?? 'unknown'}): ${cmd} ${args.join(' ')}`)
114121
}
115122

116123
function log(msg: string): void {

0 commit comments

Comments
 (0)