forked from asyncapi/community
-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (109 loc) · 4.94 KB
/
update-maintainers.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# 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