publish-rust.mjs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 [level] = cliArguments();
  6. if (!level) {
  7. throw new Error('A version level — e.g. "path" — must be provided.');
  8. }
  9. // Go to the client directory and install the dependencies.
  10. cd(path.join(workingDirectory, 'clients', 'rust'));
  11. // Publish the new version.
  12. const releaseArgs = dryRun
  13. ? []
  14. : ['--no-push', '--no-tag', '--no-confirm', '--execute'];
  15. await $`cargo release ${level} ${releaseArgs}`;
  16. // Stop here if this is a dry run.
  17. if (dryRun) {
  18. process.exit(0);
  19. }
  20. // Get the new version.
  21. const newVersion = getCargo(path.join('clients', 'rust')).package.version;
  22. // Expose the new version to CI if needed.
  23. if (process.env.CI) {
  24. await $`echo "new_version=${newVersion}" >> $GITHUB_OUTPUT`;
  25. }
  26. // Soft reset the last commit so we can create our own commit and tag.
  27. await $`git reset --soft HEAD~1`;
  28. // Commit the new version.
  29. await $`git commit -am "Publish Rust client v${newVersion}"`;
  30. // Tag the new version.
  31. await $`git tag -a rust@v${newVersion} -m "Rust client v${newVersion}"`;