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 15 commits
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
181 changes: 181 additions & 0 deletions .github/workflows/update-maintainers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
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@v3
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: Checkout community repo
uses: actions/checkout@v3
with:
repository: asyncapi/community
token: ${{ secrets.GITHUB_TOKEN }}
14Richa marked this conversation as resolved.
Show resolved Hide resolved
path: community

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

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

- name: Install @octokit/rest
run: npm install @octokit/rest
14Richa marked this conversation as resolved.
Show resolved Hide resolved

- name: Compare CODEOWNERS
id: compare-codeowners
env:
14Richa marked this conversation as resolved.
Show resolved Hide resolved
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14Richa marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const yaml = require('js-yaml');

// Get repository name
const repoName = context.repo.repo;

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 currentCodeowners = fs.readFileSync('./current_state/CODEOWNERS', 'utf8');
const previousCodeowners = fs.readFileSync('./previous_state/CODEOWNERS', 'utf8');

const currentUsernames = extractGitHubUsernames(currentCodeowners);
const previousUsernames = extractGitHubUsernames(previousCodeowners);

const addedUsernames = currentUsernames.filter(username => !previousUsernames.includes(username));
const removedUsernames = previousUsernames.filter(username => !currentUsernames.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 = './community/MAINTAINERS.yaml';
const maintainers = yaml.safeLoad(fs.readFileSync(maintainersFile, 'utf8'));

const { Octokit } = require("@octokit/rest");

const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
request: {
fetch: (url, options) => fetch(url, options)
}
});

// Update for added usernames
for (const username of addedUsernames) {
const { data } = await octokit.users.getByUsername({ username });
const twitterUsername = data.twitter_username;
14Richa marked this conversation as resolved.
Show resolved Hide resolved

// 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 maintainer = maintainers.find(maintainer => maintainer.github === username);
if (!maintainer) {
maintainers.push({
github: username,
twitter: twitterUsername,
isTscMember: false,
repos: [repoName]
});
console.log('Added maintainer:', username);
} else {
// If the maintainer already exists, check if the current repo is in their list
if (!maintainer.repos.includes(repoName)) {
maintainer.repos.push(repoName);
console.log('Added repository to existing maintainer:', username);
} else {
console.log('Maintainer', username, 'already exists and already has the repo. Skipping addition.');
14Richa marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

// Update for removed usernames
for (const username of removedUsernames) {
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: Create new branch
working-directory: ./community
run: |
git checkout -b update-maintainers-${{ github.run_id }}

- name: Commit and push
working-directory: ./community
run: |
git add .
git commit -m "Update MAINTAINERS.yaml"
git push https://${{ secrets.GITHUB_TOKEN }}@github.com/asyncapi/community update-maintainers-${{ github.run_id }}

- name: Create PR
working-directory: ./community
run: |
gh pr create --title "docs(community): update latest maintainers list" --body "Updated Maintainers list is available and this PR introduces changes with latest information about Maintainers" --head update-maintainers-${{ github.run_id }}


- name: Report workflow run status to Slack
if: failure() # Only, on failure, send a message on the slack channel
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_CI_FAIL_NOTIFY }}
SLACK_TITLE: 🚨 Update maintainers list action failed 🚨
SLACK_MESSAGE: Failed to update the maintainers list.
MSG_MINIMAL: true