From e093f121f003e3830260b3874388f62414de8adf Mon Sep 17 00:00:00 2001 From: Hongming Wang Date: Fri, 17 Apr 2026 20:23:28 -0700 Subject: [PATCH] fix(ci): use github.event.before for push diff, fetch-depth 0 HEAD~1 doesn't work for merge commits. Use github.event.before (the previous main tip) for push events and github.event.pull_request.base.sha for PRs. fetch-depth: 0 ensures both SHAs are available. Fallback: if BASE is empty (new branch), run all jobs. Co-Authored-By: Claude Opus 4.6 (1M context) --- .github/workflows/ci.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23fb0d4b..73e5a7a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,10 +21,25 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 2 + fetch-depth: 0 - id: check run: | - DIFF=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo ".github/workflows/ci.yml") + # For push events: diff against previous commit (handles merge commits) + # For PR events: diff against the base branch + if [ "${{ github.event_name }}" = "pull_request" ]; then + BASE="${{ github.event.pull_request.base.sha }}" + else + BASE="${{ github.event.before }}" + fi + # Fallback: if BASE is empty or all zeros (new branch), run everything + if [ -z "$BASE" ] || echo "$BASE" | grep -qE '^0+$'; then + echo "platform=true" >> "$GITHUB_OUTPUT" + echo "canvas=true" >> "$GITHUB_OUTPUT" + echo "python=true" >> "$GITHUB_OUTPUT" + echo "scripts=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + DIFF=$(git diff --name-only "$BASE" HEAD 2>/dev/null || echo ".github/workflows/ci.yml") echo "platform=$(echo "$DIFF" | grep -qE '^platform/|^\.github/workflows/ci\.yml$' && echo true || echo false)" >> "$GITHUB_OUTPUT" echo "canvas=$(echo "$DIFF" | grep -qE '^canvas/|^\.github/workflows/ci\.yml$' && echo true || echo false)" >> "$GITHUB_OUTPUT" echo "python=$(echo "$DIFF" | grep -qE '^workspace-template/|^\.github/workflows/ci\.yml$' && echo true || echo false)" >> "$GITHUB_OUTPUT"