Skip to content

Commit b0c3dcf

Browse files
committed
Change the caching strategy
1 parent 8ca333e commit b0c3dcf

File tree

7 files changed

+153
-62
lines changed

7 files changed

+153
-62
lines changed

.github/workflows/daily-check.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Daily check
2+
3+
on:
4+
schedule:
5+
- cron: "0 8 * * *"
6+
workflow_dispatch:
7+
8+
env:
9+
TAG: v0
10+
NOTHING_TO_DO: true
11+
12+
jobs:
13+
check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
fetch-tags: true
20+
persist-credentials: true
21+
22+
- name: Install building tools
23+
run: |
24+
sudo apt-get install --yes ca-certificates curl gnupg && curl -sL https://deb.nodesource.com/setup_21.x | sudo bash -
25+
sudo apt-get update && sudo apt-get install --yes nodejs
26+
27+
- name: Run the check script
28+
run: node daily-check.js
29+
30+
- name: Commit
31+
uses: EndBug/add-and-commit@v9
32+
if: ${{ env.NOTHING_TO_DO == 'false' }}
33+
with:
34+
author_name: Mahdi Sharifi
35+
message: "Add ${{ env.TAG }}"
36+
author_email: [email protected]
37+
github_token: ${{ secrets.ACCESS_TOKEN }}
38+
39+
- name: Release
40+
uses: ncipollo/release-action@v1
41+
if: ${{ env.NOTHING_TO_DO == 'false' }}
42+
with:
43+
commit: main
44+
allowUpdates: true
45+
tag: ${{ env.TAG }}
46+
generateReleaseNotes: false
47+
name: libnode ${{ env.TAG }}
48+
token: ${{ secrets.ACCESS_TOKEN }}
49+
body: "Changelog: https://github.com/nodejs/node/releases/tag/${{ env.TAG }}"

.github/workflows/linux-daily-check.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Linux
22

33
on:
4-
schedule:
5-
- cron: "0 8 * * *"
6-
workflow_dispatch:
4+
push:
5+
tags:
6+
- "v*"
77

88
jobs:
99
update:
@@ -24,7 +24,10 @@ jobs:
2424
with:
2525
path: .ccache
2626
save-always: true
27-
key: ${{ github.workflow }}-${{ matrix.arch }}
27+
key: ${{ github.workflow }}-${{ matrix.arch }}-${{ hashFiles('**/version.txt') }}
28+
restore-keys: |
29+
${{ github.workflow }}-${{ matrix.arch }}-${{ hashFiles('**/version.txt') }}
30+
${{ github.workflow }}-${{ matrix.arch }}-
2831
2932
- name: Install building tools
3033
run: |
@@ -52,5 +55,16 @@ jobs:
5255
5356
node index.js
5457
55-
- name: Find the shared library
56-
run: ls node/out/Release
58+
- name: Create archive
59+
run: |
60+
cd node/out/Release
61+
ln libnode.so.* libnode.so
62+
tar -cJf "libnode-${{ matrix.arch }}-linux.tar.xz" libnode.* node
63+
64+
- name: Upload binaries to release
65+
uses: svenstaro/upload-release-action@v2
66+
with:
67+
overwrite: true
68+
tag: ${{ github.ref }}
69+
repo_token: ${{ secrets.GITHUB_TOKEN }}
70+
file: node/out/Release/libnode-${{ matrix.arch }}-linux.tar.xz

.github/workflows/macos-daily-check.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Macos
22

33
on:
4-
schedule:
5-
- cron: "0 8 * * *"
6-
workflow_dispatch:
4+
push:
5+
tags:
6+
- "v*"
77

88
jobs:
99
update:
@@ -25,7 +25,10 @@ jobs:
2525
with:
2626
path: .ccache
2727
save-always: true
28-
key: ${{ github.workflow }}-${{ matrix.arch }}
28+
key: ${{ github.workflow }}-${{ matrix.arch }}-${{ hashFiles('**/version.txt') }}
29+
restore-keys: |
30+
${{ github.workflow }}-${{ matrix.arch }}-${{ hashFiles('**/version.txt') }}
31+
${{ github.workflow }}-${{ matrix.arch }}-
2932
3033
- name: Install building tools
3134
run: |
@@ -55,5 +58,16 @@ jobs:
5558
5659
node index.js
5760
58-
- name: Find the shared library
59-
run: ls node/out/Release
61+
- name: Create archive
62+
run: |
63+
cd node/out/Release
64+
ln libnode.* libnode.dylib
65+
tar -cJf "libnode-${{ matrix.arch }}-linux.tar.xz" libnode.* node
66+
67+
- name: Upload binaries to release
68+
uses: svenstaro/upload-release-action@v2
69+
with:
70+
overwrite: true
71+
tag: ${{ github.ref }}
72+
repo_token: ${{ secrets.GITHUB_TOKEN }}
73+
file: node/out/Release/libnode-${{ matrix.arch }}-macos.tar.xz

.github/workflows/windows-daily-check.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Windows
22

33
on:
4-
schedule:
5-
- cron: "0 8 * * *"
6-
workflow_dispatch:
4+
push:
5+
tags:
6+
- "v*"
77

88
jobs:
99
update:
@@ -28,12 +28,22 @@ jobs:
2828
scoop_update: true
2929

3030
- name: Install building tools
31-
run: scoop install git nodejs python ninja nasm
31+
run: scoop install git nodejs python ninja nasm 7zip
3232

