publish.mts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env zx
  2. import 'zx/globals';
  3. import {
  4. cliArguments,
  5. getCargo,
  6. popArgument,
  7. workingDirectory,
  8. } from './setup/shared.mts';
  9. const [folder, ...args] = cliArguments();
  10. const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');
  11. const fix = popArgument(args, '--dry-run');
  12. const dryRun = argv['dry-run'] ?? false;
  13. const [level] = args;
  14. if (!level) {
  15. throw new Error('A version level — e.g. "patch" — must be provided.');
  16. }
  17. // Get the crate name.
  18. const crate = getCargo(folder).package['name'];
  19. // Go to the crate folder to release.
  20. cd(path.dirname(manifestPath));
  21. // Publish the new version.
  22. const releaseArgs = dryRun
  23. ? []
  24. : ['--tag-name', `${crate}@v{{version}}`, '--no-confirm', '--execute'];
  25. await $`cargo release ${level} ${releaseArgs}`;
  26. // Stop here if this is a dry run.
  27. if (dryRun) {
  28. process.exit(0);
  29. }
  30. // Get the updated version number.
  31. const version = getCargo(folder).package['version'];
  32. // Expose the new version to CI if needed.
  33. if (process.env.CI) {
  34. await $`echo "crate=${crate}" >> $GITHUB_OUTPUT`;
  35. await $`echo "version=${version}" >> $GITHUB_OUTPUT`;
  36. }