Skip to content

Commit ee967f6

Browse files
authored
Merge pull request #2288 from opentensor/feat/roman/improve-bt-e2e-test-workflow
Reduce Subtensor compilation time and run E2E tests a few times faster
2 parents 39c725c + 4db9f16 commit ee967f6

File tree

1 file changed

+183
-55
lines changed

1 file changed

+183
-55
lines changed

.github/workflows/check-bittensor-e2e-tests.yml.yml renamed to .github/workflows/check-bittensor-e2e-tests.yml

Lines changed: 183 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
check-label:
2929
runs-on: ubuntu-latest
3030
outputs:
31-
skip-bittensor-e2e-tests: ${{ steps.get-labels.outputs.skip-bittensor-e2e-tests }}
31+
skip-bittensor-e2e-tests: ${{ steps.get-labels.outputs.skip-bittensor-e2e-tests || steps.set-default.outputs.skip-bittensor-e2e-tests }}
3232
steps:
3333
- name: Install dependencies
3434
run: |
@@ -38,11 +38,12 @@ jobs:
3838
- name: Check out repository
3939
uses: actions/checkout@v4
4040
with:
41-
repository: ${{ github.event.pull_request.head.repo.full_name }}
42-
ref: ${{ github.event.pull_request.head.ref }}
41+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
42+
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
4343

