generate-tasks.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  2. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  3. return new (P || (P = Promise))(function (resolve, reject) {
  4. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  5. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  6. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  7. step((generator = generator.apply(thisArg, _arguments || [])).next());
  8. });
  9. };
  10. import { writeFileSync } from 'fs.js';
  11. import { dump } from 'js-yaml.js';
  12. import fetch from 'node-fetch.js';
  13. import { join } from 'path.js';
  14. const minVersion = 64;
  15. (() => __awaiter(void 0, void 0, void 0, function* () {
  16. const res = yield fetch('https://nodejs.org/dist/index.json');
  17. if (!res.ok) {
  18. throw new Error(`${res.status} error from Node.js releases page`);
  19. }
  20. const releases = yield res.json();
  21. const buildVersion = new Map();
  22. const versionMap = {};
  23. for (const release of releases) {
  24. const moduleVersion = Number(release.modules);
  25. if (!moduleVersion || moduleVersion < minVersion) {
  26. break;
  27. }
  28. versionMap[release.version] = Number(moduleVersion);
  29. if (buildVersion.has(moduleVersion)) {
  30. continue;
  31. }
  32. buildVersion.set(moduleVersion, release.version);
  33. }
  34. const buildYaml = {
  35. name: 'Generate Binaries',
  36. on: {
  37. push: {
  38. branches: ['generate-binary'],
  39. },
  40. },
  41. jobs: {
  42. build: {
  43. name: 'Build',
  44. 'runs-on': '${{ matrix.os }}',
  45. strategy: {
  46. matrix: { os: ['macos-latest', 'ubuntu-latest', 'windows-latest'] },
  47. },
  48. steps: [
  49. { uses: 'actions/checkout@master' },
  50. { run: 'mkdir dist' },
  51. {
  52. uses: 'actions-rs/toolchain@v1',
  53. with: { target: 'wasm32-unknown-unknown', toolchain: 'nightly' },
  54. },
  55. ...[...buildVersion.entries()]
  56. .map(([moduleVersion, nodeVersion], i) => [
  57. { uses: 'actions/setup-node@v1', with: { 'node-version': nodeVersion } },
  58. {
  59. // See: https://github.com/actions/setup-node/issues/68
  60. shell: 'powershell',
  61. name: 'patch node-gyp for VS 2019',
  62. run: 'npm install --global node-gyp@latest\r\nnpm prefix -g | % {npm config set node_gyp "$_\\node_modules\\node-gyp\\bin\\node-gyp.js"}',
  63. if: "matrix.os == 'windows-latest'",
  64. },
  65. i === 0
  66. ? { run: 'npm install neon-cli rimraf' }
  67. : { run: './node_modules/.bin/rimraf rs/native/target' },
  68. { run: '../node_modules/.bin/neon build --release', 'working-directory': 'rs' },
  69. { run: `mv rs/native/index.node dist/\${{ matrix.os }}-${moduleVersion}.node` },
  70. ])
  71. .reduce((acc, v) => [...acc, ...v], []),
  72. {
  73. uses: 'actions/upload-artifact@v1',
  74. with: { name: 'dist', path: 'dist' },
  75. },
  76. ],
  77. },
  78. },
  79. };
  80. writeFileSync(join(__dirname, '..', '..', '.github', 'workflows', 'build-neon.yml'), dump(buildYaml));
  81. writeFileSync(join(__dirname, '..', '..', 'targets.json'), JSON.stringify(versionMap));
  82. }))();
  83. //# sourceMappingURL=generate-tasks.js.map