-
Notifications
You must be signed in to change notification settings - Fork 4
91 lines (78 loc) · 2.82 KB
/
add_member.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: "Add new member to django-commons"
on:
issues:
types:
- opened
- reopened
labels:
- "New member"
jobs:
add-member:
name: "Add new member"
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
pull-requests: write
issues: write
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
BRANCH_NAME: "add-user/${{ github.event.issue.number }}"
steps:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Checkout code
uses: actions/checkout@v4
- name: Get username to add
id: get_username
run:
python -c "print('USERNAME='+'${{ github.event.issue.title }}'.split(' - ')[1])" >> $GITHUB_ENV
- name: Validate add user request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_USER: ${{ github.event.issue.user.login }}
run: |
# Check whether the user exists
set +e
gh api /users/${{ env.USERNAME }} > /dev/null
if [ $? -ne 0 ]; then
gh issue comment ${{ env.ISSUE_NUMBER }} --body "User ${{ env.USERNAME }} does not exist."
exit 1
fi
# Check if the username is in the title is the same as the user who opened the issue
if [ "${{ env.USERNAME }}" != "${{ env.ISSUE_USER }}" ]; then
gh issue comment ${{ env.ISSUE_NUMBER }} --body "If you want to add a different user, please create a PR for it"
exit 1
fi
# Check if the user is already a member of the org
gh api /orgs/django-commons/members/${{ env.USERNAME }} > /dev/null
if [ $? -eq 0 ]; then
gh issue comment ${{ env.ISSUE_NUMBER }} --body "User ${{ env.USERNAME }} is already a member of django-commons."
exit 1
fi
- name: Initialize mandatory git config
run: |
git config user.name "GitHub Actions"
git config user.email [email protected]
- name: Create branch
run: git checkout -b ${{ env.BRANCH_NAME }}
- name: Add user to the list
run: |
python scripts/add_member.py ${{ env.USERNAME }}
- name: Commit changes
run: |
git add terraform/production/org.tfvars
git commit -m "Add ${{ env.USERNAME }} to django-commons"
git push origin ${{ env.BRANCH_NAME }}
- name: Create pull request
run: |
gh pr create \
--title "Add ${{ env.USERNAME }} to django-commons" \
--body "Fix #${{ env.ISSUE_NUMBER }}" \
--base main \
--head ${{ env.BRANCH_NAME }}
--label "New member"
env:
GITHUB_TOKEN: ${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}