|
| 1 | +# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +set -e |
| 16 | + |
| 17 | +COMMIT_SHA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ |
| 18 | + "https://api.github.com/repos/$OWNER/$REPO/pulls/$PR_ID" | jq -r '.head.sha') |
| 19 | + |
| 20 | +echo "Commit SHA: $COMMIT_SHA" |
| 21 | + |
| 22 | +response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ |
| 23 | + "https://api.github.com/repos/$OWNER/$REPO/actions/runs?head_sha=$COMMIT_SHA&per_page=100") |
| 24 | + |
| 25 | +echo "Response: $response" |
| 26 | + |
| 27 | +run_ids=$(echo "$response" | jq -r '.workflow_runs[].id') |
| 28 | + |
| 29 | +if [ -n "$run_ids" ]; then |
| 30 | + echo "Found run_ids for commit $COMMIT_SHA: $run_ids" |
| 31 | + |
| 32 | + for run_id in $run_ids; do |
| 33 | + if [ "$JOB_NAME" = "all-failed" ]; then |
| 34 | + echo "Rerunning all failed jobs for run_id: $run_id" |
| 35 | + |
| 36 | + rerun_response=$(curl -X POST -s -w "%{http_code}" -o /dev/null \ |
| 37 | + -H "Accept: application/vnd.github.v3+json" \ |
| 38 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 39 | + "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id/rerun-failed-jobs") |
| 40 | + if [ "$rerun_response" -eq 201 ]; then |
| 41 | + echo "Successfully requested rerun for all blocked jobs in run_id: $run_id" |
| 42 | + else |
| 43 | + echo "Failed to request rerun for run_id: $run_id with status code $rerun_response" |
| 44 | + fi |
| 45 | + |
| 46 | + else |
| 47 | + jobs_response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ |
| 48 | + "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id/jobs") |
| 49 | + |
| 50 | + echo "Jobs Response for run_id $run_id: $jobs_response" |
| 51 | + |
| 52 | + block_jobs=$(echo "$jobs_response" | jq -r --arg job_name "$JOB_NAME" \ |
| 53 | + '.jobs[] | select(.name == $job_name and .conclusion != "success") | .id') |
| 54 | + |
| 55 | + if [ -n "$block_jobs" ]; then |
| 56 | + echo "Found block jobs for run_id $run_id: $block_jobs" |
| 57 | + |
| 58 | + for job_id in $block_jobs; do |
| 59 | + echo "Rerunning job_id: $job_id" |
| 60 | + curl -X POST -H "Accept: application/vnd.github.v3+json" \ |
| 61 | + -H "Authorization: token $GITHUB_TOKEN" \ |
| 62 | + "https://api.github.com/repos/$OWNER/$REPO/actions/jobs/$job_id/rerun" |
| 63 | + done |
| 64 | + else |
| 65 | + echo "No block jobs found for run_id $run_id with name $JOB_NAME." |
| 66 | + fi |
| 67 | + fi |
| 68 | + done |
| 69 | +else |
| 70 | + echo "No matching workflow runs found for commit $COMMIT_SHA." |
| 71 | + exit 1 |
| 72 | +fi |
0 commit comments