@@ -157,7 +157,73 @@ jobs:
157157 issues : write
158158 steps :
159159 - name : Check whether one of the jobs failed
160+ id : report_failure
160161 if : ${{ contains(needs.*.result, 'failure') && github.event.pull_request == null && github.event_name != 'workflow_dispatch' }}
161162 uses : jayqi/failed-build-issue-action@1a893bbf43ef1c2a8705e2b115cd4f0fe3c5649b # v1.2.0
162163 with :
163164 github-token : ${{ secrets.GITHUB_TOKEN }}
165+ labels : " failed-build"
166+
167+ - name : Reset consecutive success counter on failure
168+ # This runs only if the previous step actually found or created an issue
169+ if : ${{ steps.report_failure.outputs.issue-number != '' }}
170+ env :
171+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
172+ GH_REPO : ${{ github.repository }}
173+ # Use the issue number from the previous step's output
174+ ISSUE_NUMBER : ${{ steps.report_failure.outputs.issue-number }}
175+ run : |
176+ echo "A failure occurred. Resetting success counter on issue #${ISSUE_NUMBER}."
177+ # This command will attempt to remove both labels.
178+ # It will not fail if the labels don't exist.
179+ gh issue remove-label $ISSUE_NUMBER "success-run-1" "success-run-2" --repo $GH_REPO || echo "No success labels to remove."
180+
181+ notify_success_and_close :
182+ name : Close issue after 3 successful builds
183+ # This job runs only if all the preceding test jobs succeeded
184+ if : ${{ success() && github.event.pull_request == null && github.event_name != 'workflow_dispatch' }}
185+ needs : [cpu_unit_tests, gpu_unit_tests, gpu_integration_tests, tpu_unit_tests, tpu_integration_tests]
186+ runs-on : ubuntu-latest
187+ permissions :
188+ issues : write
189+ steps :
190+ - name : Find existing failure issue
191+ id : find_issue
192+ env :
193+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
194+ GH_REPO : ${{ github.repository }}
195+ run : |
196+ ISSUE_NUMBER=$(gh issue list --label "failed-build" --state open --limit 1 --json number -q '.[0].number')
197+ if [[ -z "$ISSUE_NUMBER" ]]; then
198+ echo "No open build failure issue found. Nothing to do."
199+ echo "issue_number=" >> $GITHUB_OUTPUT
200+ else
201+ echo "Found open build failure issue: #${ISSUE_NUMBER}"
202+ echo "issue_number=${ISSUE_NUMBER}" >> $GITHUB_OUTPUT
203+ fi
204+
205+ - name : Add success label or close issue
206+ if : steps.find_issue.outputs.issue_number != ''
207+ env :
208+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
209+ GH_REPO : ${{ github.repository }}
210+ run : |
211+ ISSUE_NUMBER=${{ steps.find_issue.outputs.issue_number }}
212+ LABELS=$(gh issue view $ISSUE_NUMBER --json labels -q '.labels[].name')
213+
214+ if echo "$LABELS" | grep -q "success-run-2"; then
215+ echo "Third consecutive success. Closing issue #${ISSUE_NUMBER}."
216+ gh issue comment $ISSUE_NUMBER --body "Build succeeded for the third consecutive time. Closing this issue automatically."
217+ gh issue close $ISSUE_NUMBER
218+ # Clean up all tracking labels
219+ gh issue remove-label $ISSUE_NUMBER "failed-build" "success-run-2" --repo $GH_REPO
220+ elif echo "$LABELS" | grep -q "success-run-1"; then
221+ echo "Second consecutive success. Updating label on issue #${ISSUE_NUMBER}."
222+ gh issue comment $ISSUE_NUMBER --body "Build succeeded for the second time. One more successful run will close this issue."
223+ gh issue remove-label $ISSUE_NUMBER "success-run-1" --repo $GH_REPO
224+ gh issue add-label $ISSUE_NUMBER "success-run-2" --repo $GH_REPO
225+ else
226+ echo "First consecutive success since failure. Adding label to issue #${ISSUE_NUMBER}."
227+ gh issue comment $ISSUE_NUMBER --body "Build succeeded. This issue will be auto-closed after two more consecutive successful runs."
228+ gh issue add-label $ISSUE_NUMBER "success-run-1" --repo $GH_REPO
229+ fi
0 commit comments