-
Notifications
You must be signed in to change notification settings - Fork 712
65 lines (53 loc) · 2.04 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: Add new contributor to AUTHORS.md
on:
pull_request:
types: [opened]
jobs:
check_contributor_exists:
runs-on: ubuntu-latest
outputs:
is_contributor_in_file: ${{ steps.check_contributor_step.outputs.exists }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: .
- name: Check if contributor already exists
id: check_contributor_step
run: |
exists=$(grep -c -F "${{ github.event.pull_request.user.login }}" AUTHORS.md || true)
if [[ $exists -gt 0 ]]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
add_contributor:
runs-on: ubuntu-latest
needs: check_contributor_exists
if: needs.check_contributor_exists.outputs.is_contributor_in_file == 'false'
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Git and checkout PR's branch
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git fetch origin refs/pull/${{ github.event.number }}/head:pr
git checkout pr
- name: Get contributor's full name and append to AUTHORS.md file
run: |
username=${{ github.event.pull_request.user.login }}
full_name=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/users/$username" | jq -r '.name')
if [[ "$full_name" == "" || "$full_name" == "null" ]]; then
full_name='-'
fi
echo "| $full_name | $username |" >> AUTHORS.md
- name: Commit and push changes to the contributor's PR branch
run: |
git add AUTHORS.md
git commit -m "Add ${{ github.event.pull_request.user.login }} to AUTHORS.md"
git push origin pr:${{ github.event.pull_request.head.ref }}