Skip to content

Commit

Permalink
build: add node schedule updater (#17181)
Browse files Browse the repository at this point in the history
* build: add node schedule updater

* ci: update generation job
  • Loading branch information
viceice committed Aug 15, 2022
1 parent 9c23f48 commit 59dc8f6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/update-data.yml
Expand Up @@ -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:
Expand All @@ -37,3 +40,4 @@ jobs:
commit-message: 'fix(data): automatic update of static data'
committer: 'Renovate Bot <renovate@whitesourcesoftware.com>'
title: 'fix(data): automatic update of static data'
assignees: rarkins,viceice
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -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": {
Expand Down
Expand Up @@ -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');
Expand All @@ -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);

Expand Down Expand Up @@ -66,5 +68,5 @@ await (async () => {
2
);

await fs.writeFile(`./data/azure-pipelines-tasks.json`, data);
await updateJsonFile(`./data/azure-pipelines-tasks.json`, data);
})();
@@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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`);
})();
12 changes: 12 additions & 0 deletions 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);
})();
17 changes: 17 additions & 0 deletions 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);
}
}

0 comments on commit 59dc8f6

Please sign in to comment.