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
PR-URL: #53901
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
aduh95 authored and targos committed Sep 21, 2024
1 parent c04896b commit 6dea5ae
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 20 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,21 @@ jobs:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false
- run: tools/lint-readme-lists.mjs
- name: Get team members if possible
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) | ${QUOTE}${TEAM}=\(tojson)${QUOTE}"
}
[ -z "$GITHUB_TOKEN" ] || (
get_list_members "collaborators"
get_list_members "issue-triage"
get_list_members "tsc"
) >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.GH_USER_TOKEN }}
- run: tools/lint-readme-lists.mjs "$TEAMS"
env:
TEAMS: ${{ tojson(steps.team_members.outputs) }}
68 changes: 49 additions & 19 deletions tools/lint-readme-lists.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
#!/usr/bin/env node

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

import assert from 'node:assert';
import { open } from 'node:fs/promises';
import { argv } from 'node:process';

const lists = [
'TSC voting members',
'TSC regular members',
'TSC emeriti members',
'Collaborators',
'Collaborator emeriti',
'Triagers',
];
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,26 +32,47 @@ 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) {
throw new Error(`${currentGithubHandle} should be listed before ${previousGithubHandle} in the ${currentList} list (README.md:${lineNumber})`);
} 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})`,
);
}

if (currentList === 'TSC voting members' || currentList === 'TSC regular members') {
if (
currentList === 'TSC voting members' ||
currentList === 'TSC regular members'
) {
tscMembers.add(currentGithubHandle);
} else if (currentList === 'Collaborators') {
tscMembers.delete(currentGithubHandle);
}
previousGithubHandle = currentGithubHandle;
if (lists[currentList]) {
(actualMembers[lists[currentList]] ??= new Set()).add(currentGithubHandle);
}
previousGithubHandle = currentGithubHandleLowerCase;
}
}
console.info('Lists are in the alphabetical order.');

assert.deepStrictEqual(tscMembers, new Set(), 'Some TSC members are not listed as Collaborators');

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

0 comments on commit 6dea5ae

Please sign in to comment.