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

2 files changed

Lines changed: 67 additions & 20 deletions

File tree

‎.github/workflows/linters.yml‎

Lines changed: 18 additions & 1 deletion
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‎

Lines changed: 49 additions & 19 deletions
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+
importassertfrom'node:assert';
56
import{open}from'node:fs/promises';
7+
import{argv}from'node:process';
68

7-
constlists=[
8-
'TSC voting members',
9-
'TSC regular members',
10-
'TSC emeriti members',
11-
'Collaborators',
12-
'Collaborator emeriti',
13-
'Triagers',
14-
];
9+
constlists={
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+
constactualMembers={
20+
__proto__: null,
21+
// The bot is part of `@nodejs/collaborators`, but is not listed in the README.
22+
collaborators: newSet().add('nodejs-github-bot'),
23+
};
1524
consttscMembers=newSet();
1625

1726
constreadme=awaitopen(newURL('../README.md',import.meta.url),'r');
@@ -23,26 +32,47 @@ let lineNumber = 0;
2332
forawait(constlineofreadme.readLines()){
2433
lineNumber++;
2534
if(line.startsWith('### ')){
26-
currentList=lists[lists.indexOf(line.slice(4))];
35+
currentList=line.slice(4);
2736
previousGithubHandle=null;
2837
}elseif(line.startsWith('#### ')){
29-
currentList=lists[lists.indexOf(line.slice(5))];
38+
currentList=line.slice(5);
3039
previousGithubHandle=null;
31-
}elseif(currentList&&line.startsWith('* [')){
32-
constcurrentGithubHandle=line.slice(3,line.indexOf(']')).toLowerCase();
33-
if(previousGithubHandle&&previousGithubHandle>=currentGithubHandle){
34-
thrownewError(`${currentGithubHandle} should be listed before ${previousGithubHandle} in the ${currentList} list (README.md:${lineNumber})`);
40+
}elseif(currentListinlists&&line.startsWith('* [')){
41+
constcurrentGithubHandle=line.slice(3,line.indexOf(']'));
42+
constcurrentGithubHandleLowerCase=currentGithubHandle.toLowerCase();
43+
if(
44+
previousGithubHandle&&
45+
previousGithubHandle>=currentGithubHandleLowerCase
46+
){
47+
thrownewError(
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
}elseif(currentList==='Collaborators'){
4058
tscMembers.delete(currentGithubHandle);
4159
}
42-
previousGithubHandle=currentGithubHandle;
60+
if(lists[currentList]){
61+
(actualMembers[lists[currentList]]??=newSet()).add(currentGithubHandle);
62+
}
63+
previousGithubHandle=currentGithubHandleLowerCase;
4364
}
4465
}
66+
console.info('Lists are in the alphabetical order.');
67+
68+
assert.deepStrictEqual(tscMembers,newSet(),'Some TSC members are not listed as Collaborators');
4569

46-
if(tscMembers.size!==0){
47-
thrownewError(`Some TSC members are not listed as Collaborators: ${Array.from(tscMembers)}`);
70+
if(argv[2]&&argv[2]!=='{}'){
71+
constreviver=(_,value)=>
72+
(typeofvalue==='string'&&value[0]==='['&&value.at(-1)===']' ?
73+
newSet(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)