4444
- name: Get labels from PR
4545
id: get-labels
46+
if: github.event_name == 'pull_request'
4647
run: |
4748
LABELS=$(gh pr -R ${{ github.repository }} view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name')
4849
echo "Current labels: $LABELS"
@@ -54,6 +55,12 @@ jobs:
5455
env:
5556
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5657

58+
- name: Set default skip value for workflow_dispatch
59+
id: set-default
60+
if: github.event_name == 'workflow_dispatch'
61+
run: |
62+
echo "skip-bittensor-e2e-tests=false" >> $GITHUB_OUTPUT
63+
5764
find-btcli-e2e-tests:
5865
needs: check-label
5966
if: needs.check-label.outputs.skip-bittensor-e2e-tests == 'false'
@@ -74,11 +81,44 @@ jobs:
7481
working-directory: ${{ github.workspace }}/btcli
7582
run: git checkout staging
7683

84+
- name: Set up Python
85+
uses: actions/setup-python@v5
86+
with:
87+
python-version: '3.10'
88+
89+
- name: Install uv
90+
uses: astral-sh/setup-uv@v5
91+
with:
92+
enable-cache: "false"
93+
94+
- name: Create Python virtual environment
95+
working-directory: ${{ github.workspace }}/btcli
96+
run: uv venv --seed
97+
98+
- name: Install dependencies
99+
working-directory: ${{ github.workspace }}/btcli
100+
run: |
101+
source .venv/bin/activate
102+
uv run --active pip install --upgrade pip
103+
uv run --active pip install '.[dev]'
104+
uv run --active pip install pytest
105+
77106
- name: Find e2e test files
78107
id: get-btcli-tests
108+
working-directory: ${{ github.workspace }}/btcli
79109
run: |
80-
test_files=$(find ${{ github.workspace }}/btcli/tests/e2e_tests -name "test*.py" | jq -R -s -c 'split("\n") | map(select(. != ""))')
81-
echo "test-files=$test_files" >> $GITHUB_OUTPUT
110+
set -euo pipefail
111+
test_matrix=$(
112+
uv run pytest -q --collect-only tests/e2e_tests \
113+
| sed -n '/^tests\//p' \
114+
| jq -R -s -c '
115+
split("\n")
116+
| map(select(. != ""))
117+
| map({nodeid: ., label: (sub("^tests/e2e_tests/"; ""))})
118+
'
119+
)
120+
echo "Found tests: $test_matrix"
121+
echo "test-files=$test_matrix" >> "$GITHUB_OUTPUT"
82122
shell: bash
83123

84124
find-sdk-e2e-tests:
@@ -101,34 +141,148 @@ jobs:
101141
working-directory: ${{ github.workspace }}/bittensor
102142
run: git checkout staging
103143

144+
- name: Set up Python
145+
uses: actions/setup-python@v5
146+
with:
147+
python-version: '3.10'
148+
149+
- name: Install uv
150+
uses: astral-sh/setup-uv@v5
151+
with:
152+
enable-cache: "false"
153+
154+
- name: Create Python virtual environment
155+
working-directory: ${{ github.workspace }}/bittensor
156+
run: uv venv --seed
157+
158+
- name: Install dependencies
159+
working-directory: ${{ github.workspace }}/bittensor
160+
run: |
161+
source .venv/bin/activate
162+
uv run --active pip install --upgrade pip
163+
uv run --active pip install '.[dev]'
164+
uv run --active pip install pytest
165+
104166
- name: Find e2e test files
105167
id: get-sdk-tests
168+
working-directory: ${{ github.workspace }}/bittensor
106169
run: |
107-
test_files=$(find ${{ github.workspace }}/bittensor/tests/e2e_tests -name "test*.py" | jq -R -s -c 'split("\n") | map(select(. != ""))')
108-
echo "test-files=$test_files" >> $GITHUB_OUTPUT
170+
set -euo pipefail
171+
test_matrix=$(
172+
uv run pytest -q --collect-only tests/e2e_tests \
173+
| sed -n '/^e2e_tests\//p' \
174+
| sed 's|^|tests/|' \
175+
| jq -R -s -c '
176+
split("\n")
177+
| map(select(. != ""))
178+
| map({nodeid: ., label: (sub("^tests/e2e_tests/"; ""))})
179+
'
180+
)
181+
echo "Found tests: $test_matrix"
182+
echo "test-files=$test_matrix" >> "$GITHUB_OUTPUT"
109183
shell: bash
110184

111-
build-image-with-current-branch:
185+
# build artifacts for fast-runtime and non-fast-runtime
186+
artifacts:
187+
name: Node • ${{ matrix.runtime }} • ${{ matrix.platform.arch }}
112188
needs: check-label
113189
if: needs.check-label.outputs.skip-bittensor-e2e-tests == 'false'
114-
runs-on: ubuntu-latest
190+
strategy:
191+
matrix:
192+
platform:
193+
- runner: [self-hosted, type-ccx33]
194+
triple: x86_64-unknown-linux-gnu
195+
arch: amd64
196+
runtime: ["fast-runtime", "non-fast-runtime"]
197+
198+
runs-on: ${{ matrix.platform.runner }}
199+
115200
steps:
116201
- name: Checkout code
117202
uses: actions/checkout@v4
118203
with:
119-
repository: ${{ github.event.pull_request.head.repo.full_name }}
120-
ref: ${{ github.event.pull_request.head.ref }}
204+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
205+
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
206+
207+
- name: Install Rust + dependencies
208+
run: |
209+
chmod +x ./scripts/install_build_env.sh
210+
./scripts/install_build_env.sh
121211
122-
- name: Patch non-fast-runtime node
212+
- name: Add Rust target triple
213+
run: |
214+
source "$HOME/.cargo/env"
215+
rustup target add ${{ matrix.platform.triple }}
216+
217+
- name: Patch limits for local run
123218
run: |
124219
chmod +x ./scripts/localnet_patch.sh
125220
./scripts/localnet_patch.sh
126221
127-
- name: Set up QEMU
128-
uses: docker/setup-qemu-action@v3
222+
- name: Build binaries
223+
run: |
224+
export PATH="$HOME/.cargo/bin:$PATH"
225+
export CARGO_BUILD_TARGET="${{ matrix.platform.triple }}"
226+
227+
if [ "${{ matrix.runtime }}" = "fast-runtime" ]; then
228+
./scripts/localnet.sh --build-only
229+
else
230+
./scripts/localnet.sh False --build-only
231+
fi
232+
233+
# use `ci_target` name bc .dockerignore excludes `target`
234+
- name: Prepare artifacts for upload
235+
run: |
236+
RUNTIME="${{ matrix.runtime }}"
237+
TRIPLE="${{ matrix.platform.triple }}"
238+
239+
# Verify binaries exist before copying
240+
BINARY_PATH="target/${RUNTIME}/${TRIPLE}/release/node-subtensor"
241+
WASM_PATH="target/${RUNTIME}/${TRIPLE}/release/wbuild/node-subtensor-runtime/node_subtensor_runtime.compact.compressed.wasm"
129242
130-
- name: Set up Docker Buildx
131-
uses: docker/setup-buildx-action@v3
243+
if [[ ! -f "$BINARY_PATH" ]]; then
244+
echo "❌ Error: Binary not found at $BINARY_PATH"
245+
exit 1
246+
fi
247+
248+
if [[ ! -f "$WASM_PATH" ]]; then
249+
echo "❌ Error: WASM file not found at $WASM_PATH"
250+
exit 1
251+
fi
252+
253+
mkdir -p build/ci_target/${RUNTIME}/${TRIPLE}/release/
254+
cp -v "$BINARY_PATH" \
255+
build/ci_target/${RUNTIME}/${TRIPLE}/release/
256+
257+
mkdir -p build/ci_target/${RUNTIME}/${TRIPLE}/release/wbuild/node-subtensor-runtime/
258+
cp -v "$WASM_PATH" \
259+
build/ci_target/${RUNTIME}/${TRIPLE}/release/wbuild/node-subtensor-runtime/
260+
261+
- name: Upload artifact
262+
uses: actions/upload-artifact@v4
263+
with:
264+
name: binaries-${{ matrix.platform.triple }}-${{ matrix.runtime }}
265+
path: build/
266+
if-no-files-found: error
267+
268+
# Collect all artifacts and build a Docker image
269+
build-image-with-current-branch:
270+
needs: [check-label, artifacts]
271+
if: needs.check-label.outputs.skip-bittensor-e2e-tests == 'false'
272+
runs-on: ubuntu-latest
273+
steps:
274+
- name: Checkout code
275+
uses: actions/checkout@v4
276+
with:
277+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
278+
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
279+
280+
- name: Download all binary artifacts
281+
uses: actions/download-artifact@v5
282+
with:
283+
pattern: binaries-*
284+
path: build/
285+
merge-multiple: true
132286

133287
- name: Move Docker data-root to /mnt/data
134288
run: |
@@ -141,7 +295,7 @@ jobs:
141295
docker info | grep "Docker Root Dir"
142296
143297
- name: Build Docker Image
144-
run: docker build -f Dockerfile-localnet -t localnet .
298+
run: docker build -f Dockerfile-localnet --build-arg BUILT_IN_CI="Boom shakalaka" -t localnet .
145299

146300
- name: Save Docker Image as Tar
147301
run: docker save -o /mnt/data/subtensor-localnet.tar localnet
@@ -162,31 +316,18 @@ jobs:
162316
runs-on: ubuntu-latest
163317
strategy:
164318
fail-fast: false
165-
max-parallel: 16
319+
max-parallel: 32
166320
matrix:
167-
rust-branch:
168-
- stable
169-
rust-target:
170-
- x86_64-unknown-linux-gnu
171-
os:
172-
- ubuntu-latest
173-
test-file: ${{ fromJson(needs.find-btcli-e2e-tests.outputs.test-files) }}
174-
175-
env:
176-
RELEASE_NAME: development
177-
RUSTV: ${{ matrix.rust-branch }}
178-
RUST_BACKTRACE: full
179-
RUST_BIN_DIR: target/${{ matrix.rust-target }}
180-
TARGET: ${{ matrix.rust-target }}
321+
include: ${{ fromJson(needs.find-btcli-e2e-tests.outputs.test-files) }}
181322

182323
timeout-minutes: 60
183-
name: "cli: ${{ matrix.test-file }}"
324+
name: "cli: ${{ matrix.label }}"
184325
steps:
185326
- name: Check-out repository
186327
uses: actions/checkout@v4
187328
with:
188-
repository: ${{ github.event.pull_request.head.repo.full_name }}
189-
ref: ${{ github.event.pull_request.head.ref }}
329+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
330+
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
190331

191332
- name: Install uv
192333
uses: astral-sh/setup-uv@v5
@@ -230,7 +371,7 @@ jobs:
230371
set +e
231372
for i in 1 2; do
232373
echo "🔁 Attempt $i: Running tests"
233-
uv run pytest ${{ matrix.test-file }} -s
374+
uv run pytest "${{ matrix.nodeid }}" -s
234375
status=$?
235376
if [ $status -eq 0 ]; then
236377
echo "✅ Tests passed on attempt $i"
@@ -256,31 +397,18 @@ jobs:
256397
runs-on: ubuntu-latest
257398
strategy:
258399
fail-fast: false
259-
max-parallel: 16
400+
max-parallel: 64
260401
matrix:
261-
rust-branch:
262-
- stable
263-
rust-target:
264-
- x86_64-unknown-linux-gnu
265-
os:
266-
- ubuntu-latest
267-
test-file: ${{ fromJson(needs.find-sdk-e2e-tests.outputs.test-files) }}
268-
269-
env:
270-
RELEASE_NAME: development
271-
RUSTV: ${{ matrix.rust-branch }}
272-
RUST_BACKTRACE: full
273-
RUST_BIN_DIR: target/${{ matrix.rust-target }}
274-
TARGET: ${{ matrix.rust-target }}
402+
include: ${{ fromJson(needs.find-sdk-e2e-tests.outputs.test-files) }}
275403

276404
timeout-minutes: 60
277-
name: "sdk: ${{ matrix.test-file }}"
405+
name: "sdk: ${{ matrix.label }}"
278406
steps:
279407
- name: Check-out repository
280408
uses: actions/checkout@v4
281409
with:
282-
repository: ${{ github.event.pull_request.head.repo.full_name }}
283-
ref: ${{ github.event.pull_request.head.ref }}
410+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
411+
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
284412

285413
- name: Install uv
286414
uses: astral-sh/setup-uv@v5
@@ -324,7 +452,7 @@ jobs:
324452
set +e
325453
for i in 1 2; do
326454
echo "🔁 Attempt $i: Running tests"
327-
uv run pytest ${{ matrix.test-file }} -s
455+
uv run pytest "${{ matrix.nodeid }}" -s
328456
status=$?
329457
if [ $status -eq 0 ]; then
330458
echo "✅ Tests passed on attempt $i"

0 commit comments

Comments
 (0)