Skip to content

Commit c266b2b

Browse files
authored
Try workflow dispatch (#76)
* Fix the bug of evaluation is not triggered * Try workflow dispatch
1 parent 9fab983 commit c266b2b

2 files changed

Lines changed: 51 additions & 68 deletions

File tree

.github/workflows/pr-evaluation-run.yml

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
11
name: Router Submission Evaluation
22

33
on:
4-
pull_request_target:
5-
types: [labeled, synchronize, reopened]
4+
workflow_dispatch:
5+
inputs:
6+
pr_number:
7+
description: Pull request number to evaluate
8+
required: true
9+
type: string
10+
base_ref:
11+
description: Base branch ref for evaluation scripts checkout
12+
required: true
13+
type: string
14+
base_sha:
15+
description: Base commit SHA for PR diff/evaluation
16+
required: true
17+
type: string
618

719
jobs:
820
evaluate-router:
9-
if: >-
10-
contains(github.event.pull_request.labels.*.name, 'evaluate-requested') &&
11-
(
12-
github.event.action != 'labeled' ||
13-
github.event.label.name == 'evaluate-requested'
14-
)
1521
runs-on: self-hosted
1622
permissions:
1723
contents: read
1824
issues: write
1925
checks: write
2026
pull-requests: write
27+
env:
28+
PR_NUMBER: ${{ inputs.pr_number }}
29+
BASE_REF: ${{ inputs.base_ref }}
30+
BASE_SHA: ${{ inputs.base_sha }}
31+
PR_CHECKOUT_REF: ${{ format('refs/pull/{0}/head', inputs.pr_number) }}
2132
steps:
2233
- name: Checkout base repository (for evaluation scripts)
2334
uses: actions/checkout@v4
2435
with:
25-
ref: ${{ github.event.pull_request.base.ref }}
36+
ref: ${{ env.BASE_REF }}
2637
path: base
2738
fetch-depth: 0
2839

2940
- name: Checkout PR branch (for prediction file only)
3041
uses: actions/checkout@v4
3142
with:
32-
ref: ${{ github.event.pull_request.head.sha }}
43+
ref: ${{ env.PR_CHECKOUT_REF }}
3344
path: pr
3445
fetch-depth: 0
3546

@@ -39,8 +50,8 @@ jobs:
3950
working-directory: pr
4051
run: |
4152
set -euo pipefail
42-
BASE_REF="${{ github.event.pull_request.base.ref }}"
43-
BASE_SHA="${{ github.event.pull_request.base.sha }}"
53+
BASE_REF="${{ env.BASE_REF }}"
54+
BASE_SHA="${{ env.BASE_SHA }}"
4455
4556
if [[ -z "$BASE_SHA" ]]; then
4657
echo "Error: Could not determine PR base SHA" >&2
@@ -154,9 +165,9 @@ jobs:
154165
ROUTERARENA_DATASET_DIR: ${{ github.workspace }}/dataset
155166
run: |
156167
set -euo pipefail; trap 'cat evaluation_output.txt' EXIT
157-
BASE_SHA="${{ github.event.pull_request.base.sha }}"
168+
BASE_SHA="${{ env.BASE_SHA }}"
158169
uv run python automation/process_pr_submission.py \
159-
--pr "${{ github.event.pull_request.number }}" \
170+
--pr "${{ env.PR_NUMBER }}" \
160171
--router "${{ steps.detect.outputs.router }}" \
161172
--split "${{ steps.detect.outputs.split }}" \
162173
--base-ref "$BASE_SHA" > evaluation_output.txt 2>&1
@@ -206,28 +217,9 @@ jobs:
206217
comment += '*Evaluation completed by RouterArena automated workflow*';
207218
208219
await github.rest.issues.createComment({
209-
issue_number: context.payload.pull_request.number,
220+
issue_number: Number('${{ env.PR_NUMBER }}'),
210221
owner: context.repo.owner,
211222
repo: context.repo.repo,
212223
body: comment
213224
});
214225
console.log('Successfully posted evaluation results as PR comment');
215-
216-
- name: Remove evaluation label
217-
if: ${{ always() }}
218-
uses: actions/github-script@v7
219-
with:
220-
script: |
221-
try {
222-
await github.rest.issues.removeLabel({
223-
owner: context.repo.owner,
224-
repo: context.repo.repo,
225-
issue_number: context.payload.pull_request.number,
226-
name: 'evaluate-requested'
227-
});
228-
} catch (error) {
229-
// Ignore if label is already removed/missing.
230-
if (error.status !== 404) {
231-
throw error;
232-
}
233-
}

.github/workflows/pr-evaluation.yml

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
)
1818
runs-on: self-hosted
1919
permissions:
20+
actions: write
2021
issues: write
2122
pull-requests: write
2223
checks: write
@@ -43,42 +44,32 @@ jobs:
4344
}
4445
}
4546
46-
- name: Add evaluation label to PR
47+
- name: Fetch PR details
48+
id: pr
4749
uses: actions/github-script@v7
48-
env:
49-
HAS_ROUTER_EVAL_BOT_TOKEN: ${{ secrets.ROUTER_EVAL_BOT_TOKEN != '' }}
5050
with:
51-
github-token: ${{ secrets.ROUTER_EVAL_BOT_TOKEN || github.token }}
5251
script: |
53-
const labelName = 'evaluate-requested';
54-
const issue_number = context.payload.issue.number;
55-
if (process.env.HAS_ROUTER_EVAL_BOT_TOKEN !== 'true') {
56-
core.warning('ROUTER_EVAL_BOT_TOKEN is not configured. Labeling may not trigger the evaluation workflow due to GITHUB_TOKEN recursion guard.');
57-
}
52+
const pr = await github.rest.pulls.get({
53+
owner: context.repo.owner,
54+
repo: context.repo.repo,
55+
pull_number: context.payload.issue.number
56+
});
57+
core.setOutput('number', String(pr.data.number));
58+
core.setOutput('base_ref', pr.data.base.ref);
59+
core.setOutput('base_sha', pr.data.base.sha);
5860
59-
try {
60-
await github.rest.issues.addLabels({
61-
owner: context.repo.owner,
62-
repo: context.repo.repo,
63-
issue_number,
64-
labels: [labelName]
65-
});
66-
} catch (error) {
67-
// If the label does not exist yet, create it once then retry.
68-
if (error.status !== 422) {
69-
throw error;
61+
- name: Dispatch evaluation workflow
62+
uses: actions/github-script@v7
63+
with:
64+
script: |
65+
await github.rest.actions.createWorkflowDispatch({
66+
owner: context.repo.owner,
67+
repo: context.repo.repo,
68+
workflow_id: 'pr-evaluation-run.yml',
69+
ref: '${{ steps.pr.outputs.base_ref }}',
70+
inputs: {
71+
pr_number: '${{ steps.pr.outputs.number }}',
72+
base_ref: '${{ steps.pr.outputs.base_ref }}',
73+
base_sha: '${{ steps.pr.outputs.base_sha }}'
7074
}
71-
await github.rest.issues.createLabel({
72-
owner: context.repo.owner,
73-
repo: context.repo.repo,
74-
name: labelName,
75-
color: '0e8a16',
76-
description: 'Triggers Router Submission Evaluation workflow'
77-
});
78-
await github.rest.issues.addLabels({
79-
owner: context.repo.owner,
80-
repo: context.repo.repo,
81-
issue_number,
82-
labels: [labelName]
83-
});
84-
}
75+
});

0 commit comments

Comments
 (0)