Skip to content

Commit 5a9bcee

Browse files
committed
fix: ensure breaking change detection works on forked branches
also fail on warnings
1 parent 018baf9 commit 5a9bcee

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

scripts/api-diff/api-diff.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ cd "$(dirname "$0")/../.."
1212

1313
# Configuration
1414
DOCKER_IMAGE="${OASDIFF_DOCKER_IMAGE:-tufin/oasdiff:latest}"
15-
BASE_BRANCH="${BASE_BRANCH:-origin/master}"
15+
16+
# Detect base branch from GitHub Actions environment or fallback to local defaults
17+
if [ -n "$GITHUB_BASE_REF" ]; then
18+
# In GitHub Actions PR, use the base ref (e.g., "master")
19+
BASE_BRANCH="${BASE_BRANCH:-origin/$GITHUB_BASE_REF}"
20+
else
21+
# Local development: default to origin/master
22+
BASE_BRANCH="${BASE_BRANCH:-origin/master}"
23+
fi
1624

1725
FAIL_ON_BREAKING=false
1826
TARGET_FILE=""
@@ -29,9 +37,11 @@ for arg in "$@"; do
2937
fi
3038
done
3139

40+
# Detect current branch: GitHub Actions PR branch, or local git branch
41+
CURRENT_BRANCH="${GITHUB_HEAD_REF:-$(git branch --show-current 2>/dev/null || echo "")}"
42+
3243
# If --fail-on-breaking not explicitly set, determine based on branch name
3344
if [ "$FAIL_ON_BREAKING" = false ]; then
34-
CURRENT_BRANCH=${CURRENT_BRANCH:-$(git branch --show-current 2>/dev/null || echo "")}
3545
if [[ "$CURRENT_BRANCH" == *breaking* ]]; then
3646
echo "Branch '$CURRENT_BRANCH' contains 'breaking', allowing breaking changes"
3747
FAIL_ON_BREAKING=false
@@ -135,7 +145,7 @@ for file in $files; do
135145
echo ""
136146
echo "--- Breaking changes check ---"
137147
set +e
138-
BREAKING_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" breaking --fail-on ERR --include-path-params /base/"$file" /current/"$file" 2>&1)
148+
BREAKING_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" breaking --fail-on WARN --include-path-params /base/"$file" /current/"$file" 2>&1)
139149
BREAKING_EXIT=$?
140150
set -e
141151

0 commit comments

Comments
 (0)