MCPcopy Index your code
hub / github.com/less/less.js / runCreateReleasePRStep

Function runCreateReleasePRStep

scripts/test-release-automation.js:258–324  ·  view source on GitHub ↗
({ repoDir, nextVersion, releaseBranch })

Source from the content-addressed store, hash-verified

256// ---------------------------------------------------------------------------
257
258function runCreateReleasePRStep({ repoDir, nextVersion, releaseBranch }) {
259 // Stub `gh` binary so any calls are recorded but do nothing
260 const binDir = path.join(repoDir, '.test-bin');
261 fs.mkdirSync(binDir, { recursive: true });
262 const ghLog = path.join(repoDir, 'gh-calls.log');
263 fs.writeFileSync(path.join(binDir, 'gh'), `#!/bin/sh\necho "$@" >> "${ghLog}"\n`);
264 fs.chmodSync(path.join(binDir, 'gh'), 0o755);
265
266 const initialHead = execSync('git rev-parse HEAD', { cwd: repoDir, encoding: 'utf8' }).trim();
267
268 const script = `
269set -euo pipefail
270NEXT_VERSION=${JSON.stringify(nextVersion)}
271RELEASE_BRANCH=${JSON.stringify(releaseBranch)}
272TITLE="chore: release v\${NEXT_VERSION}"
273
274git checkout -b "\${RELEASE_BRANCH}"
275
276node -e "
277 const fs = require('fs');
278 const version = process.env.NEXT_VERSION;
279 const dirs = fs.readdirSync('packages', { withFileTypes: true })
280 .filter(d => d.isDirectory())
281 .map(d => 'packages/' + d.name + '/package.json');
282 for (const f of ['package.json', ...dirs].filter(f => fs.existsSync(f))) {
283 const pkg = JSON.parse(fs.readFileSync(f, 'utf8'));
284 if (!pkg.version) continue;
285 pkg.version = version;
286 fs.writeFileSync(f, JSON.stringify(pkg, null, '\\t') + '\\n');
287 }
288"
289
290git add package.json packages/*/package.json
291COMMITTED=false
292if git diff --cached --quiet; then
293 echo "STATUS:NO_CHANGES"
294else
295 git commit -m "\${TITLE}"
296 COMMITTED=true
297fi
298echo "STATUS:COMMITTED=\${COMMITTED}"
299`;
300
301 const result = spawnSync('bash', ['-c', script], {
302 cwd: repoDir,
303 env: {
304 ...process.env,
305 NEXT_VERSION: nextVersion,
306 GH_TOKEN: 'fake-token',
307 PATH: `${binDir}:${process.env.PATH}`,
308 },
309 encoding: 'utf8',
310 });
311
312 const finalHead = execSync('git rev-parse HEAD', { cwd: repoDir, encoding: 'utf8' }).trim();
313 const ghCalls = fs.existsSync(ghLog) ? fs.readFileSync(ghLog, 'utf8').trim() : '';
314
315 return {

Callers 1

Calls 1

joinMethod · 0.65

Tested by

no test coverage detected