Skip to content

Commit 3835131

Browse files
aduh95targos
authored andcommitted
tools: add workflow to ensure README lists are in sync with gh teams
PR-URL: #53901 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 0429b1e commit 3835131

File tree

2 files changed

+67
-20
lines changed

2 files changed

+67
-20
lines changed

.github/workflows/linters.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,21 @@ jobs:
185185
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
186186
with:
187187
persist-credentials: false
188-
- run: tools/lint-readme-lists.mjs
188+
- name: Get team members if possible
189+
id: team_members
190+
run: |
191+
get_list_members() {
192+
TEAM="$1"
193+
QUOTE='"'
194+
gh api "/orgs/nodejs/teams/$TEAM/members" -X GET -f per_page=100 --jq "map(.login) | ${QUOTE}${TEAM}=\(tojson)${QUOTE}"
195+
}
196+
[ -z "$GITHUB_TOKEN" ] || (
197+
get_list_members "collaborators"
198+
get_list_members "issue-triage"
199+
get_list_members "tsc"
200+
) >> "$GITHUB_OUTPUT"
201+
env:
202+
GITHUB_TOKEN: ${{ secrets.GH_USER_TOKEN }}
203+
- run: tools/lint-readme-lists.mjs "$TEAMS"
204+
env:
205+
TEAMS: ${{ tojson(steps.team_members.outputs) }}

tools/lint-readme-lists.mjs

+49-19
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
#!/usr/bin/env node
22

3-
// Validates the list in the README are in the correct order.
3+
// Validates the list in the README are in the correct order, and consistent with the actual GitHub teams.
44

5+
import assert from 'node:assert';
56
import { open } from 'node:fs/promises';
7+
import { argv } from 'node:process';
68

7-
const lists = [
8-
'TSC voting members',
9-
'TSC regular members',
10-
'TSC emeriti members',
11-
'Collaborators',
12-
'Collaborator emeriti',
13-
'Triagers',
14-
];
9+
const lists = {
10+
'__proto__': null,
11+
12+
'TSC voting members': 'tsc',
13+
'TSC regular members': null,
14+
'TSC emeriti members': null,
15+
'Collaborators': 'collaborators',
16+
'Collaborator emeriti': null,
17+
'Triagers': 'issue-triage',
18+
};
19+
const actualMembers = {
20+
__proto__: null,
21+
// The bot is part of `@nodejs/collaborators`, but is not listed in the README.
22+
collaborators: new Set().add('nodejs-github-bot'),
23+
};
1524
const tscMembers = new Set();
1625

1726
const readme = await open(new URL('../README.md', import.meta.url), 'r');
@@ -23,26 +32,47 @@ let lineNumber = 0;
2332
for await (const line of readme.readLines()) {
2433
lineNumber++;
2534
if (line.startsWith('### ')) {
26-
currentList = lists[lists.indexOf(line.slice(4))];
35+
currentList = line.slice(4);
2736
previousGithubHandle = null;
2837
} else if (line.startsWith('#### ')) {
29-
currentList = lists[lists.indexOf(line.slice(5))];
38+
currentList = line.slice(5);
3039
previousGithubHandle = null;
31-
} else if (currentList && line.startsWith('* [')) {
32-
const currentGithubHandle = line.slice(3, line.indexOf(']')).toLowerCase();
33-
if (previousGithubHandle && previousGithubHandle >= currentGithubHandle) {
34-
throw new Error(`${currentGithubHandle} should be listed before ${previousGithubHandle} in the ${currentList} list (README.md:${lineNumber})`);
40+
} else if (currentList in lists && line.startsWith('* [')) {
41+
const currentGithubHandle = line.slice(3, line.indexOf(']'));
42+
const currentGithubHandleLowerCase = currentGithubHandle.toLowerCase();
43+
if (
44+
previousGithubHandle &&
45+
previousGithubHandle >= currentGithubHandleLowerCase
46+
) {
47+
throw new Error(
48+
`${currentGithubHandle} should be listed before ${previousGithubHandle} in the ${currentList} list (README.md:${lineNumber})`,
49+
);
3550
}
3651

37-
if (currentList === 'TSC voting members' || currentList === 'TSC regular members') {
52+
if (
53+
currentList === 'TSC voting members' ||
54+
currentList === 'TSC regular members'
55+
) {
3856
tscMembers.add(currentGithubHandle);
3957
} else if (currentList === 'Collaborators') {
4058
tscMembers.delete(currentGithubHandle);
4159
}
42-
previousGithubHandle = currentGithubHandle;
60+
if (lists[currentList]) {
61+
(actualMembers[lists[currentList]] ??= new Set()).add(currentGithubHandle);
62+
}
63+
previousGithubHandle = currentGithubHandleLowerCase;
4364
}
4465
}
66+
console.info('Lists are in the alphabetical order.');
67+
68+
assert.deepStrictEqual(tscMembers, new Set(), 'Some TSC members are not listed as Collaborators');
4569

46-
if (tscMembers.size !== 0) {
47-
throw new Error(`Some TSC members are not listed as Collaborators: ${Array.from(tscMembers)}`);
70+
if (argv[2] && argv[2] !== '{}') {
71+
const reviver = (_, value) =>
72+
(typeof value === 'string' && value[0] === '[' && value.at(-1) === ']' ?
73+
new Set(JSON.parse(value)) :
74+
value);
75+
assert.deepStrictEqual(JSON.parse(argv[2], reviver), { ...actualMembers });
76+
} else {
77+
console.warn('Skipping the check of GitHub teams membership.');
4878
}

0 commit comments

Comments
 (0)