Skip to content

Commit 9f930cc

Browse files
Merge pull request #204 from DSACMS/sachin/labor-hours-new
Fixed MAINTAINERS.md Automation - NEW
2 parents 6ee6ea4 + c7463e0 commit 9f930cc

File tree

6 files changed

+250
-192
lines changed

6 files changed

+250
-192
lines changed
Lines changed: 70 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,78 @@
1+
name: Update Contributors Information
2+
13
on:
2-
push:
3-
branches:
4-
- main
5-
workflow_dispatch:
4+
workflow_dispatch: {}
5+
schedule:
6+
# Weekly on Saturdays.
7+
- cron: "30 1 * * 6"
8+
push:
9+
branches: [main]
610

711
jobs:
8-
update-contributors:
9-
runs-on: ubuntu-latest
10-
name: Update contributors info in MAINTAINERS.md
11-
permissions:
12-
contents: write
13-
pull-requests: write
14-
steps:
15-
# Update contributor list
16-
- name: Contribute List
17-
uses: akhilmhdh/[email protected]
18-
env:
19-
{% raw %}
20-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21-
{% endraw %}
22-
with:
23-
# https://github.com/marketplace/actions/contribute-list#optional-parameters
24-
readme_path: MAINTAINERS.md
25-
use_username: false
26-
commit_message: "BOT: Update contributors info in MAINTAINERS.md"
12+
update-contributors:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Update contributor list
25+
id: contrib_list
26+
uses: akhilmhdh/[email protected]
27+
env:
28+
{% raw %}
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
{% endraw %}
31+
with:
32+
readme_path: MAINTAINERS.md
33+
use_username: false
34+
commit_message: "update contributors information"
35+
36+
- name: Get contributors count
37+
id: get_contributors
38+
env:
39+
{% raw %}
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
{% endraw %}
42+
43+
run: |
44+
OWNER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
45+
REPO=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)
46+
QUERY='query { repository(owner: \"'"$OWNER"'\", name: \"'"$REPO"'\") { collaborators { totalCount } } }'
47+
48+
CONTRIBUTORS=$(gh api \
49+
-H "Accept: application/vnd.github+json" \
50+
-H "X-GitHub-Api-Version: 2022-11-28" \
51+
"/repos/$OWNER/$REPO/contributors?per_page=100" | \
52+
jq '[.[] | select(.type != "Bot" and (.login | test("\\[bot\\]$") | not) and (.login | test("-bot$") | not))] | length')
53+
54+
echo "Total contributors: $CONTRIBUTORS"
55+
echo "contributors=$CONTRIBUTORS" >> $GITHUB_OUTPUT
56+
2757
28-
# Update contributor count
29-
- name: Checkout repository
30-
uses: actions/checkout@v4
58+
- name: Update MAINTAINERS.md
59+
run: |
60+
{% raw %}
61+
CONTRIBUTORS="${{ steps.get_contributors.outputs.contributors }}"
62+
{% endraw %}
3163
32-
- name: Pull changes from contributors-readme-action
33-
run: |
34-
git pull
64+
perl -i -pe 's/(<!--CONTRIBUTOR COUNT START-->).*?(<!--CONTRIBUTOR COUNT END-->)/$1 '"$CONTRIBUTORS"' $2/' MAINTAINERS.md
3565
36-
- name: Get repository contributors count
37-
id: get_contributors
38-
# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-contributors
39-
# https://docs.github.com/en/graphql/reference/objects#repositorycollaboratorconnection
40-
# https://docs.github.com/en/graphql/guides/forming-calls-with-graphql#communicating-with-graphql
41-
# CANNOT have newlines!
42-
run: |
43-
{% raw %}
44-
OWNER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
45-
REPO=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)
46-
QUERY='query { repository(owner: \"'"$OWNER"'\", name: \"'"$REPO"'\") { collaborators { totalCount } } }'
47-
CONTRIBUTORS=$(curl -s -X POST -H "Authorization: bearer ${{ secrets.GITHUB_TOKEN }}" -H "Content-Type: application/json" -d "{\"query\": \"$QUERY\"}" https://api.github.com/graphql | jq -r '.data.repository.collaborators.totalCount')
48-
echo "Total contributors: $CONTRIBUTORS"
49-
echo "contributors=$CONTRIBUTORS" >> $GITHUB_OUTPUT
50-
{% endraw %}
66+
git config user.name 'github-actions[bot]'
67+
git config user.email 'github-actions[bot]@users.noreply.github.com'
68+
git add MAINTAINERS.md
69+
git commit -m "update contributors count to $CONTRIBUTORS" || exit 0
5170
52-
- name: Replace slug in MAINTAINERS.md with number of contributors
53-
# https://stackoverflow.com/questions/10613643/replace-a-unknown-string-between-two-known-strings-with-sed
54-
run: |
55-
{% raw %}
56-
CONTRIBUTORS=${{ steps.get_contributors.outputs.contributors }}
57-
sed -i 's/<!--CONTRIBUTOR COUNT START-->.*<!--CONTRIBUTOR COUNT END-->/<!--CONTRIBUTOR COUNT START--> '"$CONTRIBUTORS"' <!--CONTRIBUTOR COUNT END-->/g' MAINTAINERS.md
58-
{% endraw %}
71+
- name: Push protected
72+
uses: CasperWA/push-protected@v2
73+
with:
74+
{% raw %}
75+
token: ${{ secrets.PUSH_TO_PROTECTED_BRANCH }}
76+
{% endraw %}
5977

60-
- name: Commit and push changes
61-
# https://github.com/orgs/community/discussions/26560#discussioncomment-3531273
62-
# commit changes, but if no changes exist, then exit cleanly
63-
run: |
64-
git config user.name 'github-actions[bot]'
65-
git config user.email 'github-actions[bot]@users.noreply.github.com'
66-
git add MAINTAINERS.md
67-
git commit -m "BOT: Update contributors info in MAINTAINERS.md" || exit 0
68-
git push
78+
branch: main

tier2/{{cookiecutter.project_slug}}/MAINTAINERS.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This is a list of maintainers for this project. See [CODEOWNERS.md](./CODEOWNERS
1111

1212
## Contributors
1313

14+
<!-- In order to automatically update the MAINTAINERS.md, you must enter a secret into your Secrets and Variables under Actions within your repository settings. The name of the secret must be PUSH_TO_PROTECTED_BRANCH and the value must be a Personal Access Token with specific permissions. Please follow [this link](https://github.com/CasperWA/push-protected?tab=readme-ov-file#notes-on-token-and-user-permissions) for more information. -->
15+
1416
Total number of contributors: <!--CONTRIBUTOR COUNT START--> <!--CONTRIBUTOR COUNT END-->
1517

1618
<!-- readme: contributors -start -->
@@ -31,11 +33,21 @@ Total number of contributors: <!--CONTRIBUTOR COUNT START--> <!--CONTRIBUTOR COU
3133
* [Schedule](#schedule)
3234
* [Communication and Workflow](#communication-and-workflow)
3335
<!-- * [Beta Features](#beta-features) -->
34-
* [Preparing a Release Candidate](#preparing-a-release-candidate)
35-
* [Incorporating feedback from review](#incorporating-feedback-from-review)
36-
* [Making a Release](#making-a-release)
37-
* [Auto Changelog](#auto-changelog)
38-
* [Hotfix Releases](#hotfix-releases)
36+
- [Maintainers](#maintainers)
37+
- [Maintainers:](#maintainers-1)
38+
- [Contributors](#contributors)
39+
- [Tier 2 Release Guidelines](#tier-2-release-guidelines)
40+
- [Table of Contents](#table-of-contents)
41+
- [Versioning](#versioning)
42+
- [Release Process](#release-process)
43+
- [Goals](#goals)
44+
- [Schedule](#schedule)
45+
- [Communication and Workflow](#communication-and-workflow)
46+
- [Preparing a Release Candidate](#preparing-a-release-candidate)
47+
- [Incorporating feedback from review](#incorporating-feedback-from-review)
48+
- [Making a Release](#making-a-release)
49+
- [Auto Changelog](#auto-changelog)
50+
- [Hotfix Releases](#hotfix-releases)
3951

4052
## Versioning
4153

Lines changed: 70 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,78 @@
1+
name: Update Contributors Information
2+
13
on:
2-
push:
3-
branches:
4-
- main
5-
workflow_dispatch:
4+
workflow_dispatch: {}
5+
schedule:
6+
# Weekly on Saturdays.
7+
- cron: "30 1 * * 6"
8+
push:
9+
branches: [main]
610

711
jobs:
8-
update-contributors:
9-
runs-on: ubuntu-latest
10-
name: Update contributors info in MAINTAINERS.md
11-
permissions:
12-
contents: write
13-
pull-requests: write
14-
steps:
15-
# Update contributor list
16-
- name: Contribute List
17-
uses: akhilmhdh/[email protected]
18-
env:
19-
{% raw %}
20-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21-
{% endraw %}
22-
with:
23-
# https://github.com/marketplace/actions/contribute-list#optional-parameters
24-
readme_path: MAINTAINERS.md
25-
use_username: false
26-
commit_message: "BOT: Update contributors info in MAINTAINERS.md"
12+
update-contributors:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Update contributor list
25+
id: contrib_list
26+
uses: akhilmhdh/[email protected]
27+
env:
28+
{% raw %}
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
{% endraw %}
31+
with:
32+
readme_path: MAINTAINERS.md
33+
use_username: false
34+
commit_message: "update contributors information"
35+
36+
- name: Get contributors count
37+
id: get_contributors
38+
env:
39+
{% raw %}
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
{% endraw %}
42+
43+
run: |
44+
OWNER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
45+
REPO=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)
46+
QUERY='query { repository(owner: \"'"$OWNER"'\", name: \"'"$REPO"'\") { collaborators { totalCount } } }'
47+
48+
CONTRIBUTORS=$(gh api \
49+
-H "Accept: application/vnd.github+json" \
50+
-H "X-GitHub-Api-Version: 2022-11-28" \
51+
"/repos/$OWNER/$REPO/contributors?per_page=100" | \
52+
jq '[.[] | select(.type != "Bot" and (.login | test("\\[bot\\]$") | not) and (.login | test("-bot$") | not))] | length')
53+
54+
echo "Total contributors: $CONTRIBUTORS"
55+
echo "contributors=$CONTRIBUTORS" >> $GITHUB_OUTPUT
56+
2757
28-
# Update contributor count
29-
- name: Checkout repository
30-
uses: actions/checkout@v4
58+
- name: Update MAINTAINERS.md
59+
run: |
60+
{% raw %}
61+
CONTRIBUTORS="${{ steps.get_contributors.outputs.contributors }}"
62+
{% endraw %}
3163
32-
- name: Pull changes from contributors-readme-action
33-
run: |
34-
git pull
64+
perl -i -pe 's/(<!--CONTRIBUTOR COUNT START-->).*?(<!--CONTRIBUTOR COUNT END-->)/$1 '"$CONTRIBUTORS"' $2/' MAINTAINERS.md
3565
36-
- name: Get repository contributors count
37-
id: get_contributors
38-
# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-contributors
39-
# https://docs.github.com/en/graphql/reference/objects#repositorycollaboratorconnection
40-
# https://docs.github.com/en/graphql/guides/forming-calls-with-graphql#communicating-with-graphql
41-
# CANNOT have newlines!
42-
run: |
43-
{% raw %}
44-
OWNER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
45-
REPO=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)
46-
QUERY='query { repository(owner: \"'"$OWNER"'\", name: \"'"$REPO"'\") { collaborators { totalCount } } }'
47-
CONTRIBUTORS=$(curl -s -X POST -H "Authorization: bearer ${{ secrets.GITHUB_TOKEN }}" -H "Content-Type: application/json" -d "{\"query\": \"$QUERY\"}" https://api.github.com/graphql | jq -r '.data.repository.collaborators.totalCount')
48-
echo "Total contributors: $CONTRIBUTORS"
49-
echo "contributors=$CONTRIBUTORS" >> $GITHUB_OUTPUT
50-
{% endraw %}
66+
git config user.name 'github-actions[bot]'
67+
git config user.email 'github-actions[bot]@users.noreply.github.com'
68+
git add MAINTAINERS.md
69+
git commit -m "update contributors count to $CONTRIBUTORS" || exit 0
5170
52-
- name: Replace slug in MAINTAINERS.md with number of contributors
53-
# https://stackoverflow.com/questions/10613643/replace-a-unknown-string-between-two-known-strings-with-sed
54-
run: |
55-
{% raw %}
56-
CONTRIBUTORS=${{ steps.get_contributors.outputs.contributors }}
57-
sed -i 's/<!--CONTRIBUTOR COUNT START-->.*<!--CONTRIBUTOR COUNT END-->/<!--CONTRIBUTOR COUNT START--> '"$CONTRIBUTORS"' <!--CONTRIBUTOR COUNT END-->/g' MAINTAINERS.md
58-
{% endraw %}
71+
- name: Push protected
72+
uses: CasperWA/push-protected@v2
73+
with:
74+
{% raw %}
75+
token: ${{ secrets.PUSH_TO_PROTECTED_BRANCH }}
76+
{% endraw %}
5977

60-
- name: Commit and push changes
61-
# https://github.com/orgs/community/discussions/26560#discussioncomment-3531273
62-
# commit changes, but if no changes exist, then exit cleanly
63-
run: |
64-
git config user.name 'github-actions[bot]'
65-
git config user.email 'github-actions[bot]@users.noreply.github.com'
66-
git add MAINTAINERS.md
67-
git commit -m "BOT: Update contributors info in MAINTAINERS.md" || exit 0
68-
git push
78+
branch: main

tier3/{{cookiecutter.project_slug}}/MAINTAINERS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ This is a list of maintainers for this project. See [CODEOWNERS.md](./CODEOWNERS
2121

2222
## Contributors
2323

24+
<!-- In order to automatically update the MAINTAINERS.md, you must enter a secret into your Secrets and Variables under Actions within your repository settings. The name of the secret must be PUSH_TO_PROTECTED_BRANCH and the value must be a Personal Access Token with specific permissions. Please follow [this link](https://github.com/CasperWA/push-protected?tab=readme-ov-file#notes-on-token-and-user-permissions) for more information. -->
25+
2426
Total number of contributors: <!--CONTRIBUTOR COUNT START--> <!--CONTRIBUTOR COUNT END-->
2527

2628
<!-- readme: contributors -start -->

0 commit comments

Comments
 (0)