-
Notifications
You must be signed in to change notification settings - Fork 84
123 lines (108 loc) · 4.61 KB
/
generate-config.yaml
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
name: Update config
on:
pull_request_target:
types: [closed]
permissions:
contents: write
pull-requests: write
jobs:
update-config:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHAINS_PAT: ${{ secrets.CHAINS_PAT }}
EXTERNAL_REPO: ${{ secrets.EXTERNAL_REPO }}
steps:
- name: Checkout axelar-configs repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check if PR was merged
id: check_if_merged
run: |
if [ "${{ github.event.pull_request.merged }}" != "true" ]; then
echo "PR was not merged. Exiting."
exit 0
fi
- name: Get the merge commit SHA
id: merge_commit
run: |
MERGE_COMMIT=$(git log -1 --pretty=format:"%H")
echo "MERGE_COMMIT=$MERGE_COMMIT" >> $GITHUB_ENV
- name: Determine NETWORK
id: determine_network
run: |
echo "Checking modified files in commit ${{ env.MERGE_COMMIT }}"
MODIFIED_FILES=$(git diff --name-only HEAD~1..HEAD)
echo "Modified files: $MODIFIED_FILES"
if echo "$MODIFIED_FILES" | grep -q "registry/mainnet/interchain/squid.tokenlist.json"; then
echo "NETWORK=mainnet" >> $GITHUB_ENV
elif echo "$MODIFIED_FILES" | grep -q "registry/testnet/interchain/squid.tokenlist.json"; then
echo "NETWORK=testnet" >> $GITHUB_ENV
else
echo "No relevant changes detected."
echo "NETWORK=none" >> $GITHUB_ENV
exit 0
fi
- name: Checkout external repository
if: env.NETWORK != 'none'
uses: actions/checkout@v4
with:
repository: axelarnetwork/${{ secrets.EXTERNAL_REPO }}
path: ${{ secrets.EXTERNAL_REPO }}
token: ${{ secrets.CHAINS_PAT }}
- name: Install jq
if: env.NETWORK != 'none'
run: sudo apt-get install -y jq
- name: Setup Branch Name
if: env.NETWORK != 'none'
id: branch-name
run: echo "::set-output name=branch::feat/config-update-$(date +'%Y-%m-%d-%H-%M-%S')"
- name: Create branch and generate config
if: env.NETWORK != 'none'
run: |
cd ${{ secrets.EXTERNAL_REPO }}
curl -sSL https://install.python-poetry.org | python3 -
poetry install
git config --local user.email "[email protected]"
git config --local user.name "devops"
git checkout -b ${{ steps.branch-name.outputs.branch }}
poetry run python generate.py --network ${{ env.NETWORK }} --generate-config
git add --all
git commit -m "create branch ${{ steps.branch-name.outputs.branch }}"
git push --set-upstream origin ${{ steps.branch-name.outputs.branch }}
- name: Create Pull Request
if: env.NETWORK != 'none'
id: create_pr
run: |
cd ${{ secrets.EXTERNAL_REPO }}
PR_TITLE="feat: update configurations for ${{ env.NETWORK }}"
PR_BODY="Auto-generated PR with updated configuration files"
PR_HEAD="${{ steps.branch-name.outputs.branch }}"
PR_BASE="main"
RESPONSE=$(curl -s -X POST \
-H "Authorization: token ${{ secrets.CHAINS_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/axelarnetwork/${{ secrets.EXTERNAL_REPO }}/pulls \
-d "{\"title\":\"$PR_TITLE\",\"body\":\"$PR_BODY\",\"head\":\"$PR_HEAD\",\"base\":\"$PR_BASE\"}")
PR_NUMBER=$(echo $RESPONSE | jq -r .number)
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- name: Merge Pull Request
if: env.NETWORK != 'none'
run: |
PR_NUMBER=${{ env.PR_NUMBER }}
PR_TITLE="feat: update configurations for ${{ env.NETWORK }}"
curl -s -X PUT \
-H "Authorization: token ${{ secrets.CHAINS_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/axelarnetwork/${{ secrets.EXTERNAL_REPO }}/pulls/$PR_NUMBER/merge \
-d "{\"commit_title\":\"Merge PR #$PR_NUMBER: $PR_TITLE\",\"merge_method\":\"squash\"}"
- name: Publish configuration
if: env.NETWORK != 'none'
run: |
WORKFLOW_FILE="publish-${{ env.NETWORK }}-configs.yaml"
curl -X POST \
-H "Authorization: token ${{ secrets.CHAINS_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/axelarnetwork/${{ secrets.EXTERNAL_REPO }}/actions/workflows/$WORKFLOW_FILE/dispatches \
-d '{"ref":"main"}'