Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: update MAINTAINERS.yaml based on CODEOWNERS changes #248

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b69de5d
added new workflow
14Richa Jul 12, 2023
8e493d7
Update .github/workflows/update-maintainers.yml
14Richa Jul 12, 2023
70ffb1c
repo name fix
14Richa Jul 12, 2023
9ae74df
added create PR step
14Richa Jul 12, 2023
dcc8334
version change
14Richa Jul 12, 2023
3f60bfc
added slack alert
14Richa Jul 12, 2023
5cabea9
added twitter username code
14Richa Jul 15, 2023
7367b1f
added token
14Richa Jul 15, 2023
4de0eb2
fixed syntax error
14Richa Jul 17, 2023
9f31a73
Update .github/workflows/update-maintainers.yml
14Richa Jul 18, 2023
9fff056
fixed variable names
14Richa Jul 18, 2023
bcd504f
added code for maintainer already exists, and current repo is not in…
14Richa Jul 18, 2023
17dd441
added community repo code
14Richa Jul 18, 2023
073c252
minor fix
14Richa Jul 18, 2023
78f41e6
minor fix
14Richa Jul 18, 2023
8b56e2f
Update .github/workflows/update-maintainers.yml
14Richa Jul 18, 2023
0e97613
making regex comment proof
14Richa Jul 18, 2023
2acd8b3
excluding bot account before twitter api call
14Richa Jul 18, 2023
cf8d9fd
minor fix in remove codeowner code block
14Richa Jul 18, 2023
30b0293
remove ocktokit dependecy
14Richa Jul 19, 2023
a315646
Update .github/workflows/update-maintainers.yml
14Richa Jul 20, 2023
dc5b57b
changed token name
14Richa Jul 20, 2023
504fbfe
minor fix
14Richa Jul 25, 2023
7528dfd
changed console statement
14Richa Jul 25, 2023
1973052
Update .github/workflows/update-maintainers.yml
14Richa Jul 25, 2023
573771d
added the file in global replicator file
14Richa Jul 27, 2023
d409dc5
Merge branch '14Richa/update-maintainers-workflow' of github.com:14Ri…
14Richa Jul 27, 2023
093d749
Merge branch 'master' into 14Richa/update-maintainers-workflow
KhudaDad414 Jul 27, 2023
8b1ab9e
minor fixes
14Richa Aug 18, 2023
84c9280
Merge branch '14Richa/update-maintainers-workflow' of github.com:14Ri…
14Richa Aug 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions .github/workflows/update-maintainers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Update MAINTAINERS.yaml
14Richa marked this conversation as resolved.
Show resolved Hide resolved

on:
pull_request:
types: [closed]
paths:
- 'CODEOWNERS'

jobs:
update-maintainers:
if: github.event.pull_request.merged
runs-on: ubuntu-latest

steps:
- name: Checkout main branch
uses: actions/checkout@v2
14Richa marked this conversation as resolved.
Show resolved Hide resolved
with:
ref: master
path: current_state

- name: Checkout one commit before last one
uses: actions/checkout@v3
with:
fetch-depth: 2
ref: master
path: previous_state

- run: cd previous_state && git checkout HEAD^

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
14Richa marked this conversation as resolved.
Show resolved Hide resolved

- name: Install js-yaml
run: npm install [email protected]

- name: Get repository name
run: |
REPO_NAME=$(basename ${{ github.repository }})
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV
echo "Repository Name: $REPO_NAME"

- name: Compare CODEOWNERS
id: compare-codeowners
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const yaml = require('js-yaml');

// Get repository name
const repoName = process.env.REPO_NAME;
14Richa marked this conversation as resolved.
Show resolved Hide resolved

function extractGitHubUsernames(content) {
14Richa marked this conversation as resolved.
Show resolved Hide resolved
const regex = /@([a-zA-Z0-9_-]+)/g;
const matches = content.match(regex);
if (!matches) {
return [];
}
return matches.map(match => match.substr(1));
}

const mainCodeowners = fs.readFileSync('./current_state/CODEOWNERS', 'utf8');
const prCodeowners = fs.readFileSync('./previous_state/CODEOWNERS', 'utf8');
14Richa marked this conversation as resolved.
Show resolved Hide resolved

const mainUsernames = extractGitHubUsernames(mainCodeowners);
const prUsernames = extractGitHubUsernames(prCodeowners);
14Richa marked this conversation as resolved.
Show resolved Hide resolved

const addedUsernames = mainUsernames.filter(username => !prUsernames.includes(username));
const removedUsernames = prUsernames.filter(username => !mainUsernames.includes(username));
console.log('Added Usernames:', addedUsernames);
console.log('Removed Usernames:', removedUsernames);
console.log(`ADDED_USERNAMES=${addedUsernames.join(', ')}`);
console.log(`REMOVED_USERNAMES=${removedUsernames.join(', ')}`);

// Update MAINTAINERS.yaml
const maintainersFile = './current_state/MAINTAINERS.yaml';
const maintainers = yaml.safeLoad(fs.readFileSync(maintainersFile, 'utf8'));

// Update for added usernames
addedUsernames.forEach(username => {
// Exclude bot accounts
if (username === 'asyncapi-bot' || username === 'asyncapi-bot-eve') {
console.log('Skipping bot account:', username);
return; // Skip the iteration for bot accounts
}
const existingMaintainer = maintainers.find(maintainer => maintainer.github === username);
if (!existingMaintainer) {
14Richa marked this conversation as resolved.
Show resolved Hide resolved
maintainers.push({
github: username,
isTscMember: false,
repos: [repoName]
});
console.log('Added maintainer:', username);
} else {
console.log('Maintainer', username, 'already exists. Skipping addition.');
14Richa marked this conversation as resolved.
Show resolved Hide resolved
}
});

// Update for removed usernames
removedUsernames.forEach(username => {
const index = maintainers.findIndex(maintainer => maintainer.github === username);
14Richa marked this conversation as resolved.
Show resolved Hide resolved
if (index !== -1) {
const maintainer = maintainers[index];
const repoIndex = maintainer.repos.indexOf(repoName);

if (repoIndex !== -1) {
maintainer.repos.splice(repoIndex, 1);
console.log(`Removed repository ${repoName} from maintainer ${username}`);

if (maintainer.repos.length === 0) {
maintainers.splice(index, 1);
console.log(`Removed maintainer ${username} as they have no other repositories`);
}
} else {
console.log(`Repository ${repoName} not found for maintainer ${username}`);
}
} else {
console.log(`Maintainer ${username} does not exist. Skipping removal.`);
}
});

// Write updated MAINTAINERS.yaml file
const updatedMaintainers = yaml.safeDump(maintainers);
fs.writeFileSync(maintainersFile, updatedMaintainers);
console.log('Updated MAINTAINERS.yaml:', updatedMaintainers);

- name: Commit and push
working-directory: ./current_state
run: |
git add .
git commit -m "Update MAINTAINERS.yaml"
git push https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} master
14Richa marked this conversation as resolved.
Show resolved Hide resolved