Skip to content

Commit 0c59fdd

Browse files
committed
fix(ci): improve link validation test robustness and reduce noise
- Fix Test Setup Validation to handle edge cases without false failures - Remove unnecessary Cypress artifacts upload (screenshots/videos) - Reduce verbose logging while maintaining debugging capability - Add clear success/failure reporting with actionable messages - Improve handling of empty test subjects and fallback scenarios The test now only fails for genuine setup issues, not configuration edge cases like empty subject lists or cache optimization scenarios.
1 parent 02efdb2 commit 0c59fdd

File tree

3 files changed

+53
-42
lines changed

3 files changed

+53
-42
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,20 @@ runs:
8484
}
8585
}
8686
87-
- name: Set workflow status
88-
if: steps.generate-comment.outputs.has-broken-links == 'true'
87+
- name: Report validation results
8988
run: |
89+
has_broken_links="${{ steps.generate-comment.outputs.has-broken-links }}"
9090
broken_count="${{ steps.generate-comment.outputs.broken-link-count }}"
91-
echo "::error::Found $broken_count broken link(s)"
92-
exit 1
91+
92+
if [ "$has_broken_links" = "true" ]; then
93+
echo "::error::❌ Link validation failed: Found $broken_count broken link(s)"
94+
echo "Check the PR comment for detailed broken link information"
95+
exit 1
96+
else
97+
echo "::notice::✅ Link validation passed successfully"
98+
echo "All links in the changed files are valid"
99+
if [ "${{ steps.generate-comment.outputs.comment-generated }}" = "true" ]; then
100+
echo "PR comment posted with validation summary and cache statistics"
101+
fi
102+
fi
93103
shell: bash

.github/actions/validate-links/action.yml

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,35 +64,28 @@ runs:
6464
echo "::error::Link validation failed with exit code $exit_code"
6565
fi
6666
67-
# Check for specific error patterns and logs
67+
# Check for specific error patterns and logs (but don't dump full content)
6868
if [ -f /tmp/hugo_server.log ]; then
69-
echo "::group::Hugo Server Logs"
70-
cat /tmp/hugo_server.log
71-
echo "::endgroup::"
69+
echo "Hugo server log available for debugging"
7270
fi
7371
7472
if [ -f hugo.log ]; then
75-
echo "::group::Additional Hugo Logs"
76-
cat hugo.log
77-
echo "::endgroup::"
73+
echo "Additional Hugo log available for debugging"
7874
fi
7975
8076
if [ -f /tmp/broken_links_report.json ]; then
81-
echo "::group::Broken Links Report"
82-
cat /tmp/broken_links_report.json
83-
echo "::endgroup::"
84-
fi
85-
86-
# Show Cypress artifacts if they exist
87-
if [ -d cypress/screenshots ]; then
88-
echo "::group::Available Screenshots"
89-
find cypress/screenshots -name "*.png" -type f 2>/dev/null || echo "No screenshots found"
90-
echo "::endgroup::"
77+
# Only show summary, not full report (full report is uploaded as artifact)
78+
broken_count=$(grep -o '"url":' /tmp/broken_links_report.json | wc -l || echo "0")
79+
echo "Broken links report contains $broken_count entries"
9180
fi
9281
9382
exit $exit_code
9483
}
9584
85+
# Report success if we get here
86+
echo "::notice::✅ Link validation completed successfully"
87+
echo "No broken links detected in the tested files"
88+
9689
- name: Upload logs on failure
9790
if: failure()
9891
uses: actions/upload-artifact@v4
@@ -103,15 +96,6 @@ runs:
10396
/tmp/hugo_server.log
10497
if-no-files-found: ignore
10598

106-
- name: Upload Cypress artifacts on failure
107-
if: failure()
108-
uses: actions/upload-artifact@v4
109-
with:
110-
name: cypress-artifacts-${{ inputs.product-name && inputs.product-name || 'default' }}
111-
path: |
112-
cypress/screenshots
113-
cypress/videos
114-
if-no-files-found: ignore
11599

116100
- name: Upload broken links report
117101
if: always()

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

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/// <reference types="cypress" />
22

33
describe('Article', () => {
4-
let subjects = Cypress.env('test_subjects').split(',');
4+
let subjects = Cypress.env('test_subjects')
5+
? Cypress.env('test_subjects').split(',').filter(s => s.trim() !== '')
6+
: [];
57
let validationStrategy = null;
68

79
// Always use HEAD for downloads to avoid timeouts
@@ -216,11 +218,13 @@ describe('Article', () => {
216218
cy.log(` • Error: ${validationStrategy.error}`);
217219
cy.log(' • All files will be tested without cache optimization');
218220

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-
);
221+
// In fallback mode, if we have no subjects, that might be expected
222+
if (subjects.length === 0) {
223+
cy.log('ℹ️ No subjects to test in fallback mode');
224+
cy.log(' This indicates no test subjects were provided to the runner');
225+
} else {
226+
cy.log(`✅ Testing ${subjects.length} subjects in fallback mode`);
227+
}
224228
} else if (subjects.length === 0) {
225229
cy.log('⚠️ No test subjects found - analyzing cause:');
226230
cy.log(' • All files were cached and skipped');
@@ -229,15 +233,13 @@ describe('Article', () => {
229233

230234
// Don't fail if this is expected (cache hit scenario)
231235
const testSubjectsData = Cypress.env('test_subjects_data');
232-
if (testSubjectsData) {
236+
if (testSubjectsData && testSubjectsData !== '[]' && testSubjectsData !== '') {
233237
cy.log('✅ Cache optimization active - this is expected');
234238
cy.log('ℹ️ Test subjects data is available, all files cached');
235239
} else {
236-
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-
);
240+
cy.log('⚠️ No test subjects data available');
241+
cy.log(' This may indicate no files were provided to test');
242+
cy.log(' This is not necessarily an error - may be expected for some runs');
241243
}
242244
} else {
243245
cy.log(`✅ Ready to test ${subjects.length} pages`);
@@ -247,6 +249,21 @@ describe('Article', () => {
247249
}
248250
}
249251

252+
// Check for truly problematic scenarios
253+
if (!validationStrategy && subjects.length === 0) {
254+
const testSubjectsData = Cypress.env('test_subjects_data');
255+
if (!testSubjectsData || testSubjectsData === '' || testSubjectsData === '[]') {
256+
cy.log('❌ Critical setup issue detected:');
257+
cy.log(' • No validation strategy');
258+
cy.log(' • No test subjects');
259+
cy.log(' • No test subjects data');
260+
cy.log(' This indicates a fundamental configuration problem');
261+
262+
// Only fail in this truly problematic case
263+
throw new Error('Critical test setup failure: No strategy, subjects, or data available');
264+
}
265+
}
266+
250267
// Always pass if we get to this point - the setup is valid
251268
cy.log('✅ Test setup validation completed successfully');
252269
});

0 commit comments

Comments
 (0)