From 315a03d87ff315ad91af22edad1024ffbe35faf6 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 17 Jul 2024 20:04:00 +0200 Subject: [PATCH] tools: add workflow to ensure `README` lists are in sync with gh teams --- .github/workflows/linters-readme.yml | 49 ++++++++++++++++++++++++++++ README.md | 10 +++--- tools/lint-readme-lists.mjs | 49 ++++++++++++++++++---------- 3 files changed, 84 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/linters-readme.yml diff --git a/.github/workflows/linters-readme.yml b/.github/workflows/linters-readme.yml new file mode 100644 index 00000000000000..af999d565ea031 --- /dev/null +++ b/.github/workflows/linters-readme.yml @@ -0,0 +1,49 @@ +# We need a separate workflow file so failures on the README are not reported on +# all PRs, only on the ones that update the README. +name: Linters (README.md) + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths: [README.md] + push: + branches: + - main + - v[0-9]+.x-staging + - v[0-9]+.x + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +env: + PYTHON_VERSION: '3.12' + NODE_VERSION: lts/* + +permissions: + contents: read + +jobs: + lint-readme-lists: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + persist-credentials: false + - name: Get ${{ env.TEAM }} team members + id: team_members + run: | + get_list_members() { + TEAM="$1" + QUOTE='"' + gh api "/orgs/nodejs/teams/$TEAM/members" -X GET -f per_page=100 --jq "map(.login) | @sh ${QUOTE}${TEAM}=\(tojson)${QUOTE}" + } + + get_list_members "collaborators" >> "$GITHUB_OUTPUT" + get_list_members "issue-triage" >> "$GITHUB_OUTPUT" + get_list_members "tsc" >> "$GITHUB_OUTPUT" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - run: tools/lint-readme-lists.mjs "$TEAMS" + env: + TEAMS: ${{ tojson(steps.team_members.outputs) }} diff --git a/README.md b/README.md index da736c5f0c916c..377ec1be2baa0c 100644 --- a/README.md +++ b/README.md @@ -735,20 +735,18 @@ maintaining the Node.js project. **Daeyeon Jeong** <> (he/him) * [F3n67u](https://github.com/F3n67u) - **Feng Yu** <> (he/him) -* [himadriganguly](https://github.com/himadriganguly) - - **Himadri Ganguly** <> (he/him) +* [gireeshpunathil](https://github.com/gireeshpunathil) - + **Gireesh Punathil** <> (he/him) * [iam-frankqiu](https://github.com/iam-frankqiu) - **Frank Qiu** <> (he/him) +* [kvakil](https://github.com/kvakil) - + **Keyhan Vakil** <> * [marsonya](https://github.com/marsonya) - **Akhil Marsonya** <> (he/him) * [meixg](https://github.com/meixg) - **Xuguang Mei** <> (he/him) * [mertcanaltin](https://github.com/mertcanaltin) - **Mert Can Altin** <> -* [Mesteery](https://github.com/Mesteery) - - **Mestery** <> (he/him) -* [PoojaDurgad](https://github.com/PoojaDurgad) - - **Pooja Durgad** <> * [preveen-stack](https://github.com/preveen-stack) - **Preveen Padmanabhan** <> (he/him) * [RedYetiDev](https://github.com/redyetidev) - diff --git a/tools/lint-readme-lists.mjs b/tools/lint-readme-lists.mjs index 8859d2097c4e79..991cd240debeb4 100755 --- a/tools/lint-readme-lists.mjs +++ b/tools/lint-readme-lists.mjs @@ -2,16 +2,24 @@ // Validates the list in the README are in the correct order. +import assert from 'node:assert'; import { open } from 'node:fs/promises'; - -const lists = [ - 'TSC voting members', - 'TSC regular members', - 'TSC emeriti members', - 'Collaborators', - 'Collaborator emeriti', - 'Triagers', -]; +import { argv } from 'node:process' + +const lists = { + __proto__: null, + 'TSC voting members': 'tsc', + 'TSC regular members': null, + 'TSC emeriti members': null, + 'Collaborators': 'collaborators', + 'Collaborator emeriti': null, + 'Triagers': 'issue-triage' +}; +const actualMembers = { + __proto__: null, + // The bot is part of `@nodejs/collaborators`, but is not listed in the README. + 'collaborators': new Set().add('nodejs-github-bot'), +}; const tscMembers = new Set(); const readme = await open(new URL('../README.md', import.meta.url), 'r'); @@ -23,14 +31,15 @@ let lineNumber = 0; for await (const line of readme.readLines()) { lineNumber++; if (line.startsWith('### ')) { - currentList = lists[lists.indexOf(line.slice(4))]; + currentList = line.slice(4); previousGithubHandle = null; } else if (line.startsWith('#### ')) { - currentList = lists[lists.indexOf(line.slice(5))]; + currentList = line.slice(5); previousGithubHandle = null; - } else if (currentList && line.startsWith('* [')) { - const currentGithubHandle = line.slice(3, line.indexOf(']')).toLowerCase(); - if (previousGithubHandle && previousGithubHandle >= currentGithubHandle) { + } else if (currentList in lists && line.startsWith('* [')) { + const currentGithubHandle = line.slice(3, line.indexOf(']')); + const currentGithubHandleLowerCase = currentGithubHandle.toLowerCase(); + if (previousGithubHandle && previousGithubHandle >= currentGithubHandleLowerCase) { throw new Error(`${currentGithubHandle} should be listed before ${previousGithubHandle} in the ${currentList} list (README.md:${lineNumber})`); } @@ -39,10 +48,14 @@ for await (const line of readme.readLines()) { } else if (currentList === 'Collaborators') { tscMembers.delete(currentGithubHandle); } - previousGithubHandle = currentGithubHandle; + if (lists[currentList]) { + (actualMembers[lists[currentList]] ??= new Set).add(currentGithubHandle); + } + previousGithubHandle = currentGithubHandleLowerCase; } } -if (tscMembers.size !== 0) { - throw new Error(`Some TSC members are not listed as Collaborators: ${Array.from(tscMembers)}`); -} +assert.deepStrictEqual(tscMembers, new Set, `Some TSC members are not listed as Collaborators`); + +const reviver = (_, value) => typeof value === 'string' && value[0] === '[' && value.at(-1) === ']' ? new Set(JSON.parse(value)) : value; +assert.deepStrictEqual({...actualMembers}, JSON.parse(argv[2], reviver))