This repository was archived by the owner on Jul 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
210 lines (185 loc) · 7.33 KB
/
Copy pathe2e-subtensor-tests.yml
File metadata and controls
210 lines (185 loc) · 7.33 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
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:
push:
branches: [ main, development, staging ]
pull_request:
branches: [ main, development, staging ]
types: [ opened, synchronize, reopened, ready_for_review, labeled, unlabeled ]
workflow_dispatch:
inputs:
docker_image_tag:
description: "Docker image tag"
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: ""
env:
CARGO_TERM_COLOR: always
jobs:
gate:
runs-on: ubuntu-latest
timeout-minutes: 5
if: ${{ github.event_name != 'pull_request' || (github.event.pull_request.draft == false && (github.head_ref == '' || !startsWith(github.head_ref, 'changelog/'))) }}
steps:
- run: 'true'
find-tests:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: gate
outputs:
test-files: ${{ steps.get-tests.outputs.test-files }}
steps:
- name: Check-out repository under $GITHUB_WORKSPACE
uses: actions/checkout@v6
- name: Find test files
id: get-tests
run: |
test_files=$(find tests/e2e_tests -name "test*.py" | jq -R -s -c 'split("\n") | map(select(. != ""))')
echo "test-files=$test_files" >> "$GITHUB_OUTPUT"
resolve-image:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: gate
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
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
echo "Reading PR description for image tag override ..."
pr_body=$(gh pr view ${{ github.event.pull_request.number }} -R ${{ github.repository }} --json body --jq '.body' || echo "")
# Look for a line like: E2E_IMAGE_TAG=pr-2638
desc_tag=$(printf '%s\n' "$pr_body" | grep -oE 'E2E_IMAGE_TAG=[A-Za-z0-9._-]+' | head -n1 | cut -d= -f2)
if [[ -n "$desc_tag" ]]; then
image="ghcr.io/opentensor/subtensor-localnet:${desc_tag}"
echo "Using image tag from PR description: ${desc_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=""
while IFS= read -r label; do
[[ -z "$label" ]] && continue
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 <<< "$labels"
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" == "main" ]]; then
image="ghcr.io/opentensor/subtensor-localnet:main"
else
image="ghcr.io/opentensor/subtensor-localnet:devnet-ready"
fi
else
# For workflow_dispatch or push, use current branch
if [[ "${GITHUB_REF_NAME}" == "main" ]]; 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"
run-e2e-tests:
name: ${{ matrix.test-file }} / Python ${{ matrix.python-version }}
needs:
- find-tests
- resolve-image
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
fail-fast: false # Allow other matrix jobs to run even if this job fails
max-parallel: 64 # Cap concurrent matrix legs (each runs on its own GitHub-hosted runner)
matrix:
os:
- ubuntu-latest
test-file: ${{ fromJson(needs.find-tests.outputs.test-files) }}
python-version: [ "3.10", "3.11", "3.12", "3.13", "3.14" ]
steps:
- name: Check-out repository
uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v8.0.0
with:
python-version: ${{ matrix.python-version }}
enable-cache: true
- 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 ${{ needs.resolve-image.outputs.image-name }}
- name: Run tests
env:
LOCALNET_IMAGE_NAME: ${{ needs.resolve-image.outputs.image-name }}
SKIP_PULL: "1"
run: |
uv run pytest ${{ matrix.test-file }} -s