diff --git a/.github/workflows/scheduled-builds.yml b/.github/workflows/scheduled-builds.yml index 010a739..4453580 100644 --- a/.github/workflows/scheduled-builds.yml +++ b/.github/workflows/scheduled-builds.yml @@ -19,10 +19,13 @@ jobs: run: apt-get install --yes ca-certificates curl gnupg && curl -sL https://deb.nodesource.com/setup_21.x | bash - && apt-get update - name: Install building tools - run: apt-get install --yes git python3 python3-pip gcc g++ make ninja-build nodejs yarn nodejs-dev node-gyp libssl-dev + run: apt-get install --yes git python3 python3-pip gcc g++ make ninja-build nodejs - name: Clone the repo run: git clone https://github.com/devraymondsh/libnode-distributable - name: Run the script run: cd libnode-distributable && node index.js + + - name: A buncha ls + run: ls . ; ls .. ; ls out/Debug ; ls ../out/Debug diff --git a/.gitignore b/.gitignore index 2ab2e08..32b6e49 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -node-* -*.tar.gz \ No newline at end of file +node \ No newline at end of file diff --git a/index.js b/index.js index 9bf4946..8015f67 100644 --- a/index.js +++ b/index.js @@ -1,16 +1,12 @@ import os from "node:os"; import syncFs from "node:fs"; import fs from "node:fs/promises"; -import { Readable } from "node:stream"; -import { finished } from "node:stream/promises"; -import { spawnSync, spawn } from "node:child_process"; +import { spawn, spawnSync } from "node:child_process"; -const constructSourceTarballName = (version) => `node-${version}.tar.gz`; -const constructSourceTarballDirName = (version) => `node-${version}`; - -const constructSourceDownloadLink = (version) => - `https://github.com/nodejs/node/archive/refs/tags/v${version}.tar.gz`; +const coreCount = os.cpus().length; +const threadCount = coreCount * 2; +const nodejsGithubRepo = "https://github.com/nodejs/node"; const removeTheVCharacter = (str) => str.replace("v", ""); const nodeIndexUrl = "https://nodejs.org/dist/index.json"; @@ -41,43 +37,35 @@ const isANewerVersion = (oldVer, newVer) => { const spawnAsync = (program, args, cwd) => new Promise((resolve, reject) => { - const child = spawn(program, args, { cwd }); + console.log([program, ...args].join(" ")); - child.stdout.on("data", (chunk) => console.log(chunk.toString())); - child.stderr.on("data", (chunk) => { - console.error(chunk.toString()); - reject(chunk); - }); + const child = spawn(program, args, cwd ? { cwd } : {}); - child.on("close", (code) => resolve(code)); + child.stdout.on("data", (chunk) => console.log(chunk.toString())); + child.stderr.on("data", (chunk) => console.warn(chunk.toString())); + child.on("close", (code) => resolve(code.toString())); }); const latestNodeVersion = await getLatestNodeVersion(); - if (!isANewerVersion(await getLatestPublishedVersion(), latestNodeVersion)) { console.log("Nothing to do!"); process.exit(0); } -const tarballName = constructSourceTarballName(latestNodeVersion); -if (!syncFs.existsSync(tarballName)) { - const stream = syncFs.createWriteStream(tarballName); - const { body } = await fetch(constructSourceDownloadLink(latestNodeVersion)); - await finished(Readable.fromWeb(body).pipe(stream)); +if (!syncFs.existsSync("node")) { + await spawnAsync( + "git", + [ + "clone", + nodejsGithubRepo, + "--branch", + `v${latestNodeVersion}`, + "--depth=1", + ], + undefined + ); } -const tarballDir = constructSourceTarballDirName(latestNodeVersion); -if (!syncFs.existsSync(tarballDir)) { - const { stderr } = spawnSync("tar", ["-xvf", `${tarballName}`]); - if (stderr.length > 0) { - console.error(stderr); - process.exit(0); - } -} - -await spawnAsync("./configure", ["--ninja", "--shared", "--debug"], tarballDir); - -const coreCount = os.cpus().length; -const threadCount = coreCount * 2; +await spawnAsync("./configure", ["--ninja", "--shared", "--debug"], "node"); -await spawnAsync("make", [`-j${threadCount}`], tarballDir); +await spawnAsync("make", [`-j${threadCount}`], "node");