From ad5bb3ebe100850ad07b8c5faeeee3340c4681ad Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Tue, 11 Feb 2025 11:05:06 +0200 Subject: [PATCH] ci: fix and improve automation around `MAINTAINERS.yaml` --- .github/workflows/maintainer_management.yml | 35 ++++++++++----------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/workflows/maintainer_management.yml b/.github/workflows/maintainer_management.yml index e14a5c521..cb2fa8075 100644 --- a/.github/workflows/maintainer_management.yml +++ b/.github/workflows/maintainer_management.yml @@ -6,6 +6,9 @@ on: paths: - 'MAINTAINERS.yaml' +env: + GH_TOKEN_ORG_ADMIN: ${{ secrets.GH_TOKEN_ORG_ADMIN }} + jobs: detect_maintainer_changes: if: github.event.pull_request.merged @@ -92,31 +95,24 @@ jobs: - name: Invite new maintainers to the organization uses: actions/github-script@v6 with: + github-token: ${{ env.GH_TOKEN_ORG_ADMIN }} script: | - console.log(process.env); const newMaintainers = '${{ needs.detect_maintainer_changes.outputs.newMaintainers }}'.split(','); - - const promises = newMaintainers.map(async (maintainer) => { + for (const maintainer of newMaintainers) { try { - const response = await fetch(`https://api.github.com/orgs/asyncapi/teams/maintainers/memberships/${maintainer}`, { - method: 'PUT', - headers: { - 'Authorization': 'token ${{ secrets.GH_TOKEN_ORG_ADMIN }}', - }, + await github.request('PUT /orgs/{org}/memberships/{username}', { + org: 'asyncapi', + username: maintainer }); - const data = await response.json(); - console.log(data); } catch (error) { core.setFailed(`Failed to add ${maintainer} to the organization: ${error.message}`); } - }); - - await Promise.all(promises); + } - name: Add new maintainers to the team uses: actions/github-script@v6 with: - github-token: ${{ secrets.GH_TOKEN }} + github-token: ${{ env.GH_TOKEN_ORG_ADMIN }} script: | const newMaintainers = '${{ needs.detect_maintainer_changes.outputs.newMaintainers }}'.split(','); for (const maintainer of newMaintainers) { @@ -142,7 +138,7 @@ jobs: - name: Display welcome message for new maintainers uses: actions/github-script@v6 with: - github-token: ${{ secrets.GH_TOKEN }} + github-token: ${{ env.GH_TOKEN_ORG_ADMIN }} script: | const newMaintainers = "${{ needs.add_maintainer.outputs.newMaintainers }}".split(","); console.log(`New maintainers: ${newMaintainers}`); @@ -166,7 +162,7 @@ jobs: - name: Remove maintainers from the organization uses: actions/github-script@v6 with: - github-token: ${{ secrets.GH_TOKEN }} + github-token: ${{ env.GH_TOKEN_ORG_ADMIN }} script: | const removedMaintainers = '${{ needs.detect_maintainer_changes.outputs.removedMaintainers }}'.split(','); for (const maintainer of removedMaintainers) { @@ -193,7 +189,7 @@ jobs: - name: Display goodbye message to removed maintainers uses: actions/github-script@v6 with: - github-token: ${{ secrets.GH_TOKEN }} + github-token: ${{ env.GH_TOKEN_ORG_ADMIN }} script: | const removedMaintainers = "${{ needs.remove_maintainer.outputs.removedMaintainers }}".split(","); const removedTscMembers = "${{ needs.remove_maintainer.outputs.removedTscMembers }}".split(","); @@ -224,7 +220,7 @@ jobs: - name: Add TSC members to Emeritus.yaml and print uses: actions/github-script@v6 with: - github-token: ${{ secrets.GH_TOKEN }} + github-token: ${{ env.GH_TOKEN_ORG_ADMIN }} script: | const fs = require('fs'); const path = './Emeritus.yaml'; @@ -256,7 +252,8 @@ jobs: run: | git add . git commit -m "Update Emeritus.yaml" - git push https://${{ secrets.GH_TOKEN}}@github.com/asyncapi/community update-emeritus-${{ github.run_id }} + git remote set-url origin https://x-access-token:${{ env.GH_TOKEN_ORG_ADMIN }}@github.com/asyncapi/community.git + git push origin update-emeritus-${{ github.run_id }} - name: Create PR run: |