Skip to content

Commit 83eb917

Browse files
authored
Merge pull request opentensor#728 from opentensor/feat/roman/e2e-workflow-with-selection
Improve e2e tests workflow
2 parents f48829d + 7bf73d6 commit 83eb917

File tree

2 files changed

+107
-12
lines changed

2 files changed

+107
-12
lines changed

.github/workflows/e2e-subtensor-tests.yml

Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
11
name: E2E Subtensor Tests
22

33
concurrency:
4-
group: e2e-subtensor-${{ github.ref }}
4+
group: e2e-subtensor-${{ github.event.pull_request.number || github.ref }}
55
cancel-in-progress: true
66

7+
permissions:
8+
pull-requests: read
9+
contents: read
10+
711
on:
812
push:
913
branches: [main, development, staging]
1014

1115
pull_request:
1216
branches: [main, development, staging]
13-
types: [ opened, synchronize, reopened, ready_for_review ]
17+
types: [ opened, synchronize, reopened, ready_for_review, labeled, unlabeled ]
1418

1519
workflow_dispatch:
1620
inputs:
17-
verbose:
18-
description: "Output more information when triggered manually"
21+
docker_image_tag:
22+
description: "Docker image tag"
1923
required: false
20-
default: ""
24+
type: choice
25+
default: "devnet-ready"
26+
options:
27+
- main
28+
- testnet
29+
- devnet
30+
- devnet-ready
2131

2232
env:
2333
CARGO_TERM_COLOR: always
24-
VERBOSE: ${{ github.event.inputs.verbose }}
2534

2635
jobs:
2736

2837
find-tests:
2938
runs-on: ubuntu-latest
30-
if: ${{ github.event_name != 'pull_request' || (github.event.pull_request.draft == false && !startsWith(github.head_ref, 'changelog/')) }}
39+
if: ${{ github.event_name != 'pull_request' || (github.event.pull_request.draft == false && (github.head_ref == '' || !startsWith(github.head_ref, 'changelog/'))) }}
3140
outputs:
3241
test-files: ${{ steps.get-tests.outputs.test-files }}
3342
steps:
@@ -38,21 +47,101 @@ jobs:
3847
id: get-tests
3948
run: |
4049
test_files=$(find tests/e2e_tests -name "test*.py" | jq -R -s -c 'split("\n") | map(select(. != ""))')
41-
echo "::set-output name=test-files::$test_files"
50+
echo "test-files=$test_files" >> "$GITHUB_OUTPUT"
4251
shell: bash
4352

4453
pull-docker-image:
4554
runs-on: ubuntu-latest
46-
if: ${{ github.event_name != 'pull_request' || (github.event.pull_request.draft == false && !startsWith(github.head_ref, 'changelog/')) }}
55+
if: ${{ github.event_name != 'pull_request' || (github.event.pull_request.draft == false && (github.head_ref == '' || !startsWith(github.head_ref, 'changelog/'))) }}
56+
outputs:
57+
image-name: ${{ steps.set-image.outputs.image }}
4758
steps:
59+
- name: Install GitHub CLI
60+
if: github.event_name == 'pull_request'
61+
run: |
62+
sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get update
63+
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
64+
65+
- name: Set Docker image tag based on label or branch
66+
id: set-image
67+
env:
68+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
run: |
70+
echo "Event: $GITHUB_EVENT_NAME"
71+
echo "Branch: $GITHUB_REF_NAME"
72+
73+
# Check if docker_image_tag input is provided (for workflow_dispatch)
74+
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
75+
docker_tag_input="${{ github.event.inputs.docker_image_tag }}"
76+
if [[ -n "$docker_tag_input" ]]; then
77+
image="ghcr.io/opentensor/subtensor-localnet:${docker_tag_input}"
78+
echo "Using Docker image tag from workflow_dispatch input: ${docker_tag_input}"
79+
echo "✅ Final selected image: $image"
80+
echo "image=$image" >> "$GITHUB_OUTPUT"
81+
exit 0
82+
fi
83+
fi
84+
85+
echo "Reading labels ..."
86+
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
87+
# Use GitHub CLI to read labels (works for forks too)
88+
labels=$(gh pr view ${{ github.event.pull_request.number }} -R ${{ github.repository }} --json labels --jq '.labels[].name' || echo "")
89+
echo "Found labels: $labels"
90+
else
91+
labels=""
92+
fi
93+
94+
image=""
95+
96+
for label in $labels; do
97+
echo "Found label: $label"
98+
case "$label" in
99+
"subtensor-localnet:main")
100+
image="ghcr.io/opentensor/subtensor-localnet:main"
101+
break
102+
;;
103+
"subtensor-localnet:testnet")
104+
image="ghcr.io/opentensor/subtensor-localnet:testnet"
105+
break
106+
;;
107+
"subtensor-localnet:devnet")
108+
image="ghcr.io/opentensor/subtensor-localnet:devnet"
109+
break
110+
;;
111+
esac
112+
done
113+
114+
if [[ -z "$image" ]]; then
115+
# fallback to default based on branch
116+
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
117+
# For PR, use base branch (target branch)
118+
base_branch="${{ github.event.pull_request.base.ref }}"
119+
if [[ "$base_branch" == "main" ]]; then
120+
image="ghcr.io/opentensor/subtensor-localnet:main"
121+
else
122+
image="ghcr.io/opentensor/subtensor-localnet:devnet-ready"
123+
fi
124+
else
125+
# For workflow_dispatch or push, use current branch
126+
if [[ "${GITHUB_REF_NAME}" == "main" ]]; then
127+
image="ghcr.io/opentensor/subtensor-localnet:main"
128+
else
129+
image="ghcr.io/opentensor/subtensor-localnet:devnet-ready"
130+
fi
131+
fi
132+
fi
133+
134+
echo "✅ Final selected image: $image"
135+
echo "image=$image" >> "$GITHUB_OUTPUT"
136+
48137
- name: Log in to GitHub Container Registry
49138
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
50139

51140
- name: Pull Docker Image
52-
run: docker pull ghcr.io/opentensor/subtensor-localnet:devnet-ready
141+
run: docker pull ${{ steps.set-image.outputs.image }}
53142

54143
- name: Save Docker Image to Cache
55-
run: docker save -o subtensor-localnet.tar ghcr.io/opentensor/subtensor-localnet:devnet-ready
144+
run: docker save -o subtensor-localnet.tar ${{ steps.set-image.outputs.image }}
56145

57146
- name: Upload Docker Image as Artifact
58147
uses: actions/upload-artifact@v4
@@ -93,5 +182,8 @@ jobs:
93182
run: docker load -i subtensor-localnet.tar
94183

95184
- name: Run tests
185+
env:
186+
LOCALNET_IMAGE_NAME: ${{ needs.pull-docker-image.outputs.image-name }}
187+
SKIP_PULL: "1"
96188
run: |
97189
uv run pytest ${{ matrix.test-file }} -s

tests/e2e_tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
from .utils import setup_wallet, ExecCommand
1919

20-
LOCALNET_IMAGE_NAME = "ghcr.io/opentensor/subtensor-localnet:devnet-ready"
20+
LOCALNET_IMAGE_NAME = (
21+
os.getenv("LOCALNET_IMAGE_NAME")
22+
or "ghcr.io/opentensor/subtensor-localnet:devnet-ready"
23+
)
2124

2225

2326
def wait_for_node_start(process, pattern, timestamp: int = None):

0 commit comments

Comments
 (0)