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: fix and improve automation around MAINTAINERS.yaml #1664

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
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
36 changes: 23 additions & 13 deletions .github/workflows/maintainer_management.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
types: [closed]
paths:
- 'MAINTAINERS.yaml'

env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

Expand Down Expand Up @@ -75,11 +76,11 @@ jobs:

- name: Debug newMaintainers output
run: |
echo "newMaintainers = $newMaintainers"
echo "newMaintainers = ${{ steps.compare-files.outputs.newMaintainers }}"

- name: Debug removedMaintainers output
run: |
echo "removedMaintainers = $removedMaintainers"
echo "removedMaintainers = ${{ steps.compare-files.outputs.removedMaintainers }}"

outputs:
newMaintainers: ${{ steps.compare-files.outputs.newMaintainers }}
Expand All @@ -94,15 +95,23 @@ jobs:
- name: Invite new maintainers to the organization
uses: actions/github-script@v6
with:
github-token: ${{ env.GH_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
console.log(process.env)
const ghToken = process.env.GH_TOKEN;
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
});
(async () => {
await fetch(`https://api.github.com/orgs/asyncapi/teams/maintainers/memberships/${maintainer}`, {
method: 'PUT',
headers: {
'Authorization': `token ${ghToken}`,
},
}).then(response => response.json())
.then(data => console.log(data));
})()
} catch (error) {
core.setFailed(`Failed to add ${maintainer} to the organization: ${error.message}`);
}
Expand All @@ -111,7 +120,7 @@ jobs:
- name: Add new maintainers to the team
uses: actions/github-script@v6
with:
github-token: ${{ env.GH_TOKEN }}
github-token: ${{ secrets.GH_TOKEN }}
script: |
const newMaintainers = '${{ needs.detect_maintainer_changes.outputs.newMaintainers }}'.split(',');
for (const maintainer of newMaintainers) {
Expand Down Expand Up @@ -161,12 +170,13 @@ jobs:
- name: Remove maintainers from the organization
uses: actions/github-script@v6
with:
github-token: ${{ env.GH_TOKEN }}
github-token: ${{ secrets.GH_TOKEN }}
script: |
const removedMaintainers = '${{ needs.detect_maintainer_changes.outputs.removedMaintainers }}'.split(',');
for (const maintainer of removedMaintainers) {
try {
await github.request('DELETE /orgs/asyncapi/memberships/{username}', {
await github.request('DELETE /orgs/{org}/memberships/{username}', {
org: 'asyncapi',
username: maintainer
});
core.info(`Successfully removed ${maintainer} from the organization.`);
Expand All @@ -187,7 +197,7 @@ jobs:
- name: Display goodbye message to removed maintainers
uses: actions/github-script@v6
with:
github-token: ${{ env.GH_TOKEN }}
github-token: ${{ secrets.GH_TOKEN }}
script: |
const removedMaintainers = "${{ needs.remove_maintainer.outputs.removedMaintainers }}".split(",");
const removedTscMembers = "${{ needs.remove_maintainer.outputs.removedTscMembers }}".split(",");
Expand Down Expand Up @@ -218,7 +228,7 @@ jobs:
- name: Add TSC members to Emeritus.yaml and print
uses: actions/github-script@v6
with:
github-token: ${{ env.GH_TOKEN }}
github-token: ${{ secrets.GH_TOKEN }}
script: |
const fs = require('fs');
const path = './Emeritus.yaml';
Expand Down Expand Up @@ -267,4 +277,4 @@ jobs:
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
MSG_MINIMAL: true