verify-release.mjs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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
  5. * `node-addon-system-vX.Y.Z` tag matches it. With `--prebuilds`: every platform package's declared
  6. * binaries exist with the right native format and 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. const TAG_PREFIX = 'refs/tags/node-addon-system-v';
  12. function verifyVersions() {
  13. const packages = packageDirs().map((dir) => ({
  14. dir,
  15. manifest: readJson(path.join(root, dir, 'package.json')),
  16. }));
  17. const versions = new Set(packages.map((pkg) => pkg.manifest.version));
  18. if (versions.size !== 1) {
  19. throw new Error([
  20. 'published package versions must match:',
  21. ...packages.map((pkg) => `${pkg.dir}: ${pkg.manifest.version}`),
  22. ].join('\n'));
  23. }
  24. const version = packages[0].manifest.version;
  25. const ref = process.env.GITHUB_REF || '';
  26. const publish = process.env.RELEASE_PUBLISH === 'true';
  27. if (publish && !ref.startsWith(TAG_PREFIX)) {
  28. throw new Error('publishing requires running the workflow from a node-addon-system-v* tag');
  29. }
  30. if (ref.startsWith(TAG_PREFIX)) {
  31. const tagVersion = ref.slice(TAG_PREFIX.length);
  32. if (tagVersion !== version) {
  33. throw new Error(`tag/version mismatch: tag node-addon-system-v${tagVersion}, packages ${version}`);
  34. }
  35. }
  36. console.log(`Verified release version ${version}`);
  37. }
  38. function verifyPrebuilds() {
  39. for (const dir of platformDirs()) {
  40. const { name, count } = verifyPlatformBinaries(path.join(root, dir));
  41. console.log(`Verified ${name}: ${count} binaries`);
  42. }
  43. }
  44. verifyVersions();
  45. if (process.argv.includes('--prebuilds')) {
  46. verifyPrebuilds();
  47. }