Skip to content

docs(maintainers): update MAINTAINERS.yaml file with the latest CODEOWNERS changes #78

docs(maintainers): update MAINTAINERS.yaml file with the latest CODEOWNERS changes

docs(maintainers): update MAINTAINERS.yaml file with the latest CODEOWNERS changes #78

name: Maintainer Management Workflow
on:
pull_request_target:
types: [closed]
paths:
- 'MAINTAINERS.yaml'
jobs:
detect_maintainer_changes:
if: github.event.pull_request.merged
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v3
with:
ref: master
path: community-main
- name: List of directory
run: ls -la
- name: Checkout one commit before last one
uses: actions/checkout@v3
with:
fetch-depth: 2
ref: master
path: community
- name: List of directory
run: ls -la
- run: cd community && git checkout HEAD^
- name: Install dependencies
run: npm install js-yaml@4.1.0
- name: Compare files
id: compare-files
uses: actions/github-script@v6
with:
script: |
const fs = require("fs");
const yaml = require('js-yaml');
const currentMaintainers = yaml.load(fs.readFileSync('./community-main/MAINTAINERS.yaml', 'utf8'));
const previousMaintainers = yaml.load(fs.readFileSync('./community/MAINTAINERS.yaml', 'utf8'));
const removed = previousMaintainers.filter(
(newObj) => !currentMaintainers.some((oldObj) => oldObj.github === newObj.github)
);
const added = currentMaintainers.filter(
(oldObj) => !previousMaintainers.some((newObj) => newObj.github === oldObj.github)
);
if (added.length > 0) {
core.setOutput("newMaintainers", added.map((obj) => obj.github).join(","));
}
if (removed.length > 0) {
core.setOutput("removedMaintainers", removed.map((obj) => obj.github).join(","));
}
const removedTscMembers = previousMaintainers.filter(
(obj) => !currentMaintainers.some((mainObj) => mainObj.github === obj.github) && obj.isTscMember === true
);
if (removedTscMembers.length > 0) {
core.setOutput("removedTscMembers", removedTscMembers.map((obj) => obj.github).join(","));
core.info(`Removed TSC Members: ${removedTscMembers.map((obj) => obj.github).join(",")}`);
}
// Log information for debugging
core.info('Maintainers in main branch:\n' + yaml.dump(currentMaintainers));
core.info('Location of Maintainers in main branch:');
core.info(fs.realpathSync('./community-main/MAINTAINERS.yaml'));
core.info('Maintainers in PR branch:\n' + yaml.dump(previousMaintainers));
core.info('Location of Maintainers in PR branch:');
core.info(fs.realpathSync('./community/MAINTAINERS.yaml'));
- name: Debug newMaintainers output
run: |
echo "newMaintainers = ${{ steps.compare-files.outputs.newMaintainers }}"
- name: Debug removedMaintainers output
run: |
echo "removedMaintainers = ${{ steps.compare-files.outputs.removedMaintainers }}"
outputs:
newMaintainers: ${{ steps.compare-files.outputs.newMaintainers }}
removedMaintainers: ${{ steps.compare-files.outputs.removedMaintainers }}
removedTscMembers: ${{ steps.compare-files.outputs.removedTscMembers }}
add_maintainer:
needs: detect_maintainer_changes
if: needs.detect_maintainer_changes.outputs.newMaintainers != ''
runs-on: ubuntu-latest
steps:
- name: Invite new maintainers to the organization
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN_ORG_ADMIN }}
script: |
const newMaintainers = '${{ needs.detect_maintainer_changes.outputs.newMaintainers }}'.split(',');
for (const maintainer of newMaintainers) {
try {
await github.request('PUT /orgs/{org}/memberships/{username}', {
org: 'asyncapi',
username: maintainer
});
} catch (error) {
core.setFailed(`Failed to add ${maintainer} to the organization: ${error.message}`);
}
}
- name: Add new maintainers to the team
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN_ORG_ADMIN }}
script: |
const newMaintainers = '${{ needs.detect_maintainer_changes.outputs.newMaintainers }}'.split(',');
for (const maintainer of newMaintainers) {
try {
await github.request('PUT /orgs/{org}/teams/{team_slug}/memberships/{username}', {
org: 'asyncapi',
team_slug: 'maintainers',
username: maintainer
});
} catch (error) {
core.setFailed(`Failed to add ${maintainer} to the team: ${error.message}`);
}
}
outputs:
newMaintainers: ${{needs.detect_maintainer_changes.outputs.newMaintainers }}
display_message:
needs: add_maintainer
if: needs.add_maintainer.outputs.newMaintainers != ''
runs-on: ubuntu-latest
steps:
- name: Display welcome message for new maintainers
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const newMaintainers = "${{ needs.add_maintainer.outputs.newMaintainers }}".split(",");
console.log(`New maintainers: ${newMaintainers}`);
const welcomeMessage = newMaintainers.map((maintainer) => `@${maintainer.trim().replace(/^@/, '')} We invited you to join the AsyncAPI organization, and you are added to the team that lists all Maintainers.\n
Please take a moment to verify if you would like to provide more details for your account, such as your LinkedIn profile, Twitter handle, or company affiliation. In case there is anything you want to add, please open up a separate pull request for the \`MAINTAINERS.yaml\` file.\n\n
Additionally, if you are interested in becoming a [TSC member](https://www.youtube.com/watch?v=MfVUUbW2aos) and contributing to the direction of the AsyncAPI Initiative, let us know, and we'll be happy to guide you through the process. Every maintainer has the right to become a [TSC member](https://www.asyncapi.com/community/tsc), just open a pull request to modify your entry in \`MAINTAINER.yaml\` file and make sure \`isTscMember\` property is set to \`true\`. Consider also adding \`slack\` information with your Slack Member ID. We use it in our automation to drop you reminders to participate in voting. To find your Member ID, click on your profile photo in Slack and click "Profile". In the right side of their profile section, click on the three dots and click "Copy Member ID".\n\n
You can find some basic information about TSC membership in [this TSC-related guide](https://github.com/asyncapi/community/blob/master/TSC_MEMBERSHIP.md). Feel free to reach out to us for more help by dropping a comment in this pull request, or by asking for help in our Slack.\n\n
Welcome aboard! We are excited to have you as part of the team.`).join("\n");
const { owner, repo } = context.repo;
const { number: issue_number } = context.issue;
return github.rest.issues.createComment({ owner, repo, issue_number, body: welcomeMessage });
remove_maintainer:
needs: detect_maintainer_changes
if: needs.detect_maintainer_changes.outputs.removedMaintainers != ''
runs-on: ubuntu-latest
steps:
- name: Remove maintainers from the organization
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN_ORG_ADMIN }}
script: |
const removedMaintainers = '${{ needs.detect_maintainer_changes.outputs.removedMaintainers }}'.split(',');
for (const maintainer of removedMaintainers) {
try {
await github.request('DELETE /orgs/{org}/memberships/{username}', {
org: 'asyncapi',
username: maintainer
});
core.info(`Successfully removed ${maintainer} from the organization.`);
} catch (error) {
if (error.message.startsWith('Cannot find')) {
core.info(`Failed to remove ${maintainer} from the organization: ${error.message}`);
} else {
core.setFailed(`Failed to remove ${maintainer} from the organization: ${error.message}`);
}
}
}
outputs:
removedMaintainers: ${{ needs.detect_maintainer_changes.outputs.removedMaintainers }}
removedTscMembers: ${{ needs.detect_maintainer_changes.outputs.removedTscMembers }}
remove_maintainer_goodbye:
needs: remove_maintainer
if: needs.remove_maintainer.outputs.removedMaintainers != ''
runs-on: ubuntu-latest
steps:
- name: Display goodbye message to removed maintainers
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN_ORG_ADMIN }}
script: |
const removedMaintainers = "${{ needs.remove_maintainer.outputs.removedMaintainers }}".split(",");
// Goodbye message to removed maintainers
const combinedMessages = removedMaintainers.map((maintainer) => {
return `@${maintainer.trim().replace(/^@/, '')} We would like to express our gratitude for your contributions as a maintainer of AsyncAPI Initiative. Your efforts have been immensely valuable to us, and we truly appreciate your dedication. Thank you once again, and we wish you all the best in your future endeavors!\n\n`;
});
const { owner, repo } = context.repo;
const { number: issue_number } = context.issue;
for (const message of combinedMessages) {
github.rest.issues.createComment({ owner, repo, issue_number, body: message });
}
notify_slack_on_failure:
if: always() && (needs.detect_maintainer_changes.result == 'failure' || needs.add_maintainer.result == 'failure' || needs.display_message.result == 'failure' || needs.remove_maintainer.result == 'failure' || needs.remove_maintainer_goodbye.result == 'failure')
needs: [detect_maintainer_changes, add_maintainer, display_message, remove_maintainer, remove_maintainer_goodbye]
runs-on: ubuntu-latest
steps:
- name: Report workflow run status to Slack
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{secrets.SLACK_CI_FAIL_NOTIFY}}
SLACK_TITLE: 🚨 Maintainer Management Workflow failed 🚨
SLACK_MESSAGE: Failed to post a message to new Maintainer
MSG_MINIMAL: true