publish-cli-release.mjs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import assert from 'node:assert/strict';
  2. import { execFileSync } from 'node:child_process';
  3. import { createHash } from 'node:crypto';
  4. import { readFileSync, writeFileSync } from 'node:fs';
  5. import path from 'node:path';
  6. import { fileURLToPath } from 'node:url';
  7. import { versionFromTag, cliReleaseTargets } from './lib/cli-release.mjs';
  8. export function validateReleaseReports({ archive, reports, version, revision }) {
  9. const sha256 = createHash('sha256').update(readFileSync(archive)).digest('hex');
  10. assert.equal(readFileSync(`${archive}.sha256`, 'utf8'), `${sha256} ${path.basename(archive)}\n`);
  11. for (const target of cliReleaseTargets) {
  12. const directory = path.join(reports, `cli-install-${target.os}-${target.node}`);
  13. const installation = JSON.parse(readFileSync(path.join(directory, 'package-install.json'), 'utf8'));
  14. const verification = JSON.parse(readFileSync(path.join(directory, 'verification.json'), 'utf8'));
  15. assert.equal(verification.status, 'PASS');
  16. assert.equal(verification.profile, 'package');
  17. assert.equal(verification.revision, revision);
  18. assert.equal(verification.gates.find(gate => gate.name === 'test:release-package')?.status, 'PASS');
  19. assert.equal(installation.status, 'PASS');
  20. assert.equal(installation.version, version);
  21. assert.equal(installation.revision, revision);
  22. assert.equal(installation.sha256, sha256);
  23. assert.equal(installation.platform, target.os.startsWith('ubuntu') ? 'linux' : 'darwin');
  24. assert.ok(installation.node === `v${target.node}` || installation.node.startsWith(`v${target.node}.`));
  25. }
  26. return sha256;
  27. }
  28. if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
  29. const tag = process.env.MCODE_RELEASE_TAG;
  30. const version = versionFromTag(tag);
  31. const revision = execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
  32. if (!process.env.MCODE_RELEASE_DIRECTORY || !process.env.MCODE_RELEASE_REPORTS) throw new Error('Release directory and reports are required.');
  33. const archive = path.join(process.env.MCODE_RELEASE_DIRECTORY, `minimax-code-${version}.tar.gz`);
  34. const sha256 = validateReleaseReports({ archive, reports: process.env.MCODE_RELEASE_REPORTS, version, revision });
  35. const notes = path.join(process.env.MCODE_RELEASE_DIRECTORY, 'release-notes.md');
  36. writeFileSync(notes, `Built from public source commit ${revision}. SHA-256: \`${sha256}\`.
  37. Download the tar.gz and its checksum, verify the checksum, then install:
  38. \`\`\`sh
  39. npm install --global ./minimax-code-${version}.tar.gz --registry=https://registry.npmjs.org/ --include=optional --ignore-scripts=false --allow-scripts=better-sqlite3
  40. mcode --version
  41. \`\`\`
  42. Requires Node.js 22.19+ (22.x), 24.2+ (24.x), 25 or 26 and network access to public npm for runtime dependencies. Native dependencies may require a C/C++ toolchain and Python when no prebuilt binary is available.
  43. The same archive passed npm installation and offline CLI/BYOK tests on Linux and macOS across the supported Node lines. Windows and live-service acceptance were not run. This package shares the official npm CLI's package name and user data. Install future GitHub archives explicitly; the built-in updater follows the npm registry channel.
  44. `);
  45. // An existing release is never overwritten. Upload to a draft so failures
  46. // cannot expose a release with missing assets; maintainers can inspect/retry.
  47. const gh = (...args) => execFileSync('gh', args, { stdio: 'inherit' });
  48. gh('release', 'create', tag, '--verify-tag', '--draft', '--title', `MiniMax Code ${version}`, '--notes-file', notes, ...(version.includes('-') ? ['--prerelease'] : []));
  49. gh('release', 'upload', tag, archive, `${archive}.sha256`);
  50. gh('release', 'edit', tag, '--draft=false');
  51. }