Skip to content

Commit 02efdb2

Browse files
committed
fix(ci): resolve link validation workflow false failures
- Fix GitHub Actions exit logic to only fail when broken links exist - Improve Cypress test error handling with robust fallback mechanism - Enhance Test Setup Validation to handle cache scenarios correctly The workflow was incorrectly failing when generating success comments with cache statistics, treating any comment generation as broken links. Now properly distinguishes between success messages and actual failures.
1 parent a087906 commit 02efdb2

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

.github/actions/report-broken-links/action.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,18 @@ runs:
4444
4545
# Check if comment file was created and has content
4646
if [[ -f comment.md && -s comment.md ]]; then
47-
echo "has-broken-links=true" >> $GITHUB_OUTPUT
47+
echo "comment-generated=true" >> $GITHUB_OUTPUT
4848
4949
# Count broken links by parsing the comment
5050
broken_count=$(grep -o "Found [0-9]* broken link" comment.md | grep -o "[0-9]*" || echo "0")
5151
echo "broken-link-count=$broken_count" >> $GITHUB_OUTPUT
52-
echo "comment-generated=true" >> $GITHUB_OUTPUT
52+
53+
# Check if there are actually broken links (not just a success comment)
54+
if [[ "$broken_count" -gt 0 ]]; then
55+
echo "has-broken-links=true" >> $GITHUB_OUTPUT
56+
else
57+
echo "has-broken-links=false" >> $GITHUB_OUTPUT
58+
fi
5359
else
5460
echo "has-broken-links=false" >> $GITHUB_OUTPUT
5561
echo "broken-link-count=0" >> $GITHUB_OUTPUT

broken_links_report.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

cypress/e2e/content/article-links.cy.js

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,25 @@ describe('Article', () => {
7676
);
7777
cy.log(' Check that all files exist and are readable');
7878

79-
Cypress.fail(
80-
`Incremental validation task failed: ${error.message}. Check logs for details.`
79+
// Instead of failing completely, fall back to testing all provided subjects
80+
cy.log(
81+
'🔄 Falling back to test all provided subjects without cache optimization'
8182
);
83+
84+
// Reset validation strategy to indicate fallback mode
85+
validationStrategy = {
86+
fallback: true,
87+
error: error.message,
88+
unchanged: [],
89+
changed: sourceFilePaths.map((filePath) => ({
90+
filePath,
91+
error: 'fallback',
92+
})),
93+
total: sourceFilePaths.length,
94+
};
95+
96+
// Keep original subjects for testing (should come from test_subjects env var)
97+
cy.log(`📋 Testing ${subjects.length} pages in fallback mode`);
8298
});
8399
});
84100

@@ -194,20 +210,34 @@ describe('Article', () => {
194210
cy.log(` • Test subjects count: ${subjects.length}`);
195211
cy.log(` • Validation strategy: ${validationStrategy || 'Not set'}`);
196212

197-
if (subjects.length === 0) {
198-
cy.log('⚠️ No test subjects found - this may indicate:');
213+
// Check if we're in fallback mode due to cache system issues
214+
if (validationStrategy && validationStrategy.fallback) {
215+
cy.log('⚠️ Running in fallback mode due to cache system error');
216+
cy.log(` • Error: ${validationStrategy.error}`);
217+
cy.log(' • All files will be tested without cache optimization');
218+
219+
// Ensure we have subjects to test in fallback mode
220+
expect(subjects.length).to.be.greaterThan(
221+
0,
222+
'Should have test subjects in fallback mode'
223+
);
224+
} else if (subjects.length === 0) {
225+
cy.log('⚠️ No test subjects found - analyzing cause:');
199226
cy.log(' • All files were cached and skipped');
200227
cy.log(' • No files matched the test criteria');
201228
cy.log(' • File mapping failed during setup');
202229

203230
// Don't fail if this is expected (cache hit scenario)
204231
const testSubjectsData = Cypress.env('test_subjects_data');
205232
if (testSubjectsData) {
206-
cy.log(
207-
'ℹ️ Test subjects data is available, cache optimization likely active'
208-
);
233+
cy.log('✅ Cache optimization active - this is expected');
234+
cy.log('ℹ️ Test subjects data is available, all files cached');
209235
} else {
210236
cy.log('❌ No test subjects data available - potential setup issue');
237+
// Only fail if we have no data and no subjects - indicates a real problem
238+
expect(testSubjectsData).to.not.be.empty(
239+
'Should have test subjects data when no subjects to test'
240+
);
211241
}
212242
} else {
213243
cy.log(`✅ Ready to test ${subjects.length} pages`);
@@ -216,6 +246,9 @@ describe('Article', () => {
216246
cy.log(` ... and ${subjects.length - 5} more pages`);
217247
}
218248
}
249+
250+
// Always pass if we get to this point - the setup is valid
251+
cy.log('✅ Test setup validation completed successfully');
219252
});
220253

221254
subjects.forEach((subject) => {

0 commit comments

Comments
 (0)