@@ -4,6 +4,10 @@ concurrency:
44 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+
711on :
812 pull_request :
913 branches :
1216
1317 workflow_dispatch :
1418 inputs :
15- verbose :
16- description : " Output more information when triggered manually "
19+ docker_image_tag :
20+ description : " Docker image tag "
1721 required : false
18- default : " "
22+ type : choice
23+ default : " devnet-ready"
24+ options :
25+ - main
26+ - testnet
27+ - devnet
28+ - devnet-ready
1929
2030env :
2131 CARGO_TERM_COLOR : always
22- VERBOSE : ${{ github.event.inputs.verbose }}
2332
2433# job to run tests in parallel
2534jobs :
2635 # Looking for e2e tests
2736 find-tests :
2837 runs-on : ubuntu-latest
29- if : ${{ github.event.pull_request.draft == false }}
38+ if : ${{ github.event_name != 'pull_request' || github. event.pull_request.draft == false }}
3039 outputs :
3140 test-files : ${{ steps.get-tests.outputs.test-files }}
3241 steps :
@@ -64,26 +73,47 @@ jobs:
6473
6574 # Pull docker image
6675 pull-docker-image :
67- needs : find-tests
6876 runs-on : ubuntu-latest
6977 outputs :
7078 image-name : ${{ steps.set-image.outputs.image }}
7179 steps :
80+ - name : Install GitHub CLI
81+ if : github.event_name == 'pull_request'
82+ run : |
83+ sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get update
84+ 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
85+
7286 - name : Set Docker image tag based on label or branch
7387 id : set-image
88+ env :
89+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
7490 run : |
7591 echo "Event: $GITHUB_EVENT_NAME"
7692 echo "Branch: $GITHUB_REF_NAME"
77-
93+
94+ # Check if docker_image_tag input is provided (for workflow_dispatch)
95+ if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
96+ docker_tag_input="${{ github.event.inputs.docker_image_tag }}"
97+ if [[ -n "$docker_tag_input" ]]; then
98+ image="ghcr.io/opentensor/subtensor-localnet:${docker_tag_input}"
99+ echo "Using Docker image tag from workflow_dispatch input: ${docker_tag_input}"
100+ echo "✅ Final selected image: $image"
101+ echo "image=$image" >> "$GITHUB_OUTPUT"
102+ exit 0
103+ fi
104+ fi
105+
78106 echo "Reading labels ..."
79107 if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
80- labels=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH")
108+ # Use GitHub CLI to read labels (works for forks too)
109+ labels=$(gh pr view ${{ github.event.pull_request.number }} -R ${{ github.repository }} --json labels --jq '.labels[].name' || echo "")
110+ echo "Found labels: $labels"
81111 else
82112 labels=""
83113 fi
84-
114+
85115 image=""
86-
116+
87117 for label in $labels; do
88118 echo "Found label: $label"
89119 case "$label" in
@@ -101,16 +131,27 @@ jobs:
101131 ;;
102132 esac
103133 done
104-
134+
105135 if [[ -z "$image" ]]; then
106136 # fallback to default based on branch
107- if [[ "${GITHUB_REF_NAME}" == "master" ]]; then
108- image="ghcr.io/opentensor/subtensor-localnet:main"
137+ if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
138+ # For PR, use base branch (target branch)
139+ base_branch="${{ github.event.pull_request.base.ref }}"
140+ if [[ "$base_branch" == "master" ]]; then
141+ image="ghcr.io/opentensor/subtensor-localnet:main"
142+ else
143+ image="ghcr.io/opentensor/subtensor-localnet:devnet-ready"
144+ fi
109145 else
110- image="ghcr.io/opentensor/subtensor-localnet:devnet-ready"
146+ # For workflow_dispatch, use current branch
147+ if [[ "${GITHUB_REF_NAME}" == "master" ]]; then
148+ image="ghcr.io/opentensor/subtensor-localnet:main"
149+ else
150+ image="ghcr.io/opentensor/subtensor-localnet:devnet-ready"
151+ fi
111152 fi
112153 fi
113-
154+
114155 echo "✅ Final selected image: $image"
115156 echo "image=$image" >> "$GITHUB_OUTPUT"
116157
0 commit comments