1
+ name : Bittensor BTCLI Test
2
+
3
+ permissions :
4
+ pull-requests : write
5
+ contents : read
6
+
7
+ concurrency :
8
+ group : e2e-cli-${{ github.ref }}
9
+ cancel-in-progress : true
10
+
11
+ on :
12
+ pull_request :
13
+ branches :
14
+ - main
15
+ - staging
16
+ types : [opened, synchronize, reopened, labeled, unlabeled]
17
+
18
+ env :
19
+ CARGO_TERM_COLOR : always
20
+ VERBOSE : ${{ github.event.inputs.verbose }}
21
+
22
+ jobs :
23
+ apply-label-to-new-pr :
24
+ runs-on : ubuntu-latest
25
+ if : ${{ github.event.pull_request.draft == false }}
26
+ outputs :
27
+ should_continue_cli : ${{ steps.check.outputs.should_continue_cli }}
28
+ steps :
29
+ - name : Check
30
+ id : check
31
+ run : |
32
+ ACTION="${{ github.event.action }}"
33
+ if [[ "$ACTION" == "opened" || "$ACTION" == "reopened" ]]; then
34
+ echo "should_continue_cli=true" >> $GITHUB_OUTPUT
35
+ else
36
+ echo "should_continue_cli=false" >> $GITHUB_OUTPUT
37
+ fi
38
+ shell : bash
39
+
40
+ - name : Add label
41
+ if : steps.check.outputs.should_continue_cli == 'true'
42
+ uses : actions-ecosystem/action-add-labels@v1
43
+ with :
44
+ github_token : ${{ secrets.GITHUB_TOKEN }}
45
+ labels : run-bittensor-cli-tests
46
+
47
+ check-labels :
48
+ needs : apply-label-to-new-pr
49
+ runs-on : ubuntu-latest
50
+ if : always()
51
+ outputs :
52
+ run-cli-tests : ${{ steps.get-labels.outputs.run-cli-tests }}
53
+ steps :
54
+ - name : Check out repository
55
+ uses : actions/checkout@v4
56
+
57
+ - name : Get labels from PR
58
+ id : get-labels
59
+ run : |
60
+ LABELS=$(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name')
61
+ echo "Current labels: $LABELS"
62
+ if echo "$LABELS" | grep -q "run-bittensor-cli-tests"; then
63
+ echo "run-cli-tests=true" >> $GITHUB_ENV
64
+ echo "::set-output name=run-cli-tests::true"
65
+ else
66
+ echo "run-cli-tests=false" >> $GITHUB_ENV
67
+ echo "::set-output name=run-cli-tests::false"
68
+ fi
69
+ env :
70
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
71
+
72
+ find-e2e-tests :
73
+ needs : check-labels
74
+ if : always() && needs.check-labels.outputs.run-cli-tests == 'true'
75
+ runs-on : ubuntu-latest
76
+ outputs :
77
+ test-files : ${{ steps.get-tests.outputs.test-files }}
78
+ steps :
79
+ - name : Research preparation
80
+ working-directory : ${{ github.workspace }}
81
+ run : git clone https://github.com/opentensor/btcli.git
82
+
83
+ - name : Checkout
84
+ working-directory : ${{ github.workspace }}/btcli
85
+ run : git checkout staging
86
+
87
+ - name : Install dependencies
88
+ run : sudo apt-get install -y jq
89
+
90
+ - name : Find e2e test files
91
+ id : get-tests
92
+ run : |
93
+ test_files=$(find ${{ github.workspace }}/btcli/tests/e2e_tests -name "test*.py" | jq -R -s -c 'split("\n") | map(select(. != ""))')
94
+ echo "::set-output name=test-files::$test_files"
95
+ shell : bash
96
+
97
+ pull-docker-image :
98
+ needs : check-labels
99
+ runs-on : ubuntu-latest
100
+ if : always() && needs.check-labels.outputs.run-cli-tests == 'true'
101
+ steps :
102
+ - name : Log in to GitHub Container Registry
103
+ run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
104
+
105
+ - name : Pull Docker Image
106
+ run : docker pull ghcr.io/opentensor/subtensor-localnet:latest
107
+
108
+ - name : Save Docker Image to Cache
109
+ run : docker save -o subtensor-localnet.tar ghcr.io/opentensor/subtensor-localnet:latest
110
+
111
+ - name : Upload Docker Image as Artifact
112
+ uses : actions/upload-artifact@v4
113
+ with :
114
+ name : subtensor-localnet
115
+ path : subtensor-localnet.tar
116
+
117
+ run-e2e-tests :
118
+ needs :
119
+ - check-labels
120
+ - find-e2e-tests
121
+ - pull-docker-image
122
+
123
+ if : always() && needs.check-labels.outputs.run-cli-tests == 'true'
124
+ runs-on : ubuntu-latest
125
+ strategy :
126
+ fail-fast : false
127
+ max-parallel : 16
128
+ matrix :
129
+ rust-branch :
130
+ - stable
131
+ rust-target :
132
+ - x86_64-unknown-linux-gnu
133
+ os :
134
+ - ubuntu-latest
135
+ test-file : ${{ fromJson(needs.find-e2e-tests.outputs.test-files) }}
136
+
137
+ env :
138
+ RELEASE_NAME : development
139
+ RUSTV : ${{ matrix.rust-branch }}
140
+ RUST_BACKTRACE : full
141
+ RUST_BIN_DIR : target/${{ matrix.rust-target }}
142
+ TARGET : ${{ matrix.rust-target }}
143
+
144
+ timeout-minutes : 60
145
+ name : " e2e tests: ${{ matrix.test-file }}"
146
+ steps :
147
+ - name : Check-out repository
148
+ uses : actions/checkout@v4
149
+
150
+ - name : Install dependencies
151
+ run : |
152
+ sudo apt-get update &&
153
+ sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler
154
+
155
+ - name : Install uv
156
+ uses : astral-sh/setup-uv@v5
157
+
158
+ - name : Create Python virtual environment
159
+ working-directory : ${{ github.workspace }}
160
+ run : uv venv ${{ github.workspace }}/venv
161
+
162
+ - name : Clone Bittensor CLI repo
163
+ working-directory : ${{ github.workspace }}
164
+ run : git clone https://github.com/opentensor/btcli.git
165
+
166
+ - name : Setup Bittensor-cli from cloned repo
167
+ working-directory : ${{ github.workspace }}/btcli
168
+ run : |
169
+ source ${{ github.workspace }}/venv/bin/activate
170
+ git checkout staging
171
+ git fetch origin staging
172
+ uv run --active pip install --upgrade pip
173
+ uv run --active pip install pytest
174
+
175
+ - name : Install uv dependencies
176
+ working-directory : ${{ github.workspace }}
177
+ run : uv sync --all-extras --dev
178
+
179
+ - name : Clone async-substrate-interface repo
180
+ run : git clone https://github.com/opentensor/async-substrate-interface.git
181
+
182
+ - name : Checkout PR async-substrate-interface repo
183
+ working-directory : ${{ github.workspace }}/async-substrate-interface
184
+ run : |
185
+ git fetch origin ${{ github.event.pull_request.head.ref }}
186
+ git checkout ${{ github.event.pull_request.head.ref }}
187
+ echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
188
+
189
+ - name : Install async-substrate-interface package
190
+ working-directory : ${{ github.workspace }}
191
+ run : |
192
+ source ${{ github.workspace }}/venv/bin/activate
193
+ uv run --active pip uninstall async-substrate-interface -y
194
+ uv run --active pip install .
195
+
196
+ - name : Download Cached Docker Image
197
+ uses : actions/download-artifact@v4
198
+ with :
199
+ name : subtensor-localnet
200
+
201
+ - name : Load Docker Image
202
+ run : docker load -i subtensor-localnet.tar
203
+
204
+ - name : Run tests
205
+ working-directory : ${{ github.workspace }}
206
+ run : |
207
+ source ${{ github.workspace }}/venv/bin/activate
208
+ pytest ${{ matrix.test-file }} -s
209
+
210
+
211
+ run-unit-test :
212
+ needs :
213
+ - check-labels
214
+ if : always() && needs.check-labels.outputs.run-cli-tests == 'true'
215
+ runs-on : ubuntu-latest
216
+ steps :
217
+ - name : Check-out repository
218
+ uses : actions/checkout@v4
219
+
220
+ - name : Install dependencies
221
+ run : |
222
+ sudo apt-get update &&
223
+ sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler
224
+
225
+ - name : Create Python virtual environment
226
+ working-directory : ${{ github.workspace }}
227
+ run : python3 -m venv venv
228
+
229
+ - name : Clone Bittensor CLI repo
230
+ working-directory : ${{ github.workspace }}
231
+ run : git clone https://github.com/opentensor/btcli.git
232
+
233
+ - name : Setup Bittensor SDK from cloned repo
234
+ working-directory : ${{ github.workspace }}/btcli
235
+ run : |
236
+ source ${{ github.workspace }}/venv/bin/activate
237
+ git checkout staging
238
+ git fetch origin staging
239
+ python3 -m pip install --upgrade pip
240
+ python3 -m pip install '.[dev]'
241
+
242
+ - name : Clone async-substrate-interface repo
243
+ run : git clone https://github.com/opentensor/async-substrate-interface.git
244
+
245
+ - name : Checkout PR branch in async-substrate-interface repo
246
+ working-directory : ${{ github.workspace }}/async-substrate-interface
247
+ run : |
248
+ git fetch origin ${{ github.event.pull_request.head.ref }}
249
+ git checkout ${{ github.event.pull_request.head.ref }}
250
+ echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
251
+
252
+ - name : Check-out repository
253
+ uses : actions/checkout@v4
254
+
255
+ - name : Install async-substrate-interface package
256
+ working-directory : ${{ github.workspace }}
257
+ run : |
258
+ source ${{ github.workspace }}/venv/bin/activate
259
+ pip uninstall async-substrate-interface -y
260
+ pip install .
261
+
262
+ - name : Run SDK unit tests
263
+ working-directory : ${{ github.workspace }}
264
+ run : |
265
+ source ${{ github.workspace }}/venv/bin/activate
266
+ pytest ${{ github.workspace }}/btcli/tests/unit_tests
0 commit comments