3333
- name: Run the script
3434
env:
3535
ARCH: ${{ matrix.arch }}
3636
run: node index.js
3737

38-
- name: Find the shared library
39-
run: dir node\out\Release\node.lib
38+
- name: Create archive
39+
run: |
40+
cd node\out\Release
41+
tar.exe -a -c -f "libnode-${{ matrix.arch }}-windows.zip" libnode.* node.*
42+
43+
- name: Upload binaries to release
44+
uses: svenstaro/upload-release-action@v2
45+
with:
46+
overwrite: true
47+
tag: ${{ github.ref }}
48+
repo_token: ${{ secrets.GITHUB_TOKEN }}
49+
file: node\out\Release\libnode-${{ matrix.arch }}-windows.zip

daily-check.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import fs from "node:fs/promises";
2+
import { execSync } from "node:child_process";
3+
4+
const nodejsGithubRepo = "https://github.com/nodejs/node";
5+
const removeTheVCharacter = (str) => str.replace("v", "");
6+
7+
const nodeIndexUrl = "https://nodejs.org/dist/index.json";
8+
const getLatestNodeVersion = async () => {
9+
const res = await fetch(nodeIndexUrl);
10+
const jsonData = await res.json();
11+
12+
return removeTheVCharacter(jsonData[0]["version"]);
13+
};
14+
15+
const getLatestPublishedVersion = async () =>
16+
removeTheVCharacter(await fs.readFile("version.txt", { encoding: "utf8" }));
17+
18+
const isANewerVersion = (oldVer, newVer) => {
19+
const oldParts = oldVer.split(".");
20+
const newParts = newVer.split(".");
21+
22+
for (var i = 0; i < newParts.length; i++) {
23+
const a = ~~newParts[i]; // parse int
24+
const b = ~~oldParts[i]; // parse int
25+
26+
if (a > b) return true;
27+
if (a < b) return false;
28+
}
29+
30+
return false;
31+
};
32+
33+
const latestNodeVersion = await getLatestNodeVersion();
34+
const latestPublishedVersion = await getLatestPublishedVersion();
35+
if (!isANewerVersion(latestPublishedVersion, latestNodeVersion)) {
36+
console.log("Nothing to do!");
37+
process.exit(0);
38+
}
39+
40+
execSync(`echo "NOTHING_TO_DO=false" >> $GITHUB_ENV`);
41+
execSync(`echo "TAG=v${latestNodeVersion}" >> $GITHUB_ENV`);
42+
43+
await fs.writeFile("version.txt", `v${latestNodeVersion}`);

index.js

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { cpus } from "node:os";
33
import fs from "node:fs/promises";
44
import { spawn } from "node:child_process";
55

6+
const nodejsGithubRepo = "https://github.com/nodejs/node";
7+
68
let OS = process.env.OS;
79
const ARCH = process.env.ARCH == "amd64" ? "x64" : "arm64";
810

@@ -20,38 +22,8 @@ switch (process.platform) {
2022
current_os = "linux";
2123
break;
2224
}
23-
2425
if (!OS) OS = current_os;
2526

26-
const nodejsGithubRepo = "https://github.com/nodejs/node";
27-
const removeTheVCharacter = (str) => str.replace("v", "");
28-
29-
const nodeIndexUrl = "https://nodejs.org/dist/index.json";
30-
const getLatestNodeVersion = async () => {
31-
const res = await fetch(nodeIndexUrl);
32-
const jsonData = await res.json();
33-
34-
return removeTheVCharacter(jsonData[0]["version"]);
35-
};
36-
37-
const getLatestPublishedVersion = async () =>
38-
removeTheVCharacter(await fs.readFile("version.txt", { encoding: "utf8" }));
39-
40-
const isANewerVersion = (oldVer, newVer) => {
41-
const oldParts = oldVer.split(".");
42-
const newParts = newVer.split(".");
43-
44-
for (var i = 0; i < newParts.length; i++) {
45-
const a = ~~newParts[i]; // parse int
46-
const b = ~~oldParts[i]; // parse int
47-
48-
if (a > b) return true;
49-
if (a < b) return false;
50-
}
51-
52-
return false;
53-
};
54-
5527
const spawnAsync = (program, args) =>
5628
new Promise((resolve, reject) => {
5729
console.log("Running:", [program, ...args].join(" "));
@@ -66,22 +38,11 @@ const spawnAsync = (program, args) =>
6638
});
6739
});
6840

69-
const latestNodeVersion = await getLatestNodeVersion();
70-
if (!isANewerVersion(await getLatestPublishedVersion(), latestNodeVersion)) {
71-
console.log("Nothing to do!");
72-
process.exit(0);
73-
}
74-
41+
const version = await fs.readFile("version.txt", { encoding: "utf8" });
7542
if (!syncFs.existsSync("node")) {
7643
await spawnAsync(
7744
"git",
78-
[
79-
"clone",
80-
nodejsGithubRepo,
81-
"--branch",
82-
`v${latestNodeVersion}`,
83-
"--depth=1",
84-
],
45+
["clone", nodejsGithubRepo, "--branch", version, "--depth=1"],
8546
undefined,
8647
{}
8748
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "libnode-distributable",
2+
"name": "libnode",
33
"type": "module",
44
"description": "",
55
"version": "1.0.0",

0 commit comments

Comments
 (0)