-
Notifications
You must be signed in to change notification settings - Fork 23
178 lines (153 loc) · 5.84 KB
/
update-version.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Update Installer
on:
schedule:
- cron: '0 0 * * *' # Runs every day at midnight
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
update-testnet-version:
runs-on: ubuntu-latest
env:
RPC_URL: https://rpc.testnet.osmosis.zone/abci_info
VERSION_VAR: TESTNET_VERSION
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check current version from RPC
run: |
RESPONSE=$(curl -s --retry 5 --retry-delay 5 --connect-timeout 30 -H "Accept: application/json" ${{ env.RPC_URL }})
NETWORK_VERSION=$(echo $RESPONSE | jq -r '.result.response.version')
echo "NETWORK_VERSION=$NETWORK_VERSION" >> $GITHUB_ENV
- name: Get current version from file
run: |
FILE_VERSION=$(grep '${{ env.VERSION_VAR }}' i.py | cut -d'"' -f2 | head -n 1)
echo "FILE_VERSION=$FILE_VERSION" >> $GITHUB_ENV
- name: Validate version format
run: |
if [[ ! ${{ env.NETWORK_VERSION }} =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$ ]]; then
echo "Version ${{ env.NETWORK_VERSION }} does not match the format X.Y.Z or X.Y.Z-rcN"
exit 1
fi
- name: Compare versions
id: compare_versions
run: |
compare_versions() {
local v1=$1
local v2=$2
if [[ $v1 == $v2 ]]; then
echo "COMPARE_RESULT=0" >> $GITHUB_ENV
return
fi
local IFS=.
local i
local version1=($v1)
local version2=($v2)
for ((i=0; i<${#version1[@]}; i++)); do
if [[ ${version1[i]} -gt ${version2[i]} ]]; then
echo "COMPARE_RESULT=1" >> $GITHUB_ENV
return
fi
if [[ ${version1[i]} -lt ${version2[i]} ]]; then
echo "COMPARE_RESULT=2" >> $GITHUB_ENV
return
fi
done
echo "COMPARE_RESULT=0" >> $GITHUB_ENV
}
compare_versions ${{ env.NETWORK_VERSION }} ${{ env.FILE_VERSION }}
- name: Generate branch name
if: env.COMPARE_RESULT == 1
run: |
RANDOM_ID=$(openssl rand -hex 6)
BRANCH_NAME="UPDATE-${{ env.VERSION_VAR }}-TO-${{ env.NETWORK_VERSION }}-$RANDOM_ID"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Update version if different
if: env.COMPARE_RESULT == 1
run: |
sed -i "s/${{ env.VERSION_VAR }} = \".*\"/${{ env.VERSION_VAR }} = \"${{ env.NETWORK_VERSION }}\"/" i.py
- name: Create Pull Request
if: env.COMPARE_RESULT == 1
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update ${{ env.VERSION_VAR }} version to ${{ env.NETWORK_VERSION }}
base: main
branch: ${{env.BRANCH_NAME}}
title: Update ${{ env.VERSION_VAR }} version to ${{ env.NETWORK_VERSION }}
body: |
This PR updates the ${{ env.VERSION_VAR }} version to ${{ env.NETWORK_VERSION }}.
🤖 This PR was autogenerated.
update-mainnet-version:
runs-on: ubuntu-latest
env:
RPC_URL: https://rpc.osmosis.zone/abci_info
VERSION_VAR: MAINNET_VERSION
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check current version from RPC
run: |
RESPONSE=$(curl -s --retry 5 --retry-delay 5 --connect-timeout 30 -H "Accept: application/json" ${{ env.RPC_URL }})
NETWORK_VERSION=$(echo $RESPONSE | jq -r '.result.response.version')
echo "NETWORK_VERSION=$NETWORK_VERSION" >> $GITHUB_ENV
- name: Get current version from file
run: |
FILE_VERSION=$(grep '${{ env.VERSION_VAR }}' i.py | cut -d'"' -f2 | head -n 1)
echo "FILE_VERSION=$FILE_VERSION" >> $GITHUB_ENV
- name: Validate version format
run: |
if [[ ! ${{ env.NETWORK_VERSION }} =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$ ]]; then
echo "Version ${{ env.NETWORK_VERSION }} does not match the format X.Y.Z or X.Y.Z-rcN"
exit 1
fi
- name: Compare versions
id: compare_versions
run: |
compare_versions() {
local v1=$1
local v2=$2
if [[ $v1 == $v2 ]]; then
echo "COMPARE_RESULT=0" >> $GITHUB_ENV
return
fi
local IFS=.
local i
local version1=($v1)
local version2=($v2)
for ((i=0; i<${#version1[@]}; i++)); do
if [[ ${version1[i]} -gt ${version2[i]} ]]; then
echo "COMPARE_RESULT=1" >> $GITHUB_ENV
return
fi
if [[ ${version1[i]} -lt ${version2[i]} ]]; then
echo "COMPARE_RESULT=2" >> $GITHUB_ENV
return
fi
done
echo "COMPARE_RESULT=0" >> $GITHUB_ENV
}
compare_versions ${{ env.NETWORK_VERSION }} ${{ env.FILE_VERSION }}
- name: Generate branch name
if: env.COMPARE_RESULT == 1
run: |
RANDOM_ID=$(openssl rand -hex 6)
BRANCH_NAME="UPDATE-${{ env.VERSION_VAR }}-TO-${{ env.NETWORK_VERSION }}-$RANDOM_ID"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Update version if different
if: env.COMPARE_RESULT == 1
run: |
sed -i "s/${{ env.VERSION_VAR }} = \".*\"/${{ env.VERSION_VAR }} = \"${{ env.NETWORK_VERSION }}\"/" i.py
- name: Create Pull Request
if: env.COMPARE_RESULT == 1
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update ${{ env.VERSION_VAR }} version to ${{ env.NETWORK_VERSION }}
base: main
branch: ${{env.BRANCH_NAME}}
title: Update ${{ env.VERSION_VAR }} version to ${{ env.NETWORK_VERSION }}
body: |
This PR updates the ${{ env.VERSION_VAR }} version to ${{ env.NETWORK_VERSION }}.
🤖 This PR was autogenerated.