Skip to content

Merge pull request #6 from DSACMS/nat/additions #11

Merge pull request #6 from DSACMS/nat/additions

Merge pull request #6 from DSACMS/nat/additions #11

Workflow file for this run

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/contributors-readme-action@v2.3.10
env:
{% raw %}

Check failure on line 19 in .github/workflows/contributors.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/contributors.yml

Invalid workflow file

You have an error in your yaml syntax on line 19
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
{% endraw %}
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: |
{% raw %}
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
{% endraw %}
- 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: |
{% raw %}
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
{% endraw %}
- 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