-
Notifications
You must be signed in to change notification settings - Fork 183
162 lines (142 loc) · 6.24 KB
/
create_pr_with_new_address.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Process Issue
on:
issue_comment:
types: [created]
jobs:
process-issue:
runs-on: ubuntu-latest
if: contains(github.event.issue.labels.*.name, 'add-new-address') && startsWith(github.event.comment.body, '/')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if comment is "/execute" by repo owner
id: check-comment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.TOKEN_GITHUB_READ_ORG_TEAMS }} # Important: This secret with read permissions on the teams information must be configured in repository settings -> secrets -> actions
script: |
const comment = context.payload.comment.body;
const teamMembers = await github.rest.teams.listMembersInOrg({
org: 'safe-global',
team_slug: 'core-api',
});
const isMember = context.payload.sender.type === 'User' && teamMembers.data.some(member => member.login === context.payload.sender.login);
if (comment.trim() === '/execute' && isMember) {
console.log('The comment is "/execute" by a authorised member.');
return true;
}
console.log('The comment is not "/execute" or not by a authorised member.');
return false;
- name: Add comment to issue with starting message
if: steps.check-comment.outputs.result == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '🚀 Starting to apply the changes for the new address!'
})
- name: Add comment to issue with command failure
if: steps.check-comment.outputs.result == 'false'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ Wrong comment or invalid permissions!'
})
- name: Get issue inputs
if: steps.check-comment.outputs.result == 'true'
id: get-issue-inputs
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueBody = context.payload.issue.body.replaceAll("_No response_", "");
const titles = {
summary: 'Summary',
chainId: 'Chain ID',
chainDetailUrl: 'Chain detail URL',
rpcUrl: 'RPC URL',
blockscoutClientUrl: 'Blockscout Client URL',
etherscanClientUrl: 'Etherscan Client URL',
etherscanClientApiUrl: 'Etherscan Client API URL',
version: 'Version',
addressMasterCopy: 'Address \\(Master copy\\)',
txHashMasterCopy: 'Deployment Tx hash \\(Master copy\\)',
blockExplorerUrlMasterCopy: 'Block explorer URL \\(Master copy\\)',
addressMasterCopyL2: 'Address \\(Master copy L2\\)',
txHashMasterCopyL2: 'Deployment Tx hash \\(Master copy L2\\)',
blockExplorerUrlMasterCopyL2: 'Block explorer URL \\(Master copy L2\\)',
addressProxy: 'Address \\(Proxy factory\\)',
txHashProxy: 'Deployment Tx hash \\(Proxy factory\\)',
blockExplorerUrlProxy: 'Block explorer URL \\(Proxy factory\\)',
};
const buildPattern = title => new RegExp(`### ${title}(?:\\r\\n\\r\\n|\\n\\n|\\n|\\r\\n)(.+?)(?:\\r\\n\\r\\n|\\n\\n|\\n|\\r\\n)`);
const extractInfo = (pattern, text) => {
const match = text.match(pattern);
return match ? match[1].trim() : null;
};
const extractedInfo = {};
Object.keys(titles).forEach(key => {
const pattern = buildPattern(titles[key]);
extractedInfo[key] = extractInfo(pattern, issueBody);
});
console.log('Extracted Info:', extractedInfo);
return extractedInfo;
- name: Setup Python
if: steps.check-comment.outputs.result == 'true'
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
if: steps.check-comment.outputs.result == 'true'
run: |
pip install -U PyGithub safe-eth-py@git+https://github.com/safe-global/safe-eth-py@main pre-commit -r requirements-test.txt
pre-commit install
- name: Process Issue and Create PR
if: steps.check-comment.outputs.result == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_BODY_INFO: ${{ steps.get-issue-inputs.outputs.result }}
GITHUB_REPOSITORY_NAME: 'safe-global/safe-eth-py'
run: |
python .github/scripts/github_adding_addresses/create_pr_with_new_address.py
- uses: fregante/setup-git-user@v2
- name: Run pre-commit
if: steps.check-comment.outputs.result == 'true'
run: |
issue_inputs='${{ steps.get-issue-inputs.outputs.result }}'
chain_id=$(echo "$issue_inputs" | jq -r '.chainId')
version=$(echo "$issue_inputs" | jq -r '.version')
branch_name="add-new-chain-${chain_id}-${version}-addresses"
git pull origin main
git fetch
git checkout -b $branch_name origin/$branch_name
pre-commit run --all-files || true
if [[ $(git status --porcelain) ]]; then
git add .
git commit -m "Apply linter fixes"
git pull & git push
else
echo "No changes to commit."
fi
- name: Add comment to issue
if: steps.check-comment.outputs.result == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '✅ Execution finished, please review the PR and merge it.'
})