Update MAINTAINERS.yaml file #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This action updates the `MAINTAINERS.yaml` file based on `CODEOWNERS` files in all organization repositories. | |
# It is triggered when a `CODEOWNERS` file is changed; the related repository triggers this workflow by emitting the `trigger-maintainers-update` event. | |
# It can also be triggered manually. | |
name: Update MAINTAINERS.yaml file | |
on: | |
push: | |
branches: [ master ] | |
paths: | |
- 'CODEOWNERS' | |
- '.github/scripts/maintainers/**' | |
- '.github/workflows/update-maintainers.yaml' | |
schedule: | |
- cron: "0 10 * * SUN" # Runs at 10:00 AM UTC every Sunday. | |
workflow_dispatch: | |
repository_dispatch: | |
types: [ trigger-maintainers-update ] | |
concurrency: | |
group: ${{ github.workflow }} | |
cancel-in-progress: false | |
env: | |
IGNORED_REPOSITORIES: "shape-up-process" | |
IGNORED_USERS: "asyncapi-bot-eve" | |
BRANCH_NAME: "bot/update-maintainers-${{ github.run_id }}" | |
PR_TITLE: "docs(maintainers): update MAINTAINERS.yaml file with the latest CODEOWNERS changes" | |
jobs: | |
update-maintainers: | |
name: Update MAINTAINERS.yaml based on CODEOWNERS files in all organization repositories | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
# If an action pushes code using the repository’s GITHUB_TOKEN, a pull request workflow will not run. | |
token: ${{ secrets.GH_TOKEN }} | |
- name: Wait for active pull requests to be merged | |
env: | |
GH_TOKEN: ${{ github.token }} | |
TIMEOUT: 300 # Timeout in seconds | |
INTERVAL: 5 # Check interval in seconds | |
run: | | |
check_active_prs() { | |
ACTIVE_PULL_REQUESTS=$(gh -R $GITHUB_REPOSITORY pr list --search "is:pr ${PR_TITLE} in:title" --json id) | |
if [ "$ACTIVE_PULL_REQUESTS" == "[]" ]; then | |
return 1 # No active PRs | |
else | |
return 0 # Active PRs found | |
fi | |
} | |
# Loop with timeout | |
elapsed_time=0 | |
while [ $elapsed_time -lt $TIMEOUT ]; do | |
if check_active_prs; then | |
echo "There is an active pull request. Waiting for it to be merged..." | |
else | |
echo "There is no active pull request. Proceeding with updating MAINTAINERS file." | |
git pull | |
exit 0 | |
fi | |
sleep $INTERVAL | |
elapsed_time=$((elapsed_time + INTERVAL)) | |
done | |
echo "Timeout reached. Proceeding with updating MAINTAINERS.yaml file with active pull request(s) present. It may result in merge conflict." | |
exit 0 | |
- name: Restore cached GitHub API calls | |
uses: actions/cache/restore@v4 | |
with: | |
path: ./.github/scripts/maintainers/github.api.cache.json | |
key: github-api-cache | |
restore-keys: | | |
github-api-cache- | |
- name: Installing Module | |
shell: bash | |
run: npm install js-yaml@4 --no-save | |
- name: Run script updating MAINTAINERS.yaml | |
uses: actions/github-script@v7 | |
env: | |
GH_TOKEN: ${{ github.token }} | |
MAINTAINERS_FILE_PATH: "${{ github.workspace }}/MAINTAINERS.yaml" | |
with: | |
script: | | |
const script = require('./.github/scripts/maintainers/index.js') | |
await script({github, context, core}) | |
- name: Save cached GitHub API calls | |
uses: actions/cache/save@v4 | |
with: | |
path: ./.github/scripts/maintainers/github.api.cache.json | |
# re-evaluate the key, so we update cache when file changes | |
key: github-api-cache-${{ hashfiles('./.github/scripts/maintainers/github.api.cache.json') }} | |
- name: Create PR with latest changes | |
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c # https://github.com/peter-evans/create-pull-request/releases/tag/v6.1.0 | |
with: | |
token: ${{ secrets.GH_TOKEN }} | |
commit-message: ${{ env.PR_TITLE }} | |
committer: asyncapi-bot <[email protected]> | |
author: asyncapi-bot <[email protected]> | |
title: ${{ env.PR_TITLE }} | |
branch: ${{ env.BRANCH_NAME }} | |
body: | | |
**Description** | |
- Update MAINTAINERS.yaml based on CODEOWNERS files across all repositories in the organization. | |
For details on why a maintainer was removed or changed, refer to the [Job summary page](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}). | |
- name: Report workflow run status to Slack | |
uses: rtCamp/action-slack-notify@4e5fb42d249be6a45a298f3c9543b111b02f7907 # https://github.com/rtCamp/action-slack-notify/releases/tag/v2.3.0 | |
if: failure() | |
env: | |
SLACK_WEBHOOK: ${{secrets.SLACK_CI_FAIL_NOTIFY}} | |
SLACK_TITLE: 🚨 Update MAINTAINERS.yaml file Workflow failed 🚨 | |
SLACK_MESSAGE: Failed to auto update MAINTAINERS.yaml file. | |
MSG_MINIMAL: true |