mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-06 08:16:43 +00:00
detect-backend-changes diffed the event payload's base.sha against the checked-out ref. Those are two different points in time: actions/checkout resolves refs/pull/N/merge, and GitHub recomputes that ref whenever the base branch advances, so the diff picked up whatever landed on staging between the event firing and the job starting. On a recent UI-only pull request three backend commits from staging were attributed to the branch, and every backend shard ran in full Ask the API which files the pull request touches instead. That is the same set the Files changed tab shows, and it is immune to either endpoint moving. The shell body moves into .github/scripts/detect_backend_changes.sh so it can be exercised directly, and the fail-open paths now also cover an API failure, a file list past the API's 3000-entry listing ceiling, and a classifier that prints something unexpected
41 lines
1.4 KiB
Bash
Executable file
41 lines
1.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -uo pipefail
|
|
|
|
readonly API_FILE_CEILING=3000
|
|
|
|
decide() {
|
|
echo "detect-backend-changes: decision=$1"
|
|
[ -z "${GITHUB_OUTPUT:-}" ] || echo "decision=$1" >>"${GITHUB_OUTPUT}"
|
|
exit 0
|
|
}
|
|
|
|
run_full() {
|
|
echo "detect-backend-changes: $1; running job"
|
|
decide run
|
|
}
|
|
|
|
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
classify="${here}/../../.circleci/scripts/classify_changes.sh"
|
|
|
|
[ -n "${PR_NUMBER:-}" ] || run_full "not a pull_request event"
|
|
[ -n "${REPO:-}" ] || run_full "no repository in the environment"
|
|
|
|
case "${CHANGED_FILE_COUNT:-}" in
|
|
'' | *[!0-9]*) run_full "the event payload carries no changed_files count" ;;
|
|
esac
|
|
[ "${CHANGED_FILE_COUNT}" -le "${API_FILE_CEILING}" ] ||
|
|
run_full "PR #${PR_NUMBER} changes ${CHANGED_FILE_COUNT} files, past the ${API_FILE_CEILING}-file listing ceiling"
|
|
|
|
changed="$(gh api "repos/${REPO}/pulls/${PR_NUMBER}/files" --paginate --jq '.[].filename')" ||
|
|
run_full "could not list the files on PR #${PR_NUMBER}"
|
|
[ -n "${changed}" ] || run_full "the API listed no files on PR #${PR_NUMBER}"
|
|
|
|
echo "detect-backend-changes: files changed by PR #${PR_NUMBER}:"
|
|
printf '%s\n' "${changed}" | sed 's/^/ /'
|
|
|
|
decision="$(printf '%s\n' "${changed}" | bash "${classify}" backend)" ||
|
|
run_full "classify_changes.sh failed"
|
|
case "${decision}" in
|
|
run | skip) decide "${decision}" ;;
|
|
*) run_full "classify_changes.sh printed an unexpected decision: ${decision}" ;;
|
|
esac
|