Skip to content

Commit 49c72d6

Browse files
authored
Merge pull request #437 from underctrl-io/fix-netlify-build
fix: use alternative strategies for netlify build script
2 parents 419ac97 + 5e63d4a commit 49c72d6

File tree

1 file changed

+65
-9
lines changed

1 file changed

+65
-9
lines changed

apps/website/ignore_build.js

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,79 @@ const { execSync } = require('child_process');
22

33
// Check if there are changes in the website directory
44
function hasWebsiteChanges() {
5+
if (process.env.FORCE_BUILD) {
6+
return false;
7+
}
8+
59
try {
6-
// Get the list of changed files in the current commit compared to the base branch
7-
const baseBranch = process.env.BASE_BRANCH || 'main';
8-
const changedFiles = execSync(
9-
`git diff --name-only origin/${baseBranch}...HEAD`,
10-
{ encoding: 'utf8' },
11-
);
10+
let changedFiles = '';
11+
12+
// Try multiple strategies to detect changes
13+
const strategies = [
14+
// Strategy 1: Compare with Netlify's CACHED_COMMIT_REF if available
15+
() => {
16+
if (process.env.CACHED_COMMIT_REF) {
17+
return execSync(
18+
`git diff --name-only ${process.env.CACHED_COMMIT_REF}...HEAD`,
19+
{ encoding: 'utf8' }
20+
);
21+
}
22+
return null;
23+
},
24+
25+
// Strategy 2: Use git diff with HEAD~1 (compare with previous commit)
26+
() => {
27+
return execSync('git diff --name-only HEAD~1...HEAD', { encoding: 'utf8' });
28+
},
29+
30+
// Strategy 3: Check git status for uncommitted changes
31+
() => {
32+
return execSync('git status --porcelain', { encoding: 'utf8' });
33+
},
34+
35+
// Strategy 4: Fetch and compare with origin/main
36+
() => {
37+
execSync('git fetch origin main --depth=1', { stdio: 'ignore' });
38+
return execSync('git diff --name-only origin/main...HEAD', { encoding: 'utf8' });
39+
}
40+
];
41+
42+
// Try each strategy until one works
43+
for (const strategy of strategies) {
44+
try {
45+
const result = strategy();
46+
if (result !== null) {
47+
changedFiles = result;
48+
break;
49+
}
50+
} catch (e) {
51+
// Continue to next strategy
52+
continue;
53+
}
54+
}
55+
56+
if (!changedFiles) {
57+
console.log('Could not determine changes using any strategy, allowing build to proceed');
58+
return true;
59+
}
60+
61+
console.log('Changed files detected:', changedFiles.trim());
1262

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

73+
console.log('Website changes:', websiteChanges);
1874
return websiteChanges.length > 0;
1975
} catch (error) {
20-
// If we can't determine changes, allow the build to proceed
21-
console.log('Could not determine changes, allowing build to proceed');
76+
console.log('Error determining changes:', error.message);
77+
console.log('Allowing build to proceed due to error');
2278
return true;
2379
}
2480
}

0 commit comments

Comments
 (0)