chore: import upstream snapshot with attribution
This commit is contained in:
@@ -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 }}
|
||||
@@ -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
|
||||
@@ -0,0 +1,47 @@
|
||||
name: 'PR Skip Check'
|
||||
description: 'Check if PR should skip CI based on file paths'
|
||||
author: 'Paddle CI Team'
|
||||
|
||||
inputs:
|
||||
ignore-paths:
|
||||
description: 'Comma-separated paths to ignore (e.g., "skill/**,docs/**,**.md")'
|
||||
required: true
|
||||
default: '.agents/skills/**'
|
||||
base-ref:
|
||||
description: 'Base branch (defaults to PR target branch)'
|
||||
required: false
|
||||
default: ${{ github.event.pull_request.base.ref }}
|
||||
|
||||
outputs:
|
||||
should-skip:
|
||||
description: 'Whether CI should be skipped (true/false)'
|
||||
value: ${{ steps.check.outputs.should-skip }}
|
||||
is-pr:
|
||||
description: 'Whether it is a PR event'
|
||||
value: ${{ steps.check.outputs.is-pr }}
|
||||
changed-files:
|
||||
description: 'List of all changed files (newline separated)'
|
||||
value: ${{ steps.check.outputs.changed-files }}
|
||||
non-ignored-files:
|
||||
description: 'List of files not in ignored paths'
|
||||
value: ${{ steps.check.outputs.non-ignored-files }}
|
||||
total-count:
|
||||
description: 'Total number of changed files'
|
||||
value: ${{ steps.check.outputs.total-count }}
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Run PR skip check script
|
||||
id: check
|
||||
shell: bash
|
||||
run: bash ${{ github.action_path }}/check_skip.sh
|
||||
env:
|
||||
IGNORE_PATHS: ${{ inputs.ignore-paths }}
|
||||
BASE_REF: ${{ inputs.base-ref }}
|
||||
GITHUB_EVENT_NAME: ${{ github.event_name }}
|
||||
Executable
+155
@@ -0,0 +1,155 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright (c) 2026 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
|
||||
|
||||
echo "🔍 [PR Skip Check] Starting..."
|
||||
|
||||
# Parse input parameters
|
||||
IFS=',' read -ra IGNORE_PATHS <<< "${IGNORE_PATHS:-skill/**}"
|
||||
BASE_REF="${BASE_REF:-$GITHUB_BASE_REF}"
|
||||
|
||||
echo "📋 Event type: $GITHUB_EVENT_NAME"
|
||||
echo "📋 Ignore path patterns:"
|
||||
printf ' - %s\n' "${IGNORE_PATHS[@]}"
|
||||
|
||||
# Initialize output
|
||||
IS_PR="false"
|
||||
SHOULD_SKIP="false"
|
||||
CHANGED_FILES=""
|
||||
NON_IGNORED_FILES=""
|
||||
TOTAL_COUNT=0
|
||||
|
||||
# Check if PR event
|
||||
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
|
||||
IS_PR="true"
|
||||
echo "🔄 Detected PR event, running skip check"
|
||||
|
||||
# Get PR changed files
|
||||
get_pr_changed_files() {
|
||||
local files=""
|
||||
|
||||
if [ -n "$BASE_REF" ]; then
|
||||
echo "📌 Base branch: $BASE_REF" >&2
|
||||
files=$(git diff --name-only "origin/$BASE_REF...HEAD" 2>/dev/null)
|
||||
else
|
||||
echo "⚠️ No base branch specified, using HEAD^..HEAD" >&2
|
||||
files=$(git diff --name-only HEAD^ HEAD 2>/dev/null || echo "")
|
||||
fi
|
||||
|
||||
echo "$files" | grep -v '^$' || echo ""
|
||||
}
|
||||
|
||||
CHANGED_FILES=$(get_pr_changed_files)
|
||||
|
||||
if [ -n "$CHANGED_FILES" ]; then
|
||||
echo "📋 PR changed files:"
|
||||
echo "$CHANGED_FILES" | sed 's/^/ - /'
|
||||
|
||||
# Count total
|
||||
TOTAL_COUNT=$(echo "$CHANGED_FILES" | wc -l | xargs)
|
||||
|
||||
# Check if files match ignore patterns
|
||||
check_files() {
|
||||
local non_ignored=""
|
||||
|
||||
echo "🔍 [DEBUG] Starting to check files..." >&2
|
||||
|
||||
while IFS= read -r file; do
|
||||
[ -z "$file" ] && continue
|
||||
echo "🔍 [DEBUG] Checking file: '$file'" >&2
|
||||
|
||||
is_ignored=false
|
||||
echo "🔍 [DEBUG] IGNORE_PATHS length: ${#IGNORE_PATHS[@]}" >&2
|
||||
for pattern in "${IGNORE_PATHS[@]}"; do
|
||||
pattern=$(echo "$pattern" | xargs)
|
||||
echo "🔍 [DEBUG] Original pattern: '$pattern'" >&2
|
||||
if [ -n "$pattern" ]; then
|
||||
# Replace ** with * for bash pattern matching
|
||||
bash_pattern="${pattern//\**/*}"
|
||||
echo "🔍 [DEBUG] bash_pattern: '$bash_pattern'" >&2
|
||||
# Debug: show pattern matching
|
||||
if [[ "$file" == $bash_pattern ]]; then
|
||||
is_ignored=true
|
||||
echo " ✅ Ignored: $file (pattern: $pattern -> $bash_pattern)" >&2
|
||||
break
|
||||
else
|
||||
echo " 🔍 Check: $file (pattern: $pattern -> $bash_pattern) - no match" >&2
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$is_ignored" = false ]; then
|
||||
echo " ❌ Not ignored: $file" >&2
|
||||
if [ -z "$non_ignored" ]; then
|
||||
non_ignored="$file"
|
||||
else
|
||||
non_ignored="$non_ignored"$'\n'"$file"
|
||||
fi
|
||||
fi
|
||||
done <<< "$CHANGED_FILES"
|
||||
|
||||
echo "$non_ignored"
|
||||
}
|
||||
|
||||
NON_IGNORED_FILES=$(check_files)
|
||||
|
||||
echo "📋 Non-ignored files:"
|
||||
echo "$NON_IGNORED_FILES" | sed 's/^/ - /'
|
||||
|
||||
# Determine if should skip
|
||||
if [ -z "$NON_IGNORED_FILES" ]; then
|
||||
SHOULD_SKIP="true"
|
||||
echo "✅ All PR changes are in ignored paths, can skip CI"
|
||||
else
|
||||
SHOULD_SKIP="false"
|
||||
echo "❌ Some files not in ignored paths, continue CI"
|
||||
fi
|
||||
else
|
||||
echo "📭 No changed files detected in PR"
|
||||
SHOULD_SKIP="false"
|
||||
fi
|
||||
else
|
||||
# Non-PR event (push, workflow_dispatch, etc.)
|
||||
echo "🔄 not a PR event ($GITHUB_EVENT_NAME), run CI"
|
||||
SHOULD_SKIP="false"
|
||||
fi
|
||||
|
||||
# Set output variables
|
||||
echo "should-skip=$SHOULD_SKIP" >> $GITHUB_OUTPUT
|
||||
echo "is-pr=$IS_PR" >> $GITHUB_OUTPUT
|
||||
echo "total-count=$TOTAL_COUNT" >> $GITHUB_OUTPUT
|
||||
|
||||
# Handle multiline output (changed-files)
|
||||
if [ -n "$CHANGED_FILES" ]; then
|
||||
echo 'changed-files<<EOF' >> $GITHUB_OUTPUT
|
||||
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
|
||||
echo 'EOF' >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "changed-files=" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
# Handle multiline output (non-ignored-files)
|
||||
if [ -n "$NON_IGNORED_FILES" ]; then
|
||||
echo 'non-ignored-files<<EOF' >> $GITHUB_OUTPUT
|
||||
echo "$NON_IGNORED_FILES" >> $GITHUB_OUTPUT
|
||||
echo 'EOF' >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "non-ignored-files=" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
echo "📊 total=$TOTAL_COUNT, can skip=$SHOULD_SKIP"
|
||||
echo "✅ [PR Skip Check] finished"
|
||||
Reference in New Issue
Block a user