1
0

verify-release.mjs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env node
  2. /**
  3. * Release verification. Always: every published package carries one shared
  4. * version, and — when running from a tag or publishing — the `vX.Y.Z` tag
  5. * matches it. With `--prebuilds`: every platform package's declared
  6. * binaries exist with the right ELF architecture (run after
  7. * `assemble-prebuilds.mjs` or a local `build:native`).
  8. */
  9. import path from 'node:path';
  10. import { packageDirs, platformDirs, readJson, root, verifyPlatformBinaries } from './repo.mjs';
  11. function verifyVersions() {
  12. const packages = packageDirs().map((dir) => ({
  13. dir,
  14. manifest: readJson(path.join(root, dir, 'package.json')),
  15. }));
  16. const versions = new Set(packages.map((pkg) => pkg.manifest.version));
  17. if (versions.size !== 1) {
  18. throw new Error([
  19. 'published package versions must match:',
  20. ...packages.map((pkg) => `${pkg.dir}: ${pkg.manifest.version}`),
  21. ].join('\n'));
  22. }
  23. const version = packages[0].manifest.version;
  24. const ref = process.env.GITHUB_REF || '';
  25. const publish = process.env.RELEASE_PUBLISH === 'true';
  26. if (publish && !ref.startsWith('refs/tags/v')) {
  27. throw new Error('publishing requires running the workflow from a v* tag');
  28. }
  29. if (ref.startsWith('refs/tags/v')) {
  30. const tagVersion = ref.slice('refs/tags/v'.length);
  31. if (tagVersion !== version) {
  32. throw new Error(`tag/version mismatch: tag v${tagVersion}, packages ${version}`);
  33. }
  34. }
  35. console.log(`Verified release version ${version}`);
  36. }
  37. function verifyPrebuilds() {
  38. for (const dir of platformDirs()) {
  39. const { name, count } = verifyPlatformBinaries(path.join(root, dir));
  40. console.log(`Verified ${name}: ${count} binaries`);
  41. }
  42. }
  43. verifyVersions();
  44. if (process.argv.includes('--prebuilds')) {
  45. verifyPrebuilds();
  46. }