Update icon validation scripts to use dynamic base branch reference for improved accuracy in PR icon checks
This commit is contained in:
parent
39b30d7109
commit
69e0b696fb
|
|
@ -2,10 +2,12 @@ import { execSync } from 'child_process'
|
||||||
import { basename, join } from 'path'
|
import { basename, join } from 'path'
|
||||||
import { ICONS_SRC_DIR, parseMatter } from './helpers.mjs'
|
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() {
|
function getAddedIconsFromMain() {
|
||||||
try {
|
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 = []
|
const addedIcons = []
|
||||||
|
|
||||||
output.split('\n').forEach(line => {
|
output.split('\n').forEach(line => {
|
||||||
|
|
@ -21,7 +23,7 @@ function getAddedIconsFromMain() {
|
||||||
|
|
||||||
return addedIcons
|
return addedIcons
|
||||||
} catch (error) {
|
} 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 {
|
try {
|
||||||
const output = execSync('git diff --diff-filter=A --name-only', { encoding: 'utf-8' })
|
const output = execSync('git diff --diff-filter=A --name-only', { encoding: 'utf-8' })
|
||||||
const addedIcons = []
|
const addedIcons = []
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,9 @@ const getIconName = (icon) => {
|
||||||
|
|
||||||
function getAddedIconsFromMain() {
|
function getAddedIconsFromMain() {
|
||||||
try {
|
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 = []
|
const addedIcons = []
|
||||||
|
|
||||||
output.split('\n').forEach(line => {
|
output.split('\n').forEach(line => {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,16 @@ jobs:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
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
|
- name: Add in progress comment
|
||||||
id: add-in-progress-comment
|
id: add-in-progress-comment
|
||||||
|
|
@ -56,6 +66,9 @@ jobs:
|
||||||
|
|
||||||
- name: Validate icons
|
- name: Validate icons
|
||||||
id: validate
|
id: validate
|
||||||
|
env:
|
||||||
|
BASE_REF: ${{ env.BASE_REF }}
|
||||||
|
BASE_SHA: ${{ env.BASE_SHA }}
|
||||||
run: pnpm run --silent validate > ./comment-markup.md
|
run: pnpm run --silent validate > ./comment-markup.md
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
|
|
@ -68,6 +81,9 @@ jobs:
|
||||||
|
|
||||||
- name: Generate icons comment
|
- name: Generate icons comment
|
||||||
id: 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
|
run: pnpm run --silent generate-icons-comment > ./comment-icons.md || true
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue