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: updates the isTscMember property and manages changes in the tsc_members teams #807

Merged
merged 24 commits into from
Aug 3, 2023
Merged
Changes from 6 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
116 changes: 116 additions & 0 deletions .github/workflows/update-tsc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: TSC Member Update
14Richa marked this conversation as resolved.
Show resolved Hide resolved

on:
pull_request:
types: [closed]
paths:
- 'MAINTAINERS.yaml'

jobs:
update_tsc_member:
14Richa marked this conversation as resolved.
Show resolved Hide resolved
if: github.event.pull_request.merged
name: Update TSC Member
runs-on: ubuntu-latest

steps:
- name: Checkout main branch
uses: actions/checkout@v2
with:
ref: master
path: community-main

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

- run: cd community && git checkout HEAD^

- name: Install js-yaml
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 mainFile = yaml.load(fs.readFileSync('./community-main/MAINTAINERS.yaml', 'utf8'));
const prFile = yaml.load(fs.readFileSync('./community/MAINTAINERS.yaml', 'utf8'));

// Variables to store the updated value and GitHub user
let updatedMaintainers = [];
let updatedValue;

// Function to check if isTscMember value has changed
function hasIsTscMemberChanged(maintainerGithub) {
const mainMaintainer = mainFile.find(m => m.github === maintainerGithub);
const prMaintainer = prFile.find(m => m.github === maintainerGithub);

core.info(`Checking for ${maintainerGithub}`);

if (!mainMaintainer || !prMaintainer) {
console.error('Maintainer not found:', maintainerGithub);
return;
}

core.info(`${maintainerGithub} in mainFile has isTscMember as:`, mainMaintainer.isTscMember);
core.info(`${maintainerGithub} in prFile has isTscMember as:`, prMaintainer.isTscMember);

if (mainMaintainer.isTscMember !== prMaintainer.isTscMember) {
core.info(`isTscMember value changed for ${maintainerGithub}`);
updatedMaintainers.push({ githubUser: maintainerGithub, updatedValue: mainMaintainer.isTscMember });
updatedValue = mainMaintainer.isTscMember;
}
}

// Loop over all maintainers and find the changes
mainFile.forEach(maintainer => hasIsTscMemberChanged(maintainer.github));

// Log final results
core.info("Final updatedValue:", updatedValue);
core.info("Final updatedMaintainers:", JSON.stringify(updatedMaintainers));

// Set outputs
core.setOutput("updatedValue", updatedValue);
core.setOutput("updatedMaintainers", JSON.stringify(updatedMaintainers));
outputs:
updatedValue: ${{ steps.compare-files.outputs.updatedValue }}
updatedMaintainers: ${{ steps.compare-files.outputs.updatedMaintainers }}

add_or_remove_tsc_members_team:
14Richa marked this conversation as resolved.
Show resolved Hide resolved
needs: update_tsc_member
runs-on: ubuntu-latest

steps:
- name: Add or remove maintainers from the team
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const updatedValue = ${{ needs.update_tsc_member.outputs.updatedValue }};
const updatedMaintainers = JSON.parse('${{ needs.update_tsc_member.outputs.updatedMaintainers }}');
for (const maintainerObj of updatedMaintainers) {
const maintainer = maintainerObj.githubUser;
try {
if (updatedValue) {
// Add maintainer to the team
await github.request('PUT /orgs/asyncapi/teams/tsc_members/memberships/{username}', {
username: maintainer
});
core.info(`Successfully added ${maintainer} to the team.`);
} else {
// Remove maintainer from the team
await github.request('DELETE /orgs/asyncapi/teams/tsc_members/memberships/{username}', {
username: maintainer
});
core.info(`Successfully removed ${maintainer} from the team.`);
}
} catch (error) {
core.error(`Failed to update ${maintainer} in the team: ${error.message}`);
}
}
Loading