chore: import upstream snapshot with attribution
This commit is contained in:
@@ -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