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

Dry run for shipit #8290

Open
itsdouges opened this issue Feb 12, 2025 · 0 comments
Open

Dry run for shipit #8290

itsdouges opened this issue Feb 12, 2025 · 0 comments

Comments

@itsdouges
Copy link
Contributor

itsdouges commented Feb 12, 2025

Hey mate! I've gotten into a few snags with ShipIt over the years and I'm at the point where I want it to stop the possibility of builds failing in main. If there was a dry run option that would skip pushing the commit to the repo that would work really well.

Is there any way to prevent the push right now? Looking at it, no there isn't. What is we added --dry-run and conditionally applied the push phase? https://github.com/adeira/shipit/blob/master/bin/shipit.js#L48

This is the patch I'm using to implement this behaviour atm:

diff --git a/bin/shipit.js b/bin/shipit.js
index 27fea2c945ab94e03ac22d73a0da7c61eb8f6f42..fcf3de1f78e524b0e8b0a78a9c5cf9d9f1460009 100755
--- a/bin/shipit.js
+++ b/bin/shipit.js
@@ -13,13 +13,16 @@ var _createVerifyRepoPhase = _interopRequireDefault(require("../src/phases/creat
 var _createPushPhase = _interopRequireDefault(require("../src/phases/createPushPhase"));
 // yarn monorepo-babel-node src/monorepo-shipit/bin/shipit.js --help
 // yarn monorepo-babel-node src/monorepo-shipit/bin/shipit.js --committer-name=A --committer-email=B
-_commander.program.version(require('./../package.json').version).description('Export a monorepo to multiple git repositories').requiredOption('--config-filter <glob>', 'Glob pattern to filter config files', '/*.js').requiredOption('--config-dir <path>', 'Path to the directory with config files', './.shipit').requiredOption('--committer-name <name>', 'Name of the committer').requiredOption('--committer-email <email>', 'Email of the committer');
+_commander.program.version(require('./../package.json').version).description('Export a monorepo to multiple git repositories').requiredOption('--config-filter <glob>', 'Glob pattern to filter config files', '/*.js').requiredOption('--config-dir <path>', 'Path to the directory with config files', './.shipit').requiredOption('--committer-name <name>', 'Name of the committer').requiredOption('--committer-email <email>', 'Email of the committer')
+.option('--dry-run', 'Skips the push phase', false);
 _commander.program.parse();
 const options = _commander.program.opts();
+function skipPushPhase() {}
+skipPushPhase.readableName = 'Skipping push new changes';
 process.env.SHIPIT_COMMITTER_EMAIL = options.committerEmail;
 process.env.SHIPIT_COMMITTER_NAME = options.committerName;
 (0, _iterateConfigs.default)(options, config => {
-  new Set([(0, _createClonePhase.default)(config.exportedRepoURL, config.destinationPath), (0, _createCheckCorruptedRepoPhase.default)(config.destinationPath), (0, _createCleanPhase.default)(config.destinationPath), (0, _createSyncPhase.default)(config), (0, _createVerifyRepoPhase.default)(config), (0, _createPushPhase.default)(config)]).forEach(phase => {
+  new Set([(0, _createClonePhase.default)(config.exportedRepoURL, config.destinationPath), (0, _createCheckCorruptedRepoPhase.default)(config.destinationPath), (0, _createCleanPhase.default)(config.destinationPath), (0, _createSyncPhase.default)(config), (0, _createVerifyRepoPhase.default)(config), options.dryRun ? skipPushPhase : (0, _createPushPhase.default)(config)]).forEach(phase => {
     console.log(`${_chalk.default.dim('Starting phase:')} %s`, phase.readableName);
     phase();
     console.log(`${_chalk.default.dim('Finished phase:')} %s`, phase.readableName);

Edit: That said, this only worked in a pull request once. Now I'm getting OUT OF SYNC errors. I probably need to update the origin.

Edit 2: Yep. Wrote this to fix:

module.exports = {
  getGitSource() {
    if (process.env.GITHUB_HEAD_REF) {
      // We're running in a pull request so we're performing a dry run.
      return `origin/${process.env.GITHUB_HEAD_REF}`;
    }

    return "origin/main";
  },
};

Theoretically the shipit lib could handle this though.

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

No branches or pull requests

1 participant