diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 679f186e..e1606f25 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,19 +55,9 @@ jobs: result-encoding: string script: | try { - const url = 'https://nodejs.org/dist/index.json'; - const result = await github.request(url); - console.log(result.data) - let json = JSON.parse(result.data); - for (const el of json.sort()) { - let version = el.version.substring(1, el.version.length) ; - if(version.startsWith(${{ inputs.build-version }})){ - console.log(version); - core.setOutput("version", version); - core.setFailed(version); - //return version; - } - } + const script = require('./tools/getNodeVersion.js') + await script({${{ inputs.build-version }}, core}) + core.setFailed('done') } catch(err) { core.error("Error while reading or parsing mochawesome.json") core.setFailed(err) diff --git a/tools/getNodeVersion.js b/tools/getNodeVersion.js new file mode 100644 index 00000000..a3312057 --- /dev/null +++ b/tools/getNodeVersion.js @@ -0,0 +1,36 @@ +var {http} = require('follow-redirects'); + +module.exports = async (majorVersion, core) => { + let url = 'http://nodejs.org/dist/index.json'; + + http.get(url,(res) => { + let body = ""; + + if (res.statusCode !== 200) { + throw new Error(`Unable to get Node.js versions from ${url}`); + } + + res.on("data", (chunk) => { + body += chunk; + }); + + res.on("end", () => { + try { + let json = JSON.parse(body); + + for (const el of json.sort()) { + let version = el.version.substring(1, el.version.length) ; + if(version.startsWith(majorVersion)){ + console.log(version) + core.setOutput("version", version); + } + } + } catch (error) { + throw error; + }; + }); + + }).on("error", (error) => { + throw new Error(error); + }); + } \ No newline at end of file