comment-playwright-results.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. const fs = require("fs")
  2. const path = require("path")
  3. async function commentPlaywrightResults(github, context) {
  4. const commentIdentifier = "<!-- playwright-e2e-results -->"
  5. let comment = `${commentIdentifier}\n## 🎭 Playwright E2E Test Results\n\n`
  6. const testResultsDir = "apps/playwright-e2e/test-results"
  7. const reportDir = "apps/playwright-e2e/playwright-report"
  8. if (fs.existsSync(testResultsDir) && fs.readdirSync(testResultsDir).length > 0) {
  9. let hasFailures = false
  10. try {
  11. function scanDirectory(dir) {
  12. let items
  13. try {
  14. items = fs.readdirSync(dir, { withFileTypes: true })
  15. } catch (e) {
  16. return
  17. }
  18. for (const item of items) {
  19. const fullPath = path.join(dir, item.name)
  20. if (item.isDirectory()) {
  21. // Skip vscode-logs directories which contain VSCode internal files
  22. if (item.name === 'vscode-logs') {
  23. continue
  24. }
  25. scanDirectory(fullPath)
  26. } else if (item.isFile() && item.name.endsWith(".json")) {
  27. try {
  28. const content = fs.readFileSync(fullPath, "utf8")
  29. if (content.includes('"status":"failed"')) {
  30. hasFailures = true
  31. return
  32. }
  33. } catch (e) {
  34. continue
  35. }
  36. }
  37. }
  38. }
  39. scanDirectory(testResultsDir)
  40. } catch (e) {
  41. console.log("Error checking test results:", e.message)
  42. }
  43. if (hasFailures) {
  44. comment += "❌ **Some E2E tests failed**\n\n"
  45. comment += `- Check the [test results artifact](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}) for details\n`
  46. comment += `- Review the [HTML report artifact](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}) for visual debugging\n`
  47. } else {
  48. comment += "✅ **All E2E tests passed successfully!**\n\n"
  49. comment += "The extension works correctly in a Docker environment with full end-to-end functionality.\n"
  50. }
  51. } else {
  52. comment += "⚠️ **No test results found**\n\n"
  53. comment += `The E2E tests may not have run properly. Check the [workflow logs](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}) for details.\n`
  54. }
  55. comment += "\n---\n"
  56. comment += `*Workflow: [${context.workflow}](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}) • Updated: ${new Date().toISOString()}*`
  57. const { data: comments } = await github.rest.issues.listComments({
  58. issue_number: context.issue.number,
  59. owner: context.repo.owner,
  60. repo: context.repo.repo,
  61. })
  62. const existingComment = comments.find((comment) => comment.body.includes(commentIdentifier))
  63. if (existingComment) {
  64. await github.rest.issues.updateComment({
  65. comment_id: existingComment.id,
  66. owner: context.repo.owner,
  67. repo: context.repo.repo,
  68. body: comment,
  69. })
  70. console.log("Updated existing Playwright E2E comment")
  71. } else {
  72. await github.rest.issues.createComment({
  73. issue_number: context.issue.number,
  74. owner: context.repo.owner,
  75. repo: context.repo.repo,
  76. body: comment,
  77. })
  78. console.log("Created new Playwright E2E comment")
  79. }
  80. }
  81. module.exports = { commentPlaywrightResults }