Skip to content

Commit 381cd01

Browse files
committed
Use Github to clone the Nodejs source
1 parent e5ba5a3 commit 381cd01

File tree

3 files changed

+28
-38
lines changed

3 files changed

+28
-38
lines changed

.github/workflows/scheduled-builds.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ jobs:
1919
run: apt-get install --yes ca-certificates curl gnupg && curl -sL https://deb.nodesource.com/setup_21.x | bash - && apt-get update
2020

2121
- name: Install building tools
22-
run: apt-get install --yes git python3 python3-pip gcc g++ make ninja-build nodejs yarn nodejs-dev node-gyp libssl-dev
22+
run: apt-get install --yes git python3 python3-pip gcc g++ make ninja-build nodejs
2323

2424
- name: Clone the repo
2525
run: git clone https://github.com/devraymondsh/libnode-distributable
2626

2727
- name: Run the script
2828
run: cd libnode-distributable && node index.js
29+
30+
- name: A buncha ls
31+
run: ls . ; ls .. ; ls out/Debug ; ls ../out/Debug

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
node-*
2-
*.tar.gz
1+
node

index.js

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import os from "node:os";
22
import syncFs from "node:fs";
33
import fs from "node:fs/promises";
4-
import { Readable } from "node:stream";
5-
import { finished } from "node:stream/promises";
6-
import { spawnSync, spawn } from "node:child_process";
4+
import { spawn, spawnSync } from "node:child_process";
75

8-
const constructSourceTarballName = (version) => `node-${version}.tar.gz`;
9-
const constructSourceTarballDirName = (version) => `node-${version}`;
10-
11-
const constructSourceDownloadLink = (version) =>
12-
`https://github.com/nodejs/node/archive/refs/tags/v${version}.tar.gz`;
6+
const coreCount = os.cpus().length;
7+
const threadCount = coreCount * 2;
138

9+
const nodejsGithubRepo = "https://github.com/nodejs/node";
1410
const removeTheVCharacter = (str) => str.replace("v", "");
1511

1612
const nodeIndexUrl = "https://nodejs.org/dist/index.json";
@@ -41,43 +37,35 @@ const isANewerVersion = (oldVer, newVer) => {
4137

4238
const spawnAsync = (program, args, cwd) =>
4339
new Promise((resolve, reject) => {
44-
const child = spawn(program, args, { cwd });
40+
console.log([program, ...args].join(" "));
4541

46-
child.stdout.on("data", (chunk) => console.log(chunk.toString()));
47-
child.stderr.on("data", (chunk) => {
48-
console.error(chunk.toString());
49-
reject(chunk);
50-
});
42+
const child = spawn(program, args, cwd ? { cwd } : {});
5143

52-
child.on("close", (code) => resolve(code));
44+
child.stdout.on("data", (chunk) => console.log(chunk.toString()));
45+
child.stderr.on("data", (chunk) => console.warn(chunk.toString()));
46+
child.on("close", (code) => resolve(code.toString()));
5347
});
5448

5549
const latestNodeVersion = await getLatestNodeVersion();
56-
5750
if (!isANewerVersion(await getLatestPublishedVersion(), latestNodeVersion)) {
5851
console.log("Nothing to do!");
5952
process.exit(0);
6053
}
6154

62-
const tarballName = constructSourceTarballName(latestNodeVersion);
63-
if (!syncFs.existsSync(tarballName)) {
64-
const stream = syncFs.createWriteStream(tarballName);
65-
const { body } = await fetch(constructSourceDownloadLink(latestNodeVersion));
66-
await finished(Readable.fromWeb(body).pipe(stream));
55+
if (!syncFs.existsSync("node")) {
56+
await spawnAsync(
57+
"git",
58+
[
59+
"clone",
60+
nodejsGithubRepo,
61+
"--branch",
62+
`v${latestNodeVersion}`,
63+
"--depth=1",
64+
],
65+
undefined
66+
);
6767
}
6868

69-
const tarballDir = constructSourceTarballDirName(latestNodeVersion);
70-
if (!syncFs.existsSync(tarballDir)) {
71-
const { stderr } = spawnSync("tar", ["-xvf", `${tarballName}`]);
72-
if (stderr.length > 0) {
73-
console.error(stderr);
74-
process.exit(0);
75-
}
76-
}
77-
78-
await spawnAsync("./configure", ["--ninja", "--shared", "--debug"], tarballDir);
79-
80-
const coreCount = os.cpus().length;
81-
const threadCount = coreCount * 2;
69+
await spawnAsync("./configure", ["--ninja", "--shared", "--debug"], "node");
8270

83-
await spawnAsync("make", [`-j${threadCount}`], tarballDir);
71+
await spawnAsync("make", [`-j${threadCount}`], "node");

0 commit comments

Comments
 (0)