This repository was archived by the owner on Jul 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 474
230 lines (204 loc) · 7.68 KB
/
Copy pathe2e-subtensor-tests.yaml
File metadata and controls
230 lines (204 loc) · 7.68 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: E2E Subtensor Tests
concurrency:
group: e2e-subtensor-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
pull-requests: read
contents: read
on:
pull_request:
branches:
- '**'
types: [ opened, synchronize, reopened, ready_for_review, labeled, unlabeled ]
workflow_dispatch:
inputs:
docker_image_tag:
description: "Standard docker image tag (ignored if custom tag is set below)"
required: false
type: choice
default: "devnet-ready"
options:
- main
- testnet
- devnet
- devnet-ready
custom_image_tag:
description: "Custom docker image tag — overrides selection above (e.g. pr-2441)"
required: false
type: string
default: ""
# job to run tests in parallel
jobs:
# Looking for e2e tests
find-tests:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
outputs:
test-files: ${{ steps.get-tests.outputs.test-files }}
steps:
- name: Check-out repository under $GITHUB_WORKSPACE
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Install uv
uses: astral-sh/setup-uv@v8.0.0
with:
enable-cache: false
cache-dependency-glob: '**/pyproject.toml'
ignore-nothing-to-cache: true
- name: Cache uv and venv
uses: actions/cache@v5
with:
path: |
~/.cache/uv
.venv
key: uv-${{ runner.os }}-py3.10-${{ hashFiles('pyproject.toml') }}
restore-keys: uv-${{ runner.os }}-py3.10-
- name: Install dependencies (faster if cache hit)
run: uv sync --extra dev --dev
- name: Find test files
id: get-tests
shell: bash
run: |
set -euo pipefail
test_matrix=$(
uv run pytest -q --collect-only tests/e2e_tests \
| sed -n '/^e2e_tests\//p' \
| sed 's|^|tests/|' \
| jq -R -s -c '
split("\n")
| map(select(. != ""))
| map({nodeid: ., label: (sub("^tests/e2e_tests/"; ""))})
'
)
echo "Found tests: $test_matrix"
echo "test-files=$test_matrix" >> "$GITHUB_OUTPUT"
# Read Python versions
read-python-versions:
runs-on: ubuntu-latest
outputs:
python-versions: ${{ steps.read-versions.outputs.versions }}
steps:
- uses: actions/checkout@v6
- id: read-versions
run: |
versions=$(cat .github/supported-python-versions.json)
echo "versions=$versions" >> $GITHUB_OUTPUT
# Pull docker image
pull-docker-image:
runs-on: ubuntu-latest
outputs:
image-name: ${{ steps.set-image.outputs.image }}
steps:
- name: Install GitHub CLI
if: github.event_name == 'pull_request'
run: |
sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get update
sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get install -y --no-install-recommends -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" gh jq
- name: Set Docker image tag based on label or branch
id: set-image
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INPUT_CUSTOM_TAG: ${{ github.event.inputs.custom_image_tag }}
INPUT_CHOICE_TAG: ${{ github.event.inputs.docker_image_tag }}
run: |
echo "Event: $GITHUB_EVENT_NAME"
echo "Branch: $GITHUB_REF_NAME"
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
custom_tag=$(echo "$INPUT_CUSTOM_TAG" | xargs)
if [[ -n "$custom_tag" ]]; then
image="ghcr.io/opentensor/subtensor-localnet:${custom_tag}"
echo "Using custom docker image tag: ${custom_tag}"
echo "✅ Final selected image: $image"
echo "image=$image" >> "$GITHUB_OUTPUT"
exit 0
fi
if [[ -n "$INPUT_CHOICE_TAG" ]]; then
image="ghcr.io/opentensor/subtensor-localnet:${INPUT_CHOICE_TAG}"
echo "Using standard docker image tag: ${INPUT_CHOICE_TAG}"
echo "✅ Final selected image: $image"
echo "image=$image" >> "$GITHUB_OUTPUT"
exit 0
fi
fi
echo "Reading labels ..."
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
# Use GitHub CLI to read labels (works for forks too)
labels=$(gh pr view ${{ github.event.pull_request.number }} -R ${{ github.repository }} --json labels --jq '.labels[].name' || echo "")
echo "Found labels: $labels"
else
labels=""
fi
image=""
for label in $labels; do
echo "Found label: $label"
case "$label" in
"subtensor-localnet:main")
image="ghcr.io/opentensor/subtensor-localnet:main"
break
;;
"subtensor-localnet:testnet")
image="ghcr.io/opentensor/subtensor-localnet:testnet"
break
;;
"subtensor-localnet:devnet")
image="ghcr.io/opentensor/subtensor-localnet:devnet"
break
;;
esac
done
if [[ -z "$image" ]]; then
# fallback to default based on branch
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
# For PR, use base branch (target branch)
base_branch="${{ github.event.pull_request.base.ref }}"
if [[ "$base_branch" == "master" ]]; then
image="ghcr.io/opentensor/subtensor-localnet:main"
else
image="ghcr.io/opentensor/subtensor-localnet:devnet-ready"
fi
else
# For workflow_dispatch, use current branch
if [[ "${GITHUB_REF_NAME}" == "master" ]]; then
image="ghcr.io/opentensor/subtensor-localnet:main"
else
image="ghcr.io/opentensor/subtensor-localnet:devnet-ready"
fi
fi
fi
echo "✅ Final selected image: $image"
echo "image=$image" >> "$GITHUB_OUTPUT"
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
- name: Pull Docker Image
run: docker pull ${{ steps.set-image.outputs.image }}
- name: Save Docker Image to Cache
run: docker save -o subtensor-localnet.tar ${{ steps.set-image.outputs.image }}
- name: Upload Docker Image as Artifact
uses: actions/upload-artifact@v7
with:
name: subtensor-localnet
path: subtensor-localnet.tar
compression-level: 0
# Job to run tests in parallel
# Since GH Actions matrix has a limit of 256 jobs, we need to split the tests into multiple jobs with different
# Python versions. To reduce DRY we use reusable workflow.
e2e-test:
name: ${{ matrix.label }}
needs:
- find-tests
- pull-docker-image
- read-python-versions
strategy:
fail-fast: false
max-parallel: 64
matrix:
include: ${{ fromJson(needs.find-tests.outputs.test-files) }}
uses: ./.github/workflows/_run-e2e-single.yaml
with:
nodeid: ${{ matrix.nodeid }}
image-name: ${{ needs.pull-docker-image.outputs.image-name }}
python-versions: ${{ needs.read-python-versions.outputs.python-versions }}
secrets: inherit