Skip to content

Commit

Permalink
tools: add workflow to ensure README lists are in sync with gh teams
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jul 17, 2024
1 parent fcda284 commit 315a03d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 24 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/linters-readme.yml
Original file line number Diff line number Diff line change
@@ -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) }}
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -735,20 +735,18 @@ maintaining the Node.js project.
**Daeyeon Jeong** <<[email protected]>> (he/him)
* [F3n67u](https://github.com/F3n67u) -
**Feng Yu** <<[email protected]>> (he/him)
* [himadriganguly](https://github.com/himadriganguly) -
**Himadri Ganguly** <<himadri.tech@gmail.com>> (he/him)
* [gireeshpunathil](https://github.com/gireeshpunathil) -
**Gireesh Punathil** <<[email protected].com>> (he/him)
* [iam-frankqiu](https://github.com/iam-frankqiu) -
**Frank Qiu** <<[email protected]>> (he/him)
* [kvakil](https://github.com/kvakil) -
**Keyhan Vakil** <<[email protected]>>
* [marsonya](https://github.com/marsonya) -
**Akhil Marsonya** <<[email protected]>> (he/him)
* [meixg](https://github.com/meixg) -
**Xuguang Mei** <<[email protected]>> (he/him)
* [mertcanaltin](https://github.com/mertcanaltin) -
**Mert Can Altin** <<[email protected]>>
* [Mesteery](https://github.com/Mesteery) -
**Mestery** <<[email protected]>> (he/him)
* [PoojaDurgad](https://github.com/PoojaDurgad) -
**Pooja Durgad** <<[email protected]>>
* [preveen-stack](https://github.com/preveen-stack) -
**Preveen Padmanabhan** <<[email protected]>> (he/him)
* [RedYetiDev](https://github.com/redyetidev) -
Expand Down
49 changes: 31 additions & 18 deletions tools/lint-readme-lists.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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})`);
}

Expand All @@ -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))

0 comments on commit 315a03d

Please sign in to comment.