From 59dc8f64baa84ed1f17e896542611104f97117ec Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 15 Aug 2022 12:18:51 +0200 Subject: [PATCH] build: add node schedule updater (#17181) * build: add node schedule updater * ci: update generation job --- .github/workflows/update-data.yml | 4 ++++ package.json | 5 +++-- .../generate-azure-pipelines-tasks.mjs} | 4 +++- .../generate-distro-info.mjs} | 18 ++---------------- tools/static-data/generate-node-schedule.mjs | 12 ++++++++++++ tools/static-data/utils.mjs | 17 +++++++++++++++++ 6 files changed, 41 insertions(+), 19 deletions(-) rename tools/{azure-pipelines-tasks-json-generate.mjs => static-data/generate-azure-pipelines-tasks.mjs} (93%) rename tools/{distro-json-generate.mjs => static-data/generate-distro-info.mjs} (80%) create mode 100644 tools/static-data/generate-node-schedule.mjs create mode 100644 tools/static-data/utils.mjs diff --git a/.github/workflows/update-data.yml b/.github/workflows/update-data.yml index 3ba4ab312b1d79..e754113d568b7b 100644 --- a/.github/workflows/update-data.yml +++ b/.github/workflows/update-data.yml @@ -29,6 +29,9 @@ jobs: - name: Update data run: yarn run update-static-data + - name: prettify + run: yarn prettier-fix + - name: Create Pull Request uses: peter-evans/create-pull-request@923ad837f191474af6b1721408744feb989a4c27 # tag=v4.0.4 with: @@ -37,3 +40,4 @@ jobs: commit-message: 'fix(data): automatic update of static data' committer: 'Renovate Bot ' title: 'fix(data): automatic update of static data' + assignees: rarkins,viceice diff --git a/package.json b/package.json index e0658c06dd99dd..f0b4ed712a4716 100644 --- a/package.json +++ b/package.json @@ -52,8 +52,9 @@ "tsc": "tsc", "type-check": "run-s generate:* \"tsc --noEmit {@}\" --", "update-static-data": "run-s update-static-data:*", - "update-static-data:distro-info": "node tools/distro-json-generate.mjs", - "update-static-data:azure-pipelines-tasks": "node tools/azure-pipelines-tasks-json-generate.mjs", + "update-static-data:distro-info": "node tools/static-data/generate-distro-info.mjs", + "update-static-data:azure-pipelines-tasks": "node tools/static-data/generate-azure-pipelines-tasks.mjs", + "update-static-data:node-schedule": "node tools/static-data/generate-node-schedule.mjs", "verify": "node tools/verify.mjs" }, "repository": { diff --git a/tools/azure-pipelines-tasks-json-generate.mjs b/tools/static-data/generate-azure-pipelines-tasks.mjs similarity index 93% rename from tools/azure-pipelines-tasks-json-generate.mjs rename to tools/static-data/generate-azure-pipelines-tasks.mjs index a9284587761ea3..09bfa0e36500ed 100644 --- a/tools/azure-pipelines-tasks-json-generate.mjs +++ b/tools/static-data/generate-azure-pipelines-tasks.mjs @@ -6,6 +6,7 @@ import JSON5 from 'json5'; import shell from 'shelljs'; import Git from 'simple-git'; import path from 'upath'; +import { updateJsonFile } from './utils.mjs'; const glob = promisify(g); const localPath = path.join(os.tmpdir(), 'azure-pipelines-tasks'); @@ -19,6 +20,7 @@ const localPath = path.join(os.tmpdir(), 'azure-pipelines-tasks'); * 5. After all the `task.json` files have been processed it writes the results to `./data/azure-pipelines-tasks.json` */ await (async () => { + shell.echo('Generating azure pipelines tasks'); await fs.ensureDir(localPath); const git = Git(localPath); @@ -66,5 +68,5 @@ await (async () => { 2 ); - await fs.writeFile(`./data/azure-pipelines-tasks.json`, data); + await updateJsonFile(`./data/azure-pipelines-tasks.json`, data); })(); diff --git a/tools/distro-json-generate.mjs b/tools/static-data/generate-distro-info.mjs similarity index 80% rename from tools/distro-json-generate.mjs rename to tools/static-data/generate-distro-info.mjs index e08bdcdee70024..cedd4bacb4ccd5 100644 --- a/tools/distro-json-generate.mjs +++ b/tools/static-data/generate-distro-info.mjs @@ -1,6 +1,6 @@ -import fs from 'fs-extra'; import got from 'got'; import shell from 'shelljs'; +import { updateJsonFile } from './utils.mjs'; const ubuntuUrl = 'https://debian.pages.debian.net/distro-info-data/ubuntu.csv'; const debianUrl = 'https://debian.pages.debian.net/distro-info-data/debian.csv'; @@ -47,21 +47,6 @@ function csvToJson(raw) { return JSON.stringify(res, undefined, 2); } -/** - * Update given file with new provided data. - * @param {string} file Path to a data file - * @param {string} newData New data to be written - */ -async function updateJsonFile(file, newData) { - try { - shell.echo(`Updating ${file}`); - await fs.writeFile(file, newData); - } catch (e) { - shell.echo(e.toString()); - shell.exit(1); - } -} - /** * Fetch CSV and update data file. * @param {string} url Url to CSV @@ -75,6 +60,7 @@ async function update(url, file) { } await (async () => { + shell.echo('Generating distro info'); await update(ubuntuUrl, `./data/ubuntu-distro-info.json`); await update(debianUrl, `./data/debian-distro-info.json`); })(); diff --git a/tools/static-data/generate-node-schedule.mjs b/tools/static-data/generate-node-schedule.mjs new file mode 100644 index 00000000000000..b3cd175aa83617 --- /dev/null +++ b/tools/static-data/generate-node-schedule.mjs @@ -0,0 +1,12 @@ +import got from 'got'; +import shell from 'shelljs'; +import { updateJsonFile } from './utils.mjs'; + +const dataUrl = + 'https://raw.githubusercontent.com/nodejs/LTS/HEAD/schedule.json'; + +await (async () => { + shell.echo('Generating node schedule'); + const { body } = await got(dataUrl); + await updateJsonFile('./data/node-js-schedule.json', body); +})(); diff --git a/tools/static-data/utils.mjs b/tools/static-data/utils.mjs new file mode 100644 index 00000000000000..93cdbfd42b3cd9 --- /dev/null +++ b/tools/static-data/utils.mjs @@ -0,0 +1,17 @@ +import fs from 'fs-extra'; +import shell from 'shelljs'; + +/** + * Update given file with new provided data. + * @param {string} file Path to a data file + * @param {string} newData New data to be written + */ +export async function updateJsonFile(file, newData) { + try { + shell.echo(`Updating ${file}`); + await fs.writeFile(file, newData); + } catch (e) { + shell.echo(e.toString()); + shell.exit(1); + } +}