Skip to content

Commit 39d5bf6

Browse files
authored
Add workflows for e2e sdk and btcli repos (#17)
* add workflows for e2e sdk and btcli repos * update
1 parent fa9f5fe commit 39d5bf6

File tree

2 files changed

+556
-0
lines changed

2 files changed

+556
-0
lines changed
Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
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 Rust stable
151+
uses: actions-rs/[email protected]
152+
with:
153+
toolchain: ${{ matrix.rust-branch }}
154+
components: rustfmt
155+
profile: minimal
156+
157+
- name: Install rust/cargo dependencies
158+
run: |
159+
sudo apt-get update &&
160+
sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler jq
161+
162+
- name: Add wasm32-unknown-unknown target
163+
run: |
164+
rustup target add wasm32-unknown-unknown --toolchain stable-x86_64-unknown-linux-gnu
165+
rustup component add rust-src --toolchain stable-x86_64-unknown-linux-gnu
166+
167+
- name: Install uv
168+
uses: astral-sh/setup-uv@v5
169+
170+
- name: Create Python virtual environment
171+
working-directory: ${{ github.workspace }}
172+
run: uv venv ${{ github.workspace }}/venv
173+
174+
- name: Clone Bittensor CLI repo
175+
working-directory: ${{ github.workspace }}
176+
run: git clone https://github.com/opentensor/btcli.git
177+
178+
- name: Setup Bittensor-cli from cloned repo
179+
working-directory: ${{ github.workspace }}/btcli
180+
run: |
181+
source ${{ github.workspace }}/venv/bin/activate
182+
git checkout staging
183+
git fetch origin staging
184+
uv run --active pip install --upgrade pip
185+
uv run --active pip install pytest
186+
uv run --active pip install maturin
187+
188+
- name: Install uv dependencies
189+
working-directory: ${{ github.workspace }}
190+
run: uv sync --all-extras --dev
191+
192+
- name: Clone bt-decode repo
193+
run: git clone https://github.com/opentensor/bt-decode.git
194+
195+
- name: Checkout PR branch in bt-decode repo
196+
working-directory: ${{ github.workspace }}/bt-decode
197+
run: |
198+
git fetch origin ${{ github.event.pull_request.head.ref }}
199+
git checkout ${{ github.event.pull_request.head.ref }}
200+
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
201+
202+
- name: Build and install bt-decode package
203+
working-directory: ${{ github.workspace }}
204+
run: |
205+
source ${{ github.workspace }}/venv/bin/activate
206+
uv run --active maturin develop
207+
208+
- name: Download Cached Docker Image
209+
uses: actions/download-artifact@v4
210+
with:
211+
name: subtensor-localnet
212+
213+
- name: Load Docker Image
214+
run: docker load -i subtensor-localnet.tar
215+
216+
- name: Run tests
217+
working-directory: ${{ github.workspace }}
218+
run: |
219+
source ${{ github.workspace }}/venv/bin/activate
220+
pytest ${{ matrix.test-file }} -s
221+
222+
223+
run-unit-test:
224+
needs:
225+
- check-labels
226+
if: always() && needs.check-labels.outputs.run-cli-tests == 'true'
227+
runs-on: ubuntu-latest
228+
steps:
229+
- name: Check-out repository
230+
uses: actions/checkout@v4
231+
232+
- name: Install dependencies
233+
run: |
234+
sudo apt-get update &&
235+
sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler
236+
237+
- name: Create Python virtual environment
238+
working-directory: ${{ github.workspace }}
239+
run: python3 -m venv venv
240+
241+
- name: Clone Bittensor CLI repo
242+
working-directory: ${{ github.workspace }}
243+
run: git clone https://github.com/opentensor/btcli.git
244+
245+
- name: Setup Bittensor SDK from cloned repo
246+
working-directory: ${{ github.workspace }}/btcli
247+
run: |
248+
source ${{ github.workspace }}/venv/bin/activate
249+
git checkout staging
250+
git fetch origin staging
251+
python3 -m pip install --upgrade pip
252+
python3 -m pip install '.[dev]'
253+
python3 -m pip install maturin
254+
255+
- name: Clone bt-decode repo
256+
run: git clone https://github.com/opentensor/bt-decode.git
257+
258+
- name: Checkout PR branch in bt-decode repo
259+
working-directory: ${{ github.workspace }}/bt-decode
260+
run: |
261+
git fetch origin ${{ github.event.pull_request.head.ref }}
262+
git checkout ${{ github.event.pull_request.head.ref }}
263+
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
264+
265+
- name: Build and install bt-decode package
266+
working-directory: ${{ github.workspace }}
267+
run: |
268+
source ${{ github.workspace }}/venv/bin/activate
269+
maturin develop
270+
271+
- name: Run SDK unit tests
272+
working-directory: ${{ github.workspace }}
273+
run: |
274+
source ${{ github.workspace }}/venv/bin/activate
275+
pytest ${{ github.workspace }}/btcli/tests/unit_tests

0 commit comments

Comments
 (0)