diff --git a/.github/workflows/vercel-preview-guard.yml b/.github/workflows/vercel-preview-guard.yml index 21c95ebc0..c028222bd 100644 --- a/.github/workflows/vercel-preview-guard.yml +++ b/.github/workflows/vercel-preview-guard.yml @@ -15,15 +15,35 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 26 permissions: + contents: read deployments: read statuses: read checks: read outputs: preview_url: ${{ steps.wait.outputs.preview_url }} + frontend: ${{ steps.scope.outputs.frontend }} steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 + with: + fetch-depth: 0 + + - name: Check frontend scope + id: scope + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + MERGE_BASE=$(git merge-base "$BASE_SHA" "$HEAD_SHA") + DIFF=$(git diff --name-only "$MERGE_BASE" "$HEAD_SHA" -- frontend/) + if [ -n "$DIFF" ]; then + echo "frontend=true" >> "$GITHUB_OUTPUT" + else + echo "frontend=false" >> "$GITHUB_OUTPUT" + fi + - name: Wait for the regengine preview id: wait - if: ${{ !startsWith(github.head_ref, 'dependabot/') }} + if: ${{ !startsWith(github.head_ref, 'dependabot/') && steps.scope.outputs.frontend == 'true' }} uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 env: HEAD_SHA: ${{ github.event.pull_request.head.sha }} @@ -183,9 +203,14 @@ jobs: } throw new Error(`No ready regengine Vercel preview for ${sha} after 25 minutes`); + - name: Preview skipped + if: ${{ steps.scope.outputs.frontend == 'false' }} + run: echo "No frontend changes; Vercel preview intentionally skipped by ignore step." + access-link: name: Preview Access Link needs: preview + if: needs.preview.outputs.frontend == 'true' && needs.preview.outputs.preview_url != '' runs-on: ubuntu-latest timeout-minutes: 5 permissions: diff --git a/frontend/scripts/vercel-ignore-build.sh b/frontend/scripts/vercel-ignore-build.sh index 7ce3c5bef..9acb6a95d 100644 --- a/frontend/scripts/vercel-ignore-build.sh +++ b/frontend/scripts/vercel-ignore-build.sh @@ -9,21 +9,13 @@ fi BASE="" -if [ -n "${VERCEL_GIT_PREVIOUS_SHA:-}" ]; then - if git cat-file -e "${VERCEL_GIT_PREVIOUS_SHA}^{commit}" 2>/dev/null; then - BASE="$VERCEL_GIT_PREVIOUS_SHA" - fi -fi - +git fetch --quiet --depth=200 origin main 2>/dev/null || true +BASE="$(git merge-base HEAD FETCH_HEAD 2>/dev/null || true)" if [ -z "$BASE" ]; then - git fetch --quiet --depth=100 origin main 2>/dev/null || true - BASE="$(git merge-base HEAD FETCH_HEAD 2>/dev/null || true)" - if [ -z "$BASE" ]; then - if git cat-file -e origin/main^{commit} 2>/dev/null; then - BASE="origin/main" - elif git rev-parse --verify origin/main >/dev/null 2>&1; then - BASE="origin/main" - fi + if git cat-file -e origin/main^{commit} 2>/dev/null; then + BASE="origin/main" + elif git rev-parse --verify origin/main >/dev/null 2>&1; then + BASE="origin/main" fi fi