1515name : Add Label
1616
1717on :
18+ pull_request : # include this workflow in PR triggered Actions
1819 workflow_run :
19- workflows : [Tests, CodeQL ]
20+ workflows : ["MaxText Package Tests" ]
2021 types :
2122 - completed
2223 pull_request_review :
2324 pull_request_review_comment :
2425 workflow_dispatch :
2526
2627jobs :
28+ WaitForCI :
29+ runs-on : ubuntu-latest
30+ steps :
31+ - name : Wait for CI workflow to succeed
32+ uses : lewagon/wait-on-check-action@v1.3.1
33+ with :
34+ ref : ${{ github.event.pull_request.head.sha }}
35+ check-name : ' MaxText Package Tests' # The name of the job in Workflow A
36+ repo-token : ${{ secrets.GITHUB_TOKEN }}
37+ wait-interval : 10
38+
2739 AddPullReady :
40+ needs : [WaitForCI]
2841 permissions :
2942 checks : read
3043 pull-requests : write
3144 runs-on : ubuntu-latest
3245
3346 steps :
34- - uses : actions/github-script@v7
47+ - name : Add Pull Request Label
48+ uses : actions/github-script@v7
3549 with :
3650 script : |
3751 const owner = "google"
4054 if (context.payload.pull_request !== undefined) {
4155 pull_number = context.payload.pull_request.number
4256 } else if (context.payload.workflow_run !== undefined) {
57+ workflow_name = context.payload.workflow_run.name
4358 if (context.payload.workflow_run.pull_requests.length === 0) {
4459 console.log("This workflow is NOT running within a PR's context")
45- process.exit()
60+ process.exit(1 )
4661 }
4762 console.log(context.payload.workflow_run.pull_requests)
4863 pull_number = context.payload.workflow_run.pull_requests[0].number
@@ -68,15 +83,15 @@ jobs:
6883
6984 if (reviews.data.length === 0) {
7085 console.log("Not adding pull ready because the PR is not approved yet.")
71- process.exit()
86+ process.exit(1 )
7287 }
7388 let is_approved = false
7489 if (decision_result.repository.pullRequest.reviewDecision === "APPROVED") {
7590 is_approved = true
7691 }
7792 if (!is_approved) {
7893 console.log("Not adding pull ready because the PR is not approved yet by sufficient code owners.")
79- process.exit()
94+ process.exit(1 )
8095 }
8196
8297 const commits = await github.rest.pulls.listCommits({
@@ -85,11 +100,11 @@ jobs:
85100 pull_number,
86101 per_page: 100,
87102 })
88- // Check that the number of commits in the PR is 1.
89- if (commits.data.length !== 1) {
90- console.log("Not adding pull ready because the PR has more than one commit. Please squash your commits.")
91- process.exit(1)
92- }
103+ // Check that the number of commits in the PR is 1. This is not enforced in practice.
104+ // if (commits.data.length !== 1) {
105+ // console.log("Not adding pull ready because the PR has more than one commit. Please squash your commits.")
106+ // process.exit(1)
107+ // }
93108 const ref = commits.data.slice(-1)[0].sha
94109 const checkRuns = await github.rest.checks.listForRef({
95110 owner,
@@ -98,13 +113,13 @@ jobs:
98113 })
99114 if (checkRuns.data.check_runs.length === 0) {
100115 console.log("Not adding pull ready because no check runs are associated with the last commit: " + ref)
101- process.exit()
116+ process.exit(1 )
102117 }
103118 for (const checkRun of checkRuns.data.check_runs) {
104119 if (checkRun.name.endsWith(context.job)) continue
105120 if (checkRun.conclusion !== "success") {
106121 console.log("Not adding pull ready because " + checkRun.name + " has not passed yet: " + checkRun.html_url)
107- process.exit()
122+ process.exit(1 )
108123 }
109124 }
110125 console.log("Adding pull ready label because the PR is approved AND all the check runs have passed")
0 commit comments