Skip to content

Commit

Permalink
feature/IVYPORTAL-17377-Create-pipeline-to-run-Lighthouse-report
Browse files Browse the repository at this point in the history
  • Loading branch information
nhthinh-axonivy committed Dec 27, 2024
1 parent 4f8dc88 commit 80b2680
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/lighthouse-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,14 @@ jobs:
- name: Generate HTML Summary
run: |
cd AxonIvyPortal/portal-selenium-test/lighthouse
# Debug information
echo "Current directory: $(pwd)"
echo "Listing directory contents:"
ls -la
if [ -f "lighthouse-report.html" ]; then
echo "Found HTML report"
node -e "
const core = require('@actions/core');
const fs = require('fs');
Expand All @@ -200,7 +207,6 @@ jobs:
.addHeading('🚦 Lighthouse Audit Results')
.addRaw('## Performance Scores\n\n');
// Add scores from JSON
Object.entries(results.categories).forEach(([key, value]) => {
summary.addRaw(`### ${value.title}\n📊 Score: ${Math.floor(value.score * 100)}%\n\n`);
});
Expand All @@ -213,13 +219,17 @@ jobs:
'/actions/runs/' +
process.env.GITHUB_RUN_ID)
.write();
console.log('Summary generated successfully');
} catch (error) {
console.error('Error generating summary:', error);
process.exit(1);
}
"
else
echo "Lighthouse report file not found"
echo "Error: Lighthouse report file not found in $(pwd)"
echo "Directory contents:"
ls -la
exit 1
fi
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,24 @@ const __dirname = dirname(__filename);

// Save reports
try {
const reportsDir = "lighthouse-reports";
const scriptDir = dirname(fileURLToPath(import.meta.url));
const reportsDir = path.join(scriptDir, "lighthouse-reports");

// Ensure reports directory exists
if (!fs.existsSync(reportsDir)) {
fs.mkdirSync(reportsDir, { recursive: true });
}

if (typeof runnerResult.report === "string") {
// Save HTML report
const htmlPath = path.join(process.cwd(), "lighthouse-report.html");
// Save HTML report in the same directory as the script
const htmlPath = path.join(scriptDir, "lighthouse-report.html");
fs.writeFileSync(htmlPath, runnerResult.report);
console.log("HTML report saved successfully to:", htmlPath);
}

if (runnerResult.lhr) {
// Save JSON report
const jsonPath = path.join(process.cwd(), reportsDir, "report.json");
// Save JSON report in the reports directory
const jsonPath = path.join(reportsDir, "report.json");
fs.writeFileSync(jsonPath, JSON.stringify(runnerResult.lhr, null, 2));
console.log("JSON report saved successfully to:", jsonPath);
}
Expand Down

0 comments on commit 80b2680

Please sign in to comment.