From d792f6c9bf6472e51b9eaa9d92d198403136a439 Mon Sep 17 00:00:00 2001 From: Henrique Pinheiro Date: Fri, 24 May 2024 11:47:05 +0100 Subject: [PATCH] ci: move updateVersions script to folder, enable sorting and improve logging --- .github/workflows/update-versions.yml | 3 +++ updateVersionsAction/package-lock.json | 27 +++++++++++++++++++ updateVersionsAction/package.json | 15 +++++++++++ .../updateVersions.mjs | 17 +++++++----- 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 updateVersionsAction/package-lock.json create mode 100644 updateVersionsAction/package.json rename updateVersions.mjs => updateVersionsAction/updateVersions.mjs (69%) diff --git a/.github/workflows/update-versions.yml b/.github/workflows/update-versions.yml index 07c7e0d..72e58a4 100644 --- a/.github/workflows/update-versions.yml +++ b/.github/workflows/update-versions.yml @@ -14,9 +14,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - run: cd updateVersionsAction - uses: actions/setup-node@v4 with: node-version: 20 + - name: Install node dependencies + run: npm install - run: node updateVersions.mjs - name: Create Pull Request uses: peter-evans/create-pull-request@v6 diff --git a/updateVersionsAction/package-lock.json b/updateVersionsAction/package-lock.json new file mode 100644 index 0000000..04ef1cf --- /dev/null +++ b/updateVersionsAction/package-lock.json @@ -0,0 +1,27 @@ +{ + "name": "asdf-dotnet-release-action", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "asdf-dotnet-release-action", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "semver": "^7.6.2" + } + }, + "node_modules/semver": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", + "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + } + } +} diff --git a/updateVersionsAction/package.json b/updateVersionsAction/package.json new file mode 100644 index 0000000..eaee228 --- /dev/null +++ b/updateVersionsAction/package.json @@ -0,0 +1,15 @@ +{ + "name": "asdf-dotnet-release-action", + "version": "1.0.0", + "description": "", + "type": "module", + "main": "updateVersions.mjs", + "scripts": { + "start": "node updateVersions.mjs" + }, + "author": "", + "license": "ISC", + "dependencies": { + "semver": "^7.6.2" + } +} diff --git a/updateVersions.mjs b/updateVersionsAction/updateVersions.mjs similarity index 69% rename from updateVersions.mjs rename to updateVersionsAction/updateVersions.mjs index 8579757..a8235bf 100644 --- a/updateVersions.mjs +++ b/updateVersionsAction/updateVersions.mjs @@ -1,9 +1,12 @@ import { writeFile } from "fs/promises"; +import parse from "semver/functions/parse.js"; +import compare from "semver/functions/compare.js"; (async () => { const channelReleasesURL = "https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases-index.json"; + console.info("fetching channel releases"); const res = await fetch(channelReleasesURL); const data = await res.json(); const channelReleases = data["releases-index"]; @@ -15,6 +18,9 @@ import { writeFile } from "fs/promises"; const releasesURL = channelRelease["releases.json"]; const res = await fetch(releasesURL); const data = await res.json(); + console.info( + `extracting versions from channel-version=${data["channel-version"]}`, + ); const releasesSdks = data["releases"].flatMap((r) => { if ("sdks" in r && r["sdks"] != null) { return r.sdks; @@ -28,12 +34,11 @@ import { writeFile } from "fs/promises"; versions.push(...sdkVersions); }, Promise.resolve()); - const content = - versions - .flatMap((v) => v) - .reverse() - .join("\n") + "\n"; - await writeFile("versions.txt", content, { + const content = versions.flatMap(parse).sort(compare).join("\n") + "\n"; + + console.info(`writing versions.txt file`); + await writeFile("../versions.txt", content, { flag: "w+", }); + console.info(`done`); })();