publish.mjs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env zx
  2. import 'zx/globals';
  3. import { cliArguments, getCargo, workingDirectory } from '../utils.mjs';
  4. const dryRun = argv['dry-run'] ?? false;
  5. const [folder, level] = cliArguments();
  6. if (!folder) {
  7. throw new Error('A path to a directory with a Rust package — e.g. "clients/cli" — must be provided.');
  8. }
  9. if (!level) {
  10. throw new Error('A version level — e.g. "patch" — must be provided.');
  11. }
  12. cd(path.join(workingDirectory, folder));
  13. const packageToml = getCargo(folder).package;
  14. const oldVersion = packageToml.version;
  15. const packageName = packageToml.name;
  16. const tagName = path.basename(folder);
  17. // Publish the new version, commit the repo change, tag it, and push it all.
  18. const releaseArgs = dryRun
  19. ? []
  20. : ['--tag-name', `${tagName}@v{{version}}`, '--no-confirm', '--execute'];
  21. await $`cargo release ${level} ${releaseArgs}`;
  22. // Stop here if this is a dry run.
  23. if (dryRun) {
  24. process.exit(0);
  25. }
  26. // Get the new version.
  27. const newVersion = getCargo(folder).package.version;
  28. const newGitTag = `${tagName}@v${newVersion}`;
  29. const oldGitTag = `${tagName}@v${oldVersion}`;
  30. // Expose the new version to CI if needed.
  31. if (process.env.CI) {
  32. await $`echo "new_git_tag=${newGitTag}" >> $GITHUB_OUTPUT`;
  33. await $`echo "old_git_tag=${oldGitTag}" >> $GITHUB_OUTPUT`;
  34. }