diff --git a/.build/generate-icons-comment.mjs b/.build/generate-icons-comment.mjs index db7a7ac53..5c26730c9 100644 --- a/.build/generate-icons-comment.mjs +++ b/.build/generate-icons-comment.mjs @@ -2,10 +2,12 @@ import { execSync } from 'child_process' import { basename, join } from 'path' import { ICONS_SRC_DIR, parseMatter } from './helpers.mjs' -// Check icon files added relative to main branch (for PR) +// Check icon files added relative to base branch (for PR) function getAddedIconsFromMain() { try { - const output = execSync('git diff origin/main...HEAD --name-status', { encoding: 'utf-8' }) + // Use BASE_SHA or BASE_REF from environment, fallback to origin/main + const baseRef = process.env.BASE_SHA || process.env.BASE_REF || 'origin/main' + const output = execSync(`git diff ${baseRef}...HEAD --name-status`, { encoding: 'utf-8' }) const addedIcons = [] output.split('\n').forEach(line => { @@ -21,7 +23,7 @@ function getAddedIconsFromMain() { return addedIcons } catch (error) { - // Fallback: check relative to HEAD if origin/main doesn't exist + // Fallback: check relative to HEAD if base ref doesn't exist try { const output = execSync('git diff --diff-filter=A --name-only', { encoding: 'utf-8' }) const addedIcons = [] diff --git a/.build/validate-icons.mjs b/.build/validate-icons.mjs index 3d060ad18..c557f8513 100644 --- a/.build/validate-icons.mjs +++ b/.build/validate-icons.mjs @@ -25,7 +25,9 @@ const getIconName = (icon) => { function getAddedIconsFromMain() { try { - const output = execSync('git diff origin/main...HEAD --name-status', { encoding: 'utf-8' }) + // Use BASE_SHA or BASE_REF from environment, fallback to origin/main + const baseRef = process.env.BASE_SHA || process.env.BASE_REF || 'origin/main' + const output = execSync(`git diff ${baseRef}...HEAD --name-status`, { encoding: 'utf-8' }) const addedIcons = [] output.split('\n').forEach(line => { diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml index a802b439e..a471aec76 100644 --- a/.github/workflows/validate-pr.yml +++ b/.github/workflows/validate-pr.yml @@ -16,6 +16,16 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} + + - name: Set base branch + run: | + BASE_REF="${{ github.event.pull_request.base.ref }}" + BASE_SHA="${{ github.event.pull_request.base.sha }}" + echo "BASE_REF=${BASE_REF}" >> $GITHUB_ENV + echo "BASE_SHA=${BASE_SHA}" >> $GITHUB_ENV + # Fetch base branch to ensure it's available + git fetch origin ${BASE_REF}:${BASE_REF} || true - name: Add in progress comment id: add-in-progress-comment @@ -56,6 +66,9 @@ jobs: - name: Validate icons id: validate + env: + BASE_REF: ${{ env.BASE_REF }} + BASE_SHA: ${{ env.BASE_SHA }} run: pnpm run --silent validate > ./comment-markup.md continue-on-error: true @@ -68,6 +81,9 @@ jobs: - name: Generate icons comment id: generate-icons-comment + env: + BASE_REF: ${{ env.BASE_REF }} + BASE_SHA: ${{ env.BASE_SHA }} run: pnpm run --silent generate-icons-comment > ./comment-icons.md || true continue-on-error: true