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,29 @@ 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+ // Grab the Alpine folder, to assume it is more likely to be behind after a Security release
24+ const alpinefolder = readdirSync ( join ( '.' , supportedVersion ) ) . find ( folder => folder . startsWith ( 'alpine' ) )
2325
24- const { stdout : fullVersionOutput } = await exec (
25- `. ./functions.sh && get_full_version ./${ supportedVersion } /${ stdout . trim ( ) . split ( '\n' ) [ 0 ] } ` ,
26- { shell : 'bash' } ,
27- ) ;
28-
29- console . log ( fullVersionOutput ) ;
26+ const fullVersionOutput = readFileSync ( join ( '.' , supportedVersion , alpinefolder , 'Dockerfile' ) , 'utf-8' )
3027
3128 latestSupportedVersions [ supportedVersion ] = {
32- fullVersion : fullVersionOutput . trim ( ) ,
29+ fullVersion : fullVersionOutput . match ( / N O D E _ V E R S I O N = (?< version > \d * \. \d * \. \d ) / ) . groups [ 'version' ] ,
3330 } ;
3431 }
3532
36- const { data : availableVersionsJson } = await github . request (
37- 'https://nodejs.org/download/release/index.json' ,
38- ) ;
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" }
33+ const availableVersions = await fetch ( 'https://nodejs.org/download/release/index.json' )
34+ const availableVersionsJson = await availableVersions . json ( )
4435
4536 let filteredNewerVersions = { } ;
4637
@@ -60,6 +51,7 @@ const checkIfThereAreNewVersions = async (github) => {
6051 ) {
6152 filteredNewerVersions [ availableMajor ] = {
6253 fullVersion : `${ availableMajor } .${ availableMinor } .${ availablePatch } ` ,
54+ isSecurityRelease : availableVersion . security
6355 } ;
6456 }
6557 }
@@ -79,11 +71,10 @@ const checkIfThereAreNewVersions = async (github) => {
7971
8072// a function that queries the Node.js unofficial release website for new musl versions and security releases,
8173// and returns relevant information
82- const checkForMuslVersionsAndSecurityReleases = async ( github , versions ) => {
74+ const checkForMuslVersionsAndSecurityReleases = async ( versions ) => {
8375 try {
84- const { data : unofficialBuildsIndexText } = await github . request (
85- 'https://unofficial-builds.nodejs.org/download/release/index.json' ,
86- ) ;
76+ const unofficialBuildsIndex = await fetch ( 'https://unofficial-builds.nodejs.org/download/release/index.json' )
77+ const unofficialBuildsIndexText = await unofficialBuildsIndex . json ( )
8778
8879 for ( let version of Object . keys ( versions ) ) {
8980 const buildVersion = unofficialBuildsIndexText . find (
@@ -93,7 +84,6 @@ const checkForMuslVersionsAndSecurityReleases = async (github, versions) => {
9384
9485 versions [ version ] . muslBuildExists =
9586 buildVersion ?. files . includes ( 'linux-x64-musl' ) ?? false ;
96- versions [ version ] . isSecurityRelease = buildVersion ?. security ?? false ;
9787 }
9888 return versions ;
9989 } catch ( error ) {
@@ -102,24 +92,26 @@ const checkForMuslVersionsAndSecurityReleases = async (github, versions) => {
10292 }
10393} ;
10494
105- export default async function ( github ) {
95+ export default async function ( ) {
10696 // if there are no new versions, exit gracefully
10797 // if there are new versions,
10898 // check for musl builds
10999 // then run update.sh
110- const { shouldUpdate, versions } = await checkIfThereAreNewVersions ( github ) ;
100+ const { shouldUpdate, versions } = await checkIfThereAreNewVersions ( ) ;
111101
112102 if ( ! shouldUpdate ) {
113103 console . log ( 'No new versions found. No update required.' ) ;
114104 process . exit ( 0 ) ;
115105 } else {
116106 const newVersions = await checkForMuslVersionsAndSecurityReleases (
117- github ,
118107 versions ,
119108 ) ;
120109 let updatedVersions = [ ] ;
121110 for ( const [ version , newVersion ] of Object . entries ( newVersions ) ) {
122- if ( newVersion . muslBuildExists ) {
111+ if ( newVersion . muslBuildExists || newVersion . isSecurityRelease ) {
112+ console . log (
113+ `Updating ${ newVersion . fullVersion } .` ,
114+ ) ;
123115 const { stdout } = await exec (
124116 `./update.sh ${ newVersion . isSecurityRelease ? '-s ' : '' } ${ version } ` ,
125117 ) ;
@@ -132,9 +124,6 @@ export default async function (github) {
132124 process . exit ( 0 ) ;
133125 }
134126 }
135- const { stdout } = await exec ( `git diff` ) ;
136- console . log ( stdout ) ;
137-
138127 return updatedVersions . join ( ', ' ) ;
139128 }
140129}
0 commit comments