rolling-release-binary-upload.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Inspired by Atom's original Nightly Release Script:
  2. // https://github.com/atom/atom/blob/master/script/vsts/upload-artifacts.js
  3. const fs = require("fs");
  4. const path = require("path");
  5. const publish = require("publish-release");
  6. const packageJson = require("../../package.json");
  7. // Since cirrus always triggers this script, we must check if the version is a rolling
  8. // release version
  9. const verSegments = packageJson.version.split(".");
  10. const lastVerSegment = verSegments[verSegments.length - 1];
  11. if (lastVerSegment.length < 4 || lastVerSegment.includes('-dev')) {
  12. console.log(`According to our version: ${packageJson.version} this is not a rolling release...`);
  13. console.log("Exiting without changes...");
  14. process.exit(0);
  15. }
  16. // Again since cirrus ALWAYS triggers this script, without being able to skip for
  17. // non PR builds, Cirrus provides cli args to indicate that it is being run via cirrus,
  18. // so we can exit depending on the presence of certain env vars
  19. let cirrusFlag = process.argv.slice(2)[0];
  20. if (cirrusFlag === "cirrus") {
  21. if (typeof process.env.CIRRUS_CRON != "string") {
  22. // This build is the result of a PR or commit, not a cron job rolling release,
  23. // lets exit
  24. console.log("Due to the absence of `CIRRUS_CRON` it seems this is not a rolling release...");
  25. console.log("Exiting without uploading binaries...");
  26. process.exit(0);
  27. }
  28. }
  29. (async () => {
  30. if (!fs.existsSync("../../binaries")) {
  31. console.log("No binaries found! Exiting...");
  32. process.exit(1);
  33. }
  34. let binaryAssets = [];
  35. let files = fs.readdirSync("../../binaries");
  36. for (const file of files) {
  37. binaryAssets.push(path.resolve(`../../binaries/${file}`));
  38. }
  39. console.log(`Uploading local binaries to rolling release repo: ${binaryAssets.join(",")}`);
  40. // ROLLING_UPLOAD_TOKEN:
  41. // - Assigned within Cirrus via encrypted variables
  42. // - Assigned within GitHub Actions via secrets API
  43. // - GITHUB_TOKEN as fallback
  44. publish({
  45. token: process.env.ROLLING_UPLOAD_TOKEN || process.env.GITHUB_TOKEN,
  46. owner: "pulsar-edit",
  47. repo: "pulsar-rolling-releases",
  48. name: packageJson.version,
  49. notes: `Rolling Release: ${packageJson.version}`,
  50. tag: `v${packageJson.version}`,
  51. draft: false,
  52. prerelease: false,
  53. editRelease: true,
  54. reuseRelease: true,
  55. skipIfPublished: false,
  56. assets: binaryAssets
  57. }, (err, release) => {
  58. if (err) {
  59. console.error(err);
  60. process.exit(1);
  61. }
  62. if (typeof release?.html_url !== "string") {
  63. console.error("No 'html_url' found on release object!");
  64. console.error(release);
  65. process.exit(1);
  66. } else {
  67. console.log(`Releases published successfully: ${release.html_url}`);
  68. process.exit(0);
  69. }
  70. });
  71. })();