-
Notifications
You must be signed in to change notification settings - Fork 687
64 lines (55 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
name: Add new contributor to AUTHORS.md
on:
pull_request_target:
types:
- closed
jobs:
update-authors:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout develop branch
uses: actions/checkout@v4
with:
ref: 'develop'
fetch-depth: 0
persist-credentials: false
- name: Check if author is in AUTHORS.md
id: check-author
run: |
GH_USER="${{ github.event.pull_request.user.login }}"
# AUTHORS.md file already exist in repo, so can skip the conditional logic to create one if not exists
if ! grep -q "| ${GH_USER} |" AUTHORS.md; then
echo "new_author=true" >> $GITHUB_ENV
else
echo "new_author=false" >> $GITHUB_ENV
fi
- name: Add author to AUTHORS.md if not present
if: env.new_author == 'true'
run: |
GH_USER="${{ github.event.pull_request.user.login }}"
AUTHOR_NAME=$(curl -s https://api.github.com/users/${GH_USER} | jq -r '.name')
if [ -z "$AUTHOR_NAME" ]; then
AUTHOR_NAME="-"
fi
echo "| $AUTHOR_NAME | $GH_USER |" >> AUTHORS.md
- name: Commit updated AUTHORS.md
if: env.new_author == 'true'
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add AUTHORS.md
git commit -m "Add ${{ github.event.pull_request.user.login }} to AUTHORS.md"
- name: GitHub App token
if: env.new_author == 'true'
uses: tibdex/github-app-token@v2
id: generate-token
with:
app_id: ${{ secrets.LE_BOT_APP_ID }}
private_key: ${{ secrets.LE_BOT_PRIVATE_KEY }}
- name: Push changes to develop
if: env.new_author == 'true'
uses: ad-m/github-push-action@v0.8.0
with:
github_token: ${{ steps.generate-token.outputs.token }}
branch: 'develop'