Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 65 additions & 9 deletions apps/website/ignore_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,79 @@ const { execSync } = require('child_process');

// Check if there are changes in the website directory
function hasWebsiteChanges() {
if (process.env.FORCE_BUILD) {
return false;
}

try {
// Get the list of changed files in the current commit compared to the base branch
const baseBranch = process.env.BASE_BRANCH || 'main';
const changedFiles = execSync(
`git diff --name-only origin/${baseBranch}...HEAD`,
{ encoding: 'utf8' },
);
let changedFiles = '';

// Try multiple strategies to detect changes
const strategies = [
// Strategy 1: Compare with Netlify's CACHED_COMMIT_REF if available
() => {
if (process.env.CACHED_COMMIT_REF) {
return execSync(
`git diff --name-only ${process.env.CACHED_COMMIT_REF}...HEAD`,
{ encoding: 'utf8' }
);
}
return null;
},

// Strategy 2: Use git diff with HEAD~1 (compare with previous commit)
() => {
return execSync('git diff --name-only HEAD~1...HEAD', { encoding: 'utf8' });
},

// Strategy 3: Check git status for uncommitted changes
() => {
return execSync('git status --porcelain', { encoding: 'utf8' });
},

// Strategy 4: Fetch and compare with origin/main
() => {
execSync('git fetch origin main --depth=1', { stdio: 'ignore' });
return execSync('git diff --name-only origin/main...HEAD', { encoding: 'utf8' });
}
];

// Try each strategy until one works
for (const strategy of strategies) {
try {
const result = strategy();
if (result !== null) {
changedFiles = result;
break;
}
} catch (e) {
// Continue to next strategy
continue;
}
}

if (!changedFiles) {
console.log('Could not determine changes using any strategy, allowing build to proceed');
return true;
}

console.log('Changed files detected:', changedFiles.trim());

// Check if any of the changed files are in the website directory
const websiteChanges = changedFiles
.split('\n')
.filter((file) => file.trim() && file.startsWith('apps/website/'));
.filter((file) => {
const trimmedFile = file.trim();
// Handle git status format (files may have status prefixes like M, A, D)
const cleanFile = trimmedFile.replace(/^[MADRCU?!\s]+/, '');
return cleanFile && cleanFile.startsWith('apps/website/');
});

console.log('Website changes:', websiteChanges);
return websiteChanges.length > 0;
} catch (error) {
// If we can't determine changes, allow the build to proceed
console.log('Could not determine changes, allowing build to proceed');
console.log('Error determining changes:', error.message);
console.log('Allowing build to proceed due to error');
return true;
}
}
Expand Down