11import { promisify } from 'util' ;
2+ import { readdirSync , readFileSync } from 'node:fs' ;
3+ import { join } from 'node:path' ;
24
35import child_process from 'child_process' ;
46
@@ -7,40 +9,38 @@ const exec = promisify(child_process.exec);
79// a function that queries the Node.js release website for new versions,
810// compare the available ones with the ones we use in this repo
911// and returns whether we should update or not
10- const checkIfThereAreNewVersions = async ( github ) => {
12+ const checkIfThereAreNewVersions = async ( ) => {
1113 try {
12- const { stdout : versionsOutput } = await exec (
13- '. ./functions.sh && get_versions' ,
14- { shell : 'bash' } ,
15- ) ;
16-
17- const supportedVersions = versionsOutput . trim ( ) . split ( ' ' ) ;
14+ let files = readdirSync ( './' ) ;
15+ // get the folders with a digit, assuming they're the Node.js major versions
16+ const supportedVersions = files . filter ( ( file ) => {
17+ return file . match ( / \d / ) ;
18+ } ) ;
1819
1920 let latestSupportedVersions = { } ;
2021
2122 for ( let supportedVersion of supportedVersions ) {
22- const { stdout } = await exec ( `ls ${ supportedVersion } ` ) ;
23-
24- const { stdout : fullVersionOutput } = await exec (
25- `. ./functions.sh && get_full_version ./${ supportedVersion } /${ stdout . trim ( ) . split ( '\n' ) [ 0 ] } ` ,
26- { shell : 'bash' } ,
23+ // Grab the Alpine folder, to assume it is more likely to be behind after a Security release
24+ const alpinefolder = readdirSync ( join ( '.' , supportedVersion ) ) . find (
25+ ( folder ) => folder . startsWith ( 'alpine' ) ,
2726 ) ;
2827
29- console . log ( fullVersionOutput ) ;
28+ const fullVersionOutput = readFileSync (
29+ join ( '.' , supportedVersion , alpinefolder , 'Dockerfile' ) ,
30+ 'utf-8' ,
31+ ) ;
3032
3133 latestSupportedVersions [ supportedVersion ] = {
32- fullVersion : fullVersionOutput . trim ( ) ,
34+ fullVersion : fullVersionOutput . match (
35+ / N O D E _ V E R S I O N = (?< version > \d * \. \d * \. \d ) / ,
36+ ) . groups [ 'version' ] ,
3337 } ;
3438 }
3539
36- const { data : availableVersionsJson } = await github . request (
40+ const availableVersions = await fetch (
3741 'https://nodejs.org/download/release/index.json' ,
3842 ) ;
39-
40- // filter only more recent versions of availableVersionsJson for each major version in latestSupportedVersions' keys
41- // e.g. if latestSupportedVersions = { "12": "12.22.10", "14": "14.19.0", "16": "16.14.0", "17": "17.5.0" }
42- // and availableVersions = ["Node.js 12.22.10", "Node.js 12.24.0", "Node.js 14.19.0", "Node.js 14.22.0", "Node.js 16.14.0", "Node.js 16.16.0", "Node.js 17.5.0", "Node.js 17.8.0"]
43- // return { "12": "12.24.0", "14": "14.22.0", "16": "16.16.0", "17": "17.8.0" }
43+ const availableVersionsJson = await availableVersions . json ( ) ;
4444
4545 let filteredNewerVersions = { } ;
4646
@@ -60,6 +60,7 @@ const checkIfThereAreNewVersions = async (github) => {
6060 ) {
6161 filteredNewerVersions [ availableMajor ] = {
6262 fullVersion : `${ availableMajor } .${ availableMinor } .${ availablePatch } ` ,
63+ isSecurityRelease : availableVersion . security ,
6364 } ;
6465 }
6566 }
@@ -79,11 +80,12 @@ const checkIfThereAreNewVersions = async (github) => {
7980
8081// a function that queries the Node.js unofficial release website for new musl versions and security releases,
8182// and returns relevant information
82- const checkForMuslVersionsAndSecurityReleases = async ( github , versions ) => {
83+ const checkForMuslVersionsAndSecurityReleases = async ( versions ) => {
8384 try {
84- const { data : unofficialBuildsIndexText } = await github . request (
85+ const unofficialBuildsIndex = await fetch (
8586 'https://unofficial-builds.nodejs.org/download/release/index.json' ,
8687 ) ;
88+ const unofficialBuildsIndexText = await unofficialBuildsIndex . json ( ) ;
8789
8890 for ( let version of Object . keys ( versions ) ) {
8991 const buildVersion = unofficialBuildsIndexText . find (
@@ -93,7 +95,6 @@ const checkForMuslVersionsAndSecurityReleases = async (github, versions) => {
9395
9496 versions [ version ] . muslBuildExists =
9597 buildVersion ?. files . includes ( 'linux-x64-musl' ) ?? false ;
96- versions [ version ] . isSecurityRelease = buildVersion ?. security ?? false ;
9798 }
9899 return versions ;
99100 } catch ( error ) {
@@ -102,24 +103,22 @@ const checkForMuslVersionsAndSecurityReleases = async (github, versions) => {
102103 }
103104} ;
104105
105- export default async function ( github ) {
106+ export default async function ( ) {
106107 // if there are no new versions, exit gracefully
107108 // if there are new versions,
108109 // check for musl builds
109110 // then run update.sh
110- const { shouldUpdate, versions } = await checkIfThereAreNewVersions ( github ) ;
111+ const { shouldUpdate, versions } = await checkIfThereAreNewVersions ( ) ;
111112
112113 if ( ! shouldUpdate ) {
113114 console . log ( 'No new versions found. No update required.' ) ;
114115 process . exit ( 0 ) ;
115116 } else {
116- const newVersions = await checkForMuslVersionsAndSecurityReleases (
117- github ,
118- versions ,
119- ) ;
117+ const newVersions = await checkForMuslVersionsAndSecurityReleases ( versions ) ;
120118 let updatedVersions = [ ] ;
121119 for ( const [ version , newVersion ] of Object . entries ( newVersions ) ) {
122- if ( newVersion . muslBuildExists ) {
120+ if ( newVersion . muslBuildExists || newVersion . isSecurityRelease ) {
121+ console . log ( `Updating ${ newVersion . fullVersion } .` ) ;
123122 const { stdout } = await exec (
124123 `./update.sh ${ newVersion . isSecurityRelease ? '-s ' : '' } ${ version } ` ,
125124 ) ;
@@ -132,9 +131,6 @@ export default async function (github) {
132131 process . exit ( 0 ) ;
133132 }
134133 }
135- const { stdout } = await exec ( `git diff` ) ;
136- console . log ( stdout ) ;
137-
138134 return updatedVersions . join ( ', ' ) ;
139135 }
140136}
0 commit comments