diff --git a/.github/rerun-workflow/action.yml b/.github/rerun-workflow/action.yml new file mode 100644 index 00000000000..f4d72f32d6b --- /dev/null +++ b/.github/rerun-workflow/action.yml @@ -0,0 +1,30 @@ +name: 'Rerun Workflow' +description: 'Re-run GitHub Actions workflow for a given Pull Request' +inputs: + GITHUB_TOKEN: + description: 'GitHub token with repo scope' + required: true + OWNER: + description: 'Repository owner' + required: true + REPO: + description: 'Repository name' + required: true + PR_ID: + description: 'Pull Request ID' + required: true + JOB_NAME: + description: 'Job name to rerun' + required: true + +runs: + using: 'composite' + steps: + - run: bash ./.github/actions/rerun-workflow/rerun.sh + shell: bash + env: + GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} + OWNER: ${{ inputs.OWNER }} + REPO: ${{ inputs.REPO }} + PR_ID: ${{ inputs.PR_ID }} + JOB_NAME: ${{ inputs.JOB_NAME }} diff --git a/.github/rerun-workflow/rerun.sh b/.github/rerun-workflow/rerun.sh new file mode 100644 index 00000000000..dce8a7fad3e --- /dev/null +++ b/.github/rerun-workflow/rerun.sh @@ -0,0 +1,77 @@ +# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +COMMIT_SHA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/$OWNER/$REPO/pulls/$PR_ID" | jq -r '.head.sha') + +echo "Commit SHA: $COMMIT_SHA" + +response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/$OWNER/$REPO/actions/runs?head_sha=$COMMIT_SHA&per_page=100") + +echo "Response: $response" + +run_ids=$(echo "$response" | jq -r '.workflow_runs[].id') + +if [ -n "$run_ids" ]; then + echo "Found run_ids for commit $COMMIT_SHA: $run_ids" + + for run_id in $run_ids; do + if [ "$JOB_NAME" = "all-failed" ]; then + echo "Rerunning all failed jobs for run_id: $run_id" + + rerun_response=$(curl -X POST -s -w "%{http_code}" -o /dev/null \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id/rerun-failed-jobs") + if [ "$rerun_response" -eq 201 ]; then + echo "Successfully requested rerun for all blocked jobs in run_id: $run_id" + else + echo "Failed to request rerun for run_id: $run_id with status code $rerun_response" + fi + + else + jobs_response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id/jobs") + + echo "Jobs Response for run_id $run_id: $jobs_response" + + # if [[ "$JOB_NAME" == *"bypass"* ]]; then + block_jobs=$(echo "$jobs_response" | jq -r --arg job_name "$JOB_NAME" \ + '.jobs[] | select(.name == $job_name) | .id') + # else + # block_jobs=$(echo "$jobs_response" | jq -r --arg job_name "$JOB_NAME" \ + # '.jobs[] | select(.name == $job_name and .conclusion != "success") | .id') + # fi + + if [ -n "$block_jobs" ]; then + echo "Found block jobs for run_id $run_id: $block_jobs" + + for job_id in $block_jobs; do + echo "Rerunning job_id: $job_id" + curl -X POST -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/$OWNER/$REPO/actions/jobs/$job_id/rerun" + done + else + echo "No block jobs found for run_id $run_id with name $JOB_NAME." + fi + fi + done +else + echo "No matching workflow runs found for commit $COMMIT_SHA." + exit 1 +fi diff --git a/.github/workflows/rerun.yml b/.github/workflows/rerun.yml new file mode 100644 index 00000000000..1cca4143f29 --- /dev/null +++ b/.github/workflows/rerun.yml @@ -0,0 +1,157 @@ +name: Re-run + +on: + issue_comment: + types: [created] + +jobs: + re-run: + if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/re-run') && github.event.comment.user.login == github.event.issue.user.login }} + runs-on: ubuntu-latest + steps: + - name: Cleanup + run: | + rm -rf * .[^.]* + + - name: Checkout code + uses: actions/checkout@v5 + + - name: Rerun all failed jobs + if: ${{ contains(github.event.comment.body, 'all-failed') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'all-failed' + + - name: Rerun Approval + if: ${{ contains(github.event.comment.body, 'approval') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'Approval' + + - name: Rerun CI_ILUVATAR + if: ${{ contains(github.event.comment.body, 'ci_iluvatar') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'CI_ILUVATAR' + + - name: Rerun CI_XPU + if: ${{ contains(github.event.comment.body, 'ci_xpu') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'CI_XPU' + + - name: Rerun Codestyle-check + if: ${{ contains(github.event.comment.body, 'codestyle') || contains(github.event.comment.body, 'pre_commit') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'Pre Commit' + + - name: Rerun Clone + if: ${{ contains(github.event.comment.body, 'clone') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'FD-Clone-Linux / code-clone' + + - name: Rerun Build + if: ${{ contains(github.event.comment.body, 'build') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'FD-Build-Linux / fd-build' + + - name: Rerun run_ce_cases + if: ${{ contains(github.event.comment.body, 'run_ce_cases') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'Extracted partial CE model tasks to run in CI. / run_ce_cases' + + - name: Rerun accuracy_tests + if: ${{ contains(github.event.comment.body, 'accuracy_tests') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'Run Accuracy Tests / accuracy_tests' + + - name: Rerun base_tests + if: ${{ contains(github.event.comment.body, 'base_tests') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'Run Base Tests / base_tests' + + - name: Rerun run_tests_logprob + if: ${{ contains(github.event.comment.body, 'run_tests_logprob') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'Run FastDeploy LogProb Tests / run_tests_logprob' + + - name: Rerun run_tests_with_coverage + if: ${{ contains(github.event.comment.body, 'run_tests_with_coverage') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage' + + - name: Rerun diff_coverage_report + if: ${{ contains(github.event.comment.body, 'diff_coverage_report') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'Run FastDeploy Unit Tests and Coverage / diff_coverage_report' + + - name: Rerun stable_tests + if: ${{ contains(github.event.comment.body, 'stable_tests') }} + uses: ./.github/actions/rerun-workflow + with: + PR_ID: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + JOB_NAME: 'Run Stable Tests / stable_tests'