generate-tasks.js 4.1 KB

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