Skip to content

Commit 83943fd

Browse files
committed
Always use run_tpu_tests label to run the TPU tests.
Problem: the current approach creates two entries for TPU tests: one for `pull_request` and one for `pull_request_review`. But we only want one entry and one run of the tests. Solution: we are reusing the current labeler workflow to label the PR on approval, which in turn triggers the TPU tests. Also fix indentation in `labeler.js` and rename `welcome`.
1 parent 7631c1a commit 83943fd

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

.github/workflows/labeler.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,23 @@ on:
2424
types: [edited,opened]
2525
pull_request_target:
2626
types: [opened, edited]
27+
pull_request_review:
28+
types: [submitted]
2729

2830
permissions:
2931
contents: read
3032
issues: write
3133
pull-requests: write
3234

3335
jobs:
34-
welcome:
36+
add_labels:
3537
runs-on: ubuntu-latest
38+
# Only run on "approved" reviews for the "pull_request_review" event.
39+
# We test here because the script does not get the review information.
40+
if: |
41+
github.event_name != 'pull_request_review' ||
42+
github.event.review.state == 'approved'
43+
3644
steps:
3745
- uses: actions/checkout@v5
3846
- uses: actions/github-script@v8

.github/workflows/scripts/labeler.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,34 @@ You may obtain a copy of the License at
2222
*/
2323

2424
module.exports = async ({ github, context }) => {
25+
const labelsToAdd = []
26+
if (context.eventName == 'pull_request_review') {
27+
const issue_number = context.payload.pull_request.number
28+
labelsToAdd.push('run_tpu_tests')
29+
console.log(`Pull request review event. Pushing label 'run_tpu_tests' to row.`)
30+
} else {
2531
const issue_title = context.payload.issue ? context.payload.issue.title : context.payload.pull_request.title
2632
const issue_description = context.payload.issue ? context.payload.issue.body : context.payload.pull_request.body
2733
const issue_number = context.payload.issue ? context.payload.issue.number : context.payload.pull_request.number
2834
const keyword_label = {
29-
gemma:'Gemma'
35+
gemma:'Gemma'
3036
}
31-
const labelsToAdd = []
3237
console.log(issue_title,issue_description,issue_number)
3338

3439
for(const [keyword, label] of Object.entries(keyword_label)){
35-
if(issue_title.toLowerCase().indexOf(keyword) !=-1 || issue_description.toLowerCase().indexOf(keyword) !=-1 ){
40+
if(issue_title.toLowerCase().indexOf(keyword) !=-1 || issue_description.toLowerCase().indexOf(keyword) !=-1 ){
3641
console.log(`'${keyword}'keyword is present inside the title or description. Pushing label '${label}' to row.`)
3742
labelsToAdd.push(label)
43+
}
3844
}
39-
}
40-
if(labelsToAdd.length > 0){
45+
}
46+
if (labelsToAdd.length > 0) {
4147
console.log(`Adding labels ${labelsToAdd} to the issue '#${issue_number}'.`)
42-
github.rest.issues.addLabels({
43-
owner: context.repo.owner,
44-
repo: context.repo.repo,
45-
issue_number: context.issue.number,
46-
labels: labelsToAdd
47-
})
48-
}
49-
};
48+
github.rest.issues.addLabels({
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
issue_number: issue_number,
52+
labels: labelsToAdd
53+
})
54+
}
55+
};

.github/workflows/tpu_tests.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ on:
88
branches: [ master ]
99
pull_request:
1010
types: [labeled]
11-
pull_request_review:
12-
types: [submitted]
1311
release:
1412
types: [created]
1513

@@ -25,8 +23,7 @@ jobs:
2523
if: |
2624
github.event_name == 'push' ||
2725
github.event_name == 'release' ||
28-
(github.event_name == 'pull_request' && github.event.action == 'labeled' && github.event.label.name == 'run_tpu_tests') ||
29-
(github.event_name == 'pull_request_review' && github.event.review.state == 'approved')
26+
(github.event_name == 'pull_request' && github.event.action == 'labeled' && github.event.label.name == 'run_tpu_tests')
3027
3128
strategy:
3229
fail-fast: false

0 commit comments

Comments
 (0)