From ec71a0f817645e428c60b59e78321866ada1be6b Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 5 Feb 2021 00:12:31 +0100 Subject: [PATCH] tools: check version number in YAML comments from changelogs PR-URL: https://github.com/nodejs/node/pull/37599 Refs: https://github.com/nodejs/remark-preset-lint-node/pull/172 Reviewed-By: Darshan Sen Reviewed-By: Rich Trott Reviewed-By: James M Snell --- .github/workflows/linters.yml | 6 +++ ...list-released-versions-from-changelogs.mjs | 40 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 tools/node-lint-md-cli-rollup/src/list-released-versions-from-changelogs.mjs diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 9bb9cd14bc1d0f..e9a46ca3176780 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -50,10 +50,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: if: github.event.pull_request.draft == false runs-on: ubuntu-latest diff --git a/tools/node-lint-md-cli-rollup/src/list-released-versions-from-changelogs.mjs b/tools/node-lint-md-cli-rollup/src/list-released-versions-from-changelogs.mjs new file mode 100755 index 00000000000000..f134e122985d85 --- /dev/null +++ b/tools/node-lint-md-cli-rollup/src/list-released-versions-from-changelogs.mjs @@ -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 === '') { + toc = true; + } else if (toc && line[0] !== '<') { + input.close(); + return; + } else if (toc && line.startsWith('') + 1, -'
'.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(',')}`);