-
Notifications
You must be signed in to change notification settings - Fork 0
40 lines (35 loc) · 1.54 KB
/
update-contributors.yml
File metadata and controls
40 lines (35 loc) · 1.54 KB
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
name: Update Contributors
on:
push:
branches:
- main
workflow_dispatch:
jobs:
update-contributors:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GH_TOKEN }}
- name: Retrieve contributors and update README
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
REPO: ${{ github.repository }}
run: |
curl -s -H "Authorization: token ${GH_TOKEN}" "https://api.github.com/repos/${REPO}/contributors" > contributors.json
CONTRIBUTORS_TABLE=$(jq -r '.[] | "| [](" + .html_url + ") | [" + .login + "]( " + .html_url + " ) |"' contributors.json | paste -sd "\n" -)
NEW_SECTION=$(printf "<!-- CONTRIBUTORS:START -->\n\n| Avatar | Username |\n|--------|----------|\n%s\n\n<!-- CONTRIBUTORS:END -->" "$CONTRIBUTORS_TABLE")
ESCAPED_CONTENT=$(printf '%s' "$NEW_SECTION" | sed -e 's/[\/&]/\\&/g')
perl -0777 -pi -e "s/<!-- CONTRIBUTORS:START -->.*?<!-- CONTRIBUTORS:END -->/${ESCAPED_CONTENT}/s" README.md
- name: Commit updated README
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
if ! git diff-index --quiet HEAD; then
git commit -m "Update contributors list [skip ci]"
fi
- name: Push changes
uses: ad-m/github-push-action@v0.6.0
with:
github_token: ${{ secrets.GH_TOKEN }}