-
Notifications
You must be signed in to change notification settings - Fork 694
50 lines (44 loc) · 1.58 KB
/
add_contributor.yml
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
name: Add Contributor to AUTHORS.md
on:
pull_request:
types:
- opened
- synchronize
jobs:
add_contributor:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if contributor already exists
id: check_contributor
run: |
exists=$(grep -c -F "$GITHUB_ACTOR" AUTHORS.md || true)
if [[ $exists -gt 0 ]]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Get contributor's full name
id: get_full_name
if: steps.check_contributor.outputs.exists == 'false'
run: |
username=$GITHUB_ACTOR
access_token=$GITHUB_TOKEN
full_name=$(curl -s -H "Authorization: token $access_token" "https://api.github.com/users/$username" | jq -r '.name')
if [[ "$full_name" == "" || "$full_name" == "null" ]]; then
full_name='-'
fi
echo "full_name=$full_name" >> $GITHUB_OUTPUT
- name: Append contributor to AUTHORS.md
id: append_contributor
if: steps.check_contributor.outputs.exists == 'false'
run: |
full_name=${{ steps.get_full_name.outputs.full_name }}
echo "| $full_name | $GITHUB_ACTOR |" >> AUTHORS.md
- name: Commit and push changes to branch
id: commit_changes
if: steps.check_contributor.outputs.exists == 'false'
uses: pre-commit-ci/lite-action@v1.0.1
with:
msg: Add ${{ env.GITHUB_ACTOR }} to AUTHORS.md