Skip to content

Commit

Permalink
Merge pull request #102 from DSACMS/4-proj-automatically-generate-a-c…
Browse files Browse the repository at this point in the history
…ontributors-list-in-maintainersmd-file

Automatically Generate a Contributors List in MAINTAINERS.md file
  • Loading branch information
IsaacMilarky authored Jun 25, 2024
2 parents 73cb3a1 + e577367 commit 8b6f2ec
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
on:
push:
branches:
- main
workflow_dispatch:

jobs:
update-contributors:
runs-on: ubuntu-latest
name: Update contributors info in MAINTAINERS.md
permissions:
contents: write
pull-requests: write
steps:
# Update contributor list
- name: Contribute List
uses: akhilmhdh/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# https://github.com/marketplace/actions/contribute-list#optional-parameters
readme_path: MAINTAINERS.md
use_username: false
commit_message: "BOT: Update contributors info in MAINTAINERS.md"

# Update contributor count
- name: Checkout repository
uses: actions/checkout@v4

- name: Pull changes from contributors-readme-action
run: |
git pull
- name: Get repository contributors count
id: get_contributors
# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-contributors
# https://docs.github.com/en/graphql/reference/objects#repositorycollaboratorconnection
# https://docs.github.com/en/graphql/guides/forming-calls-with-graphql#communicating-with-graphql
# CANNOT have newlines!
run: |
OWNER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
REPO=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)
QUERY='query { repository(owner: \"'"$OWNER"'\", name: \"'"$REPO"'\") { collaborators { totalCount } } }'
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')
echo "Total contributors: $CONTRIBUTORS"
echo "contributors=$CONTRIBUTORS" >> $GITHUB_OUTPUT
- name: Replace slug in MAINTAINERS.md with number of contributors
# https://stackoverflow.com/questions/10613643/replace-a-unknown-string-between-two-known-strings-with-sed
run: |
CONTRIBUTORS=${{ steps.get_contributors.outputs.contributors }}
sed -i 's/<!--CONTRIBUTOR COUNT START-->.*<!--CONTRIBUTOR COUNT END-->/<!--CONTRIBUTOR COUNT START--> '"$CONTRIBUTORS"' <!--CONTRIBUTOR COUNT END-->/g' MAINTAINERS.md
- name: Commit and push changes
# https://github.com/orgs/community/discussions/26560#discussioncomment-3531273
# commit changes, but if no changes exist, then exit cleanly
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add MAINTAINERS.md
git commit -m "BOT: Update contributors info in MAINTAINERS.md" || exit 0
git push
6 changes: 6 additions & 0 deletions tier2/{{cookiecutter.project_slug}}/MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ This is a list of maintainers for this project. See [CODEOWNERS.md](./CODEOWNERS
|:-----|:-----|:-----|:-----|
| {role} | {names} | {github usernames} | {affiliations}|

## Contributors

Total number of contributors: <!--CONTRIBUTOR COUNT START--> <!--CONTRIBUTOR COUNT END-->

<!-- readme: contributors -start -->
<!-- readme: contributors -end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
on:
push:
branches:
- main
workflow_dispatch:

jobs:
update-contributors:
runs-on: ubuntu-latest
name: Update contributors info in MAINTAINERS.md
permissions:
contents: write
pull-requests: write
steps:
# Update contributor list
- name: Contribute List
uses: akhilmhdh/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# https://github.com/marketplace/actions/contribute-list#optional-parameters
readme_path: MAINTAINERS.md
use_username: false
commit_message: "BOT: Update contributors info in MAINTAINERS.md"

# Update contributor count
- name: Checkout repository
uses: actions/checkout@v4

- name: Pull changes from contributors-readme-action
run: |
git pull
- name: Get repository contributors count
id: get_contributors
# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-contributors
# https://docs.github.com/en/graphql/reference/objects#repositorycollaboratorconnection
# https://docs.github.com/en/graphql/guides/forming-calls-with-graphql#communicating-with-graphql
# CANNOT have newlines!
run: |
OWNER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
REPO=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)
QUERY='query { repository(owner: \"'"$OWNER"'\", name: \"'"$REPO"'\") { collaborators { totalCount } } }'
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')
echo "Total contributors: $CONTRIBUTORS"
echo "contributors=$CONTRIBUTORS" >> $GITHUB_OUTPUT
- name: Replace slug in MAINTAINERS.md with number of contributors
# https://stackoverflow.com/questions/10613643/replace-a-unknown-string-between-two-known-strings-with-sed
run: |
CONTRIBUTORS=${{ steps.get_contributors.outputs.contributors }}
sed -i 's/<!--CONTRIBUTOR COUNT START-->.*<!--CONTRIBUTOR COUNT END-->/<!--CONTRIBUTOR COUNT START--> '"$CONTRIBUTORS"' <!--CONTRIBUTOR COUNT END-->/g' MAINTAINERS.md
- name: Commit and push changes
# https://github.com/orgs/community/discussions/26560#discussioncomment-3531273
# commit changes, but if no changes exist, then exit cleanly
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add MAINTAINERS.md
git commit -m "BOT: Update contributors info in MAINTAINERS.md" || exit 0
git push
9 changes: 8 additions & 1 deletion tier3/{{cookiecutter.project_slug}}/MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ This is a list of maintainers for this project. See [CODEOWNERS.md](./CODEOWNERS
| member | active contributor in the community | multiple contributions to the project. | PROJECT GitHub org Committer Team|
| reviewer | review contributions from other members | history of review and authorship in a subproject | MAINTAINERS file reviewer entry, and GitHub Org Triage Team|
| approver | approve accepting contributions | highly experienced and active reviewer + contributor to a subproject | MAINTAINERS file approver entry and GitHub Triage Team |
| lead | set direction and priorities for a subproject | demonstrated responsibility and excellent technical judgement for the subproject | MAINTAINERS file owner entry and GitHub Org Admin Team|
| lead | set direction and priorities for a subproject | demonstrated responsibility and excellent technical judgement for the subproject | MAINTAINERS file owner entry and GitHub Org Admin Team|

## Contributors

Total number of contributors: <!--CONTRIBUTOR COUNT START--> <!--CONTRIBUTOR COUNT END-->

<!-- readme: contributors -start -->
<!-- readme: contributors -end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
on:
push:
branches:
- main
workflow_dispatch:

jobs:
update-contributors:
runs-on: ubuntu-latest
name: Update contributors info in MAINTAINERS.md
permissions:
contents: write
pull-requests: write
steps:
# Update contributor list
- name: Contribute List
uses: akhilmhdh/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# https://github.com/marketplace/actions/contribute-list#optional-parameters
readme_path: MAINTAINERS.md
use_username: false
commit_message: "BOT: Update contributors info in MAINTAINERS.md"

# Update contributor count
- name: Checkout repository
uses: actions/checkout@v4

- name: Pull changes from contributors-readme-action
run: |
git pull
- name: Get repository contributors count
id: get_contributors
# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-contributors
# https://docs.github.com/en/graphql/reference/objects#repositorycollaboratorconnection
# https://docs.github.com/en/graphql/guides/forming-calls-with-graphql#communicating-with-graphql
# CANNOT have newlines!
run: |
OWNER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
REPO=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)
QUERY='query { repository(owner: \"'"$OWNER"'\", name: \"'"$REPO"'\") { collaborators { totalCount } } }'
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')
echo "Total contributors: $CONTRIBUTORS"
echo "contributors=$CONTRIBUTORS" >> $GITHUB_OUTPUT
- name: Replace slug in MAINTAINERS.md with number of contributors
# https://stackoverflow.com/questions/10613643/replace-a-unknown-string-between-two-known-strings-with-sed
run: |
CONTRIBUTORS=${{ steps.get_contributors.outputs.contributors }}
sed -i 's/<!--CONTRIBUTOR COUNT START-->.*<!--CONTRIBUTOR COUNT END-->/<!--CONTRIBUTOR COUNT START--> '"$CONTRIBUTORS"' <!--CONTRIBUTOR COUNT END-->/g' MAINTAINERS.md
- name: Commit and push changes
# https://github.com/orgs/community/discussions/26560#discussioncomment-3531273
# commit changes, but if no changes exist, then exit cleanly
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add MAINTAINERS.md
git commit -m "BOT: Update contributors info in MAINTAINERS.md" || exit 0
git push
13 changes: 10 additions & 3 deletions tier4/{{cookiecutter.project_slug}}/MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<!-- TODO: Who are the points of contact in your project who are responsible/accountable for the project? This can often be an engineering or design manager or leader, who may or may not be the primary maintainers of the project.-->
This is a list of maintainers for this project. See [CODEOWNERS.md](./CODEOWNERS.md) for list of reviewers for different parts of the codebase. Team members include:

Maintainers:
## Maintainers:
<!-- TODO: What groups/domains are maintainers a part of? Does your project have domains/areas that are maintained by specific people? List @USERNAMES directly, or any @ALIASES for groups/teams.-->
-

Approvers:
## Approvers:
-

Reviewers:
## Reviewers:
-

| Roles | Responsibilities| Requirements | Defined by|
Expand All @@ -18,3 +18,10 @@ Reviewers:
| reviewer | review contributions from other members | history of review and authorship in a subproject | MAINTAINERS file reviewer entry, and GitHub Org Triage Team|
| approver | approve accepting contributions | highly experienced and active reviewer + contributor to a subproject | MAINTAINERS file approver entry and GitHub Triage Team |
| lead | set direction and priorities for a subproject | demonstrated responsibility and excellent technical judgement for the subproject | MAINTAINERS file owner entry and GitHub Org Admin Team|

## Contributors

Total number of contributors: <!--CONTRIBUTOR COUNT START--> <!--CONTRIBUTOR COUNT END-->

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

0 comments on commit 8b6f2ec

Please sign in to comment.