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.
pull/6261/head
Jason Stirnaman 2025-07-28 23:05:02 -05:00
parent 02efdb262b
commit 0c59fdd7c0
3 changed files with 53 additions and 42 deletions

View File

@ -84,10 +84,20 @@ runs:
} }
} }
- name: Set workflow status - name: Report validation results
if: steps.generate-comment.outputs.has-broken-links == 'true'
run: | run: |
has_broken_links="${{ steps.generate-comment.outputs.has-broken-links }}"
broken_count="${{ steps.generate-comment.outputs.broken-link-count }}" broken_count="${{ steps.generate-comment.outputs.broken-link-count }}"
echo "::error::Found $broken_count broken link(s)"
exit 1 if [ "$has_broken_links" = "true" ]; then
echo "::error::❌ Link validation failed: Found $broken_count broken link(s)"
echo "Check the PR comment for detailed broken link information"
exit 1
else
echo "::notice::✅ Link validation passed successfully"
echo "All links in the changed files are valid"
if [ "${{ steps.generate-comment.outputs.comment-generated }}" = "true" ]; then
echo "PR comment posted with validation summary and cache statistics"
fi
fi
shell: bash shell: bash

View File

@ -64,35 +64,28 @@ runs:
echo "::error::Link validation failed with exit code $exit_code" echo "::error::Link validation failed with exit code $exit_code"
fi fi
# Check for specific error patterns and logs # Check for specific error patterns and logs (but don't dump full content)
if [ -f /tmp/hugo_server.log ]; then if [ -f /tmp/hugo_server.log ]; then
echo "::group::Hugo Server Logs" echo "Hugo server log available for debugging"
cat /tmp/hugo_server.log
echo "::endgroup::"
fi fi
if [ -f hugo.log ]; then if [ -f hugo.log ]; then
echo "::group::Additional Hugo Logs" echo "Additional Hugo log available for debugging"
cat hugo.log
echo "::endgroup::"
fi fi
if [ -f /tmp/broken_links_report.json ]; then if [ -f /tmp/broken_links_report.json ]; then
echo "::group::Broken Links Report" # Only show summary, not full report (full report is uploaded as artifact)
cat /tmp/broken_links_report.json broken_count=$(grep -o '"url":' /tmp/broken_links_report.json | wc -l || echo "0")
echo "::endgroup::" echo "Broken links report contains $broken_count entries"
fi
# Show Cypress artifacts if they exist
if [ -d cypress/screenshots ]; then
echo "::group::Available Screenshots"
find cypress/screenshots -name "*.png" -type f 2>/dev/null || echo "No screenshots found"
echo "::endgroup::"
fi fi
exit $exit_code exit $exit_code
} }
# Report success if we get here
echo "::notice::✅ Link validation completed successfully"
echo "No broken links detected in the tested files"
- name: Upload logs on failure - name: Upload logs on failure
if: failure() if: failure()
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
@ -103,15 +96,6 @@ runs:
/tmp/hugo_server.log /tmp/hugo_server.log
if-no-files-found: ignore if-no-files-found: ignore
- name: Upload Cypress artifacts on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: cypress-artifacts-${{ inputs.product-name && inputs.product-name || 'default' }}
path: |
cypress/screenshots
cypress/videos
if-no-files-found: ignore
- name: Upload broken links report - name: Upload broken links report
if: always() if: always()

View File

@ -1,7 +1,9 @@
/// <reference types="cypress" /> /// <reference types="cypress" />
describe('Article', () => { describe('Article', () => {
let subjects = Cypress.env('test_subjects').split(','); let subjects = Cypress.env('test_subjects')
? Cypress.env('test_subjects').split(',').filter(s => s.trim() !== '')
: [];
let validationStrategy = null; let validationStrategy = null;
// Always use HEAD for downloads to avoid timeouts // Always use HEAD for downloads to avoid timeouts
@ -216,11 +218,13 @@ describe('Article', () => {
cy.log(` • Error: ${validationStrategy.error}`); cy.log(` • Error: ${validationStrategy.error}`);
cy.log(' • All files will be tested without cache optimization'); cy.log(' • All files will be tested without cache optimization');
// Ensure we have subjects to test in fallback mode // In fallback mode, if we have no subjects, that might be expected
expect(subjects.length).to.be.greaterThan( if (subjects.length === 0) {
0, cy.log(' No subjects to test in fallback mode');
'Should have test subjects in fallback mode' cy.log(' This indicates no test subjects were provided to the runner');
); } else {
cy.log(`✅ Testing ${subjects.length} subjects in fallback mode`);
}
} else if (subjects.length === 0) { } else if (subjects.length === 0) {
cy.log('⚠️ No test subjects found - analyzing cause:'); cy.log('⚠️ No test subjects found - analyzing cause:');
cy.log(' • All files were cached and skipped'); cy.log(' • All files were cached and skipped');
@ -229,15 +233,13 @@ describe('Article', () => {
// Don't fail if this is expected (cache hit scenario) // Don't fail if this is expected (cache hit scenario)
const testSubjectsData = Cypress.env('test_subjects_data'); const testSubjectsData = Cypress.env('test_subjects_data');
if (testSubjectsData) { if (testSubjectsData && testSubjectsData !== '[]' && testSubjectsData !== '') {
cy.log('✅ Cache optimization active - this is expected'); cy.log('✅ Cache optimization active - this is expected');
cy.log(' Test subjects data is available, all files cached'); cy.log(' Test subjects data is available, all files cached');
} else { } else {
cy.log('❌ No test subjects data available - potential setup issue'); cy.log('⚠️ No test subjects data available');
// Only fail if we have no data and no subjects - indicates a real problem cy.log(' This may indicate no files were provided to test');
expect(testSubjectsData).to.not.be.empty( cy.log(' This is not necessarily an error - may be expected for some runs');
'Should have test subjects data when no subjects to test'
);
} }
} else { } else {
cy.log(`✅ Ready to test ${subjects.length} pages`); cy.log(`✅ Ready to test ${subjects.length} pages`);
@ -247,6 +249,21 @@ describe('Article', () => {
} }
} }
// Check for truly problematic scenarios
if (!validationStrategy && subjects.length === 0) {
const testSubjectsData = Cypress.env('test_subjects_data');
if (!testSubjectsData || testSubjectsData === '' || testSubjectsData === '[]') {
cy.log('❌ Critical setup issue detected:');
cy.log(' • No validation strategy');
cy.log(' • No test subjects');
cy.log(' • No test subjects data');
cy.log(' This indicates a fundamental configuration problem');
// Only fail in this truly problematic case
throw new Error('Critical test setup failure: No strategy, subjects, or data available');
}
}
// Always pass if we get to this point - the setup is valid // Always pass if we get to this point - the setup is valid
cy.log('✅ Test setup validation completed successfully'); cy.log('✅ Test setup validation completed successfully');
}); });