Skip to content

Commit 91fefc6

Browse files
committed
fix: trigger downstream experiment validation
1 parent 5fa32c3 commit 91fefc6

4 files changed

Lines changed: 66 additions & 1 deletion

.github/workflows/experiment_validation.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ name: Experiment Validation
1212
jobs:
1313
validate:
1414
if: contains(github.event.issue.labels.*.name, 'monthly-optimization-task') || inputs.issue_number != ''
15-
runs-on: ubuntu-latest
15+
runs-on:
16+
- self-hosted
17+
- Linux
18+
- X64
1619
permissions:
1720
contents: read
1821
issues: write

.github/workflows/monthly_optimization_planner.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,65 @@ jobs:
212212
print(f"issue_number={fanout.get('issue_number') or ''}", file=output)
213213
PY
214214
215+
- name: Trigger BinancePlatform experiment validation by label
216+
if: steps.downstream_experiment_target.outputs.should_dispatch == 'true'
217+
env:
218+
GITHUB_TOKEN: ${{ secrets.CROSS_REPO_GITHUB_TOKEN }}
219+
TARGET_REPO: ${{ inputs.downstream_repo }}
220+
ISSUE_NUMBER: ${{ steps.downstream_experiment_target.outputs.issue_number }}
221+
run: |
222+
python3 - <<'PY'
223+
import json
224+
import os
225+
import urllib.error
226+
import urllib.parse
227+
import urllib.request
228+
229+
token = os.environ["GITHUB_TOKEN"]
230+
repo = os.environ["TARGET_REPO"]
231+
issue_number = os.environ["ISSUE_NUMBER"]
232+
label_name = "experiment-validation"
233+
api_base = f"https://api.github.com/repos/{repo}"
234+
headers = {
235+
"Authorization": f"Bearer {token}",
236+
"Accept": "application/vnd.github+json",
237+
"X-GitHub-Api-Version": "2022-11-28",
238+
"User-Agent": "monthly-optimization-planner",
239+
}
240+
241+
def request_json(method: str, url: str, payload: dict | None = None):
242+
data = None
243+
if payload is not None:
244+
data = json.dumps(payload).encode("utf-8")
245+
request = urllib.request.Request(url, data=data, method=method, headers=headers)
246+
with urllib.request.urlopen(request) as response:
247+
raw = response.read().decode("utf-8")
248+
return json.loads(raw) if raw else {}
249+
250+
label_path = urllib.parse.quote(label_name, safe="")
251+
try:
252+
request_json("GET", f"{api_base}/labels/{label_path}")
253+
except urllib.error.HTTPError as exc:
254+
if exc.code != 404:
255+
raise
256+
request_json(
257+
"POST",
258+
f"{api_base}/labels",
259+
{
260+
"name": label_name,
261+
"color": "1D76DB",
262+
"description": "Trigger experiment validation for monthly optimization tasks",
263+
},
264+
)
265+
266+
issue = request_json("GET", f"{api_base}/issues/{issue_number}")
267+
existing_labels = [label["name"] for label in issue.get("labels", [])]
268+
if label_name in existing_labels:
269+
request_json("DELETE", f"{api_base}/issues/{issue_number}/labels/{label_path}")
270+
request_json("POST", f"{api_base}/issues/{issue_number}/labels", {"labels": [label_name]})
271+
print(f"Toggled {label_name} on issue #{issue_number} in {repo}")
272+
PY
273+
215274
- name: Dispatch BinancePlatform experiment validation
216275
if: steps.downstream_experiment_target.outputs.should_dispatch == 'true'
217276
env:

tests/test_experiment_validation_workflow_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def test_workflow_runs_shadow_build_and_posts_comment(self) -> None:
1515
self.assertIn("issues:", workflow)
1616
self.assertIn("workflow_dispatch:", workflow)
1717
self.assertIn("issue_number:", workflow)
18+
self.assertIn("self-hosted", workflow)
1819
self.assertIn("prepare_experiment_validation.py", workflow)
1920
self.assertIn("download_history.py", workflow)
2021
self.assertIn("run_monthly_shadow_build.py", workflow)

tests/test_monthly_optimization_planner_workflow_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def test_planner_workflow_downloads_artifacts_posts_issue_and_fans_out_tasks(sel
3232
self.assertIn("Resolve upstream experiment validation target", workflow)
3333
self.assertIn("Dispatch CryptoLeaderRotation experiment validation", workflow)
3434
self.assertIn("Resolve downstream experiment validation target", workflow)
35+
self.assertIn("Trigger BinancePlatform experiment validation by label", workflow)
36+
self.assertIn("experiment-validation", workflow)
3537
self.assertIn("Dispatch BinancePlatform experiment validation", workflow)
3638
self.assertIn("gh workflow run experiment_validation.yml", workflow)
3739
self.assertIn("--allow-permission-skip", workflow)

0 commit comments

Comments
 (0)