Skip to content

Commit

Permalink
tools: check version number in YAML comments from changelogs
Browse files Browse the repository at this point in the history
PR-URL: #37599
Refs: nodejs/remark-preset-lint-node#172
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
aduh95 authored and targos committed May 1, 2021
1 parent b76aa10 commit f326fc1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ jobs:
node-version: ${{ env.NODE_VERSION }}
- name: Environment Information
run: npx envinfo
- name: Get release version numbers
id: get-released-versions
run: ./tools/node-lint-md-cli-rollup/src/list-released-versions-from-changelogs.mjs
- name: Lint docs
run: |
echo "::add-matcher::.github/workflows/remark-lint-problem-matcher.json"
NODE=$(command -v node) make lint-md
env:
NODE_RELEASED_VERSIONS: ${{ steps.get-released-versions.outputs.NODE_RELEASED_VERSIONS }}

lint-js:
runs-on: ubuntu-latest
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env node

import fs from 'node:fs';
import { createInterface } from 'node:readline';

const dataFolder = new URL('../../../doc/changelogs/', import.meta.url);

const result = [];
async function getVersionsFromFile(file) {
const input = fs.createReadStream(file);
let toc = false;
for await (const line of createInterface({
input,
crlfDelay: Infinity,
})) {
if (toc === false && line === '<table>') {
toc = true;
} else if (toc && line[0] !== '<') {
input.close();
return;
} else if (toc && line.startsWith('<a')) {
result.push(line.slice(line.indexOf('>') + 1, -'</a><br/>'.length));
}
}
}

const filesToCheck = [];

const dir = await fs.promises.opendir(dataFolder);
for await (const dirent of dir) {
if (dirent.isFile()) {
filesToCheck.push(
getVersionsFromFile(new URL(`./${dirent.name}`, dataFolder))
);
}
}

await Promise.all(filesToCheck);

console.log(`::set-output name=NODE_RELEASED_VERSIONS::${result.join(',')}`);

0 comments on commit f326fc1

Please sign in to comment.