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