Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git node staging command #875

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions components/git/staging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import CLI from '../../lib/cli.js';
import { runPromise } from '../../lib/run.js';
import { Staging } from '../../lib/staging.js';

export const command = 'staging';
export const describe = 'Automatic port commits to a release line branch';

const stagingOptions = {
autoSkip: {
describe: 'Automatically skip commits with conflicts that have to be manually resolved',
type: 'boolean'
},
backport: {
describe: 'The PR ID / number to backport, skip staging commits',
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why this option is on git node staging?

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea is that this is a convenience helper for when, let's say, you end up having to remove a commit from the staging branch after figuring out it was breaking CI, then as a releaser you can just run git node staging --backport=<PR_ID> after rebasing / removing the offending commits from the staging branch.

It's part of git node staging more from an implementation convenience point of view since all the internal logic is already there.

Copy link
Member Author

@ruyadorno ruyadorno Dec 8, 2024

Choose a reason for hiding this comment

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

Also, it's worth noting that git node staging --backport=<PR_ID> should send an automated comment by default in the original PR, which it's not going to happen in the regular git node staging automation.

type: 'number'
},
continue: {
describe: 'Continue the staging process after a conflict',
type: 'boolean'
},
paginate: {
describe: 'Sets a maximum number of commits to port',
type: 'number'
},
releaseLine: {
describe: 'The major version of the target release',
type: 'number'
},
reportDestination: {
describe: 'The destination to write the report to. Possible values are: ' +
'stdout, github, or a file path, defaults to an interactive prompt.',
type: 'string',
default: undefined
},
reporter: {
describe: 'The reporter to use for the output',
type: 'string',
default: 'markdown'
},
reset: {
describe: 'Reset the staging process',
type: 'boolean'
},
skip: {
describe: 'Continue the staging process marking the current commit as skipped',
type: 'boolean'
},
skipGH: {
describe: 'Skip all `gh` cli actions. Will not read / add label to GitHub PRs',
type: 'boolean'
}
};

export function builder(yargs) {
return yargs
.options(stagingOptions)
.example('git node staging --releaseLine=23',
'Port commits to the v1.x-staging branch');
}

export function handler(argv) {
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
const cli = new CLI(logStream);
const dir = process.cwd();

return runPromise(main(argv, cli, dir)).catch((err) => {
if (cli.spinner.enabled) {
cli.spinner.fail();
}
throw err;
});
}

async function main(argv, cli, dir) {
const {
autoSkip,
backport,
paginate,
releaseLine,
reportDestination,
reporter,
reset,
skip,
skipGH
} = argv;
const staging = new Staging({
cli,
dir,
cont: argv.continue,
autoSkip,
paginate,
releaseLine,
reportDestination,
reporter,
skip,
skipGH
});
if (backport) {
await staging.requestBackport(backport);
} else if (reset) {
await staging.reset();
} else {
await staging.run();
}
}
5 changes: 5 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
}

stopSpinner(rawText, status = SUCCESS) {
if (!rawText) {
this.spinner.stop();
return;
}

Check warning on line 113 in lib/cli.js

View check run for this annotation

Codecov / codecov/patch

lib/cli.js#L111-L113

Added lines #L111 - L113 were not covered by tests

let symbol;
switch (status) {
case SUCCESS:
Expand Down
24 changes: 18 additions & 6 deletions lib/prepare_release.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,24 @@ export default class ReleasePreparation extends Session {
const { newVersion } = this;
const proposalBranch = `v${newVersion}-proposal`;

await runAsync('git', [
'checkout',
'-b',
proposalBranch,
base
]);
try {
await forceRunAsync('git', [
'checkout',
'-b',
proposalBranch,
base
], { captureStdout: true, captureStderr: true, ignoreFailures: false });
} catch (err) {
const branchExistsRE = /fatal: a branch named '.*' already exists/i;
if (branchExistsRE.test(err.stderr)) {
await runAsync('git', [
'checkout',
proposalBranch
]);
} else {
throw err;
}
}
return proposalBranch;
}

Expand Down
18 changes: 16 additions & 2 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
ignoreFailure = true,
spawnArgs,
input,
captureStdout = false
captureStdout = false,
captureStderr = false
} = {}) {
if (cmd instanceof URL) {
cmd = fileURLToPath(cmd);
}
let stdio = 'inherit';
if (captureStdout || input != null) {
stdio = [input == null ? 'inherit' : 'pipe', captureStdout ? 'pipe' : 'inherit', 'inherit'];
stdio = [
input == null ? 'inherit' : 'pipe',
captureStdout ? 'pipe' : 'inherit',
captureStderr ? 'pipe' : 'inherit'
];
}
return new Promise((resolve, reject) => {
const opt = Object.assign({
Expand All @@ -36,13 +41,22 @@
child.stdout.setEncoding('utf8');
child.stdout.on('data', (chunk) => { stdout += chunk; });
}
let stderr;
if (captureStderr) {
stderr = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', (chunk) => { stderr += chunk; });
}

Check warning on line 49 in lib/run.js

View check run for this annotation

Codecov / codecov/patch

lib/run.js#L46-L49

Added lines #L46 - L49 were not covered by tests
child.on('error', reject);
child.on('close', (code) => {
if (code !== 0) {
if (ignoreFailure) {
return reject(new Error(IGNORE));
}
const err = new Error(`${cmd} ${args} failed: ${code}`);
if (stderr) {
err.stderr = stderr;
}

Check warning on line 59 in lib/run.js

View check run for this annotation

Codecov / codecov/patch

lib/run.js#L57-L59

Added lines #L57 - L59 were not covered by tests
err.code = code;
err.messageOnly = true;
return reject(err);
Expand Down
Loading
Loading