[New chain]: Bitrock Testnet #25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 PyGithub | |
pip install safe-eth-py | |
- 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 | |
- 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.' | |
}) |