|
| 1 | +name: Test with Detailed Comments |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [ main, develop ] |
| 6 | + |
| 7 | +jobs: |
| 8 | + test: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: read |
| 12 | + pull-requests: write |
| 13 | + checks: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Setup Node.js |
| 20 | + uses: actions/setup-node@v4 |
| 21 | + with: |
| 22 | + node-version: '20.x' |
| 23 | + cache: 'npm' |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: npm ci |
| 27 | + |
| 28 | + - name: Run linting with output capture |
| 29 | + id: lint |
| 30 | + run: | |
| 31 | + echo "lint_output<<EOF" >> $GITHUB_OUTPUT |
| 32 | + npm run lint 2>&1 || echo "LINT_FAILED=true" >> $GITHUB_OUTPUT |
| 33 | + echo "EOF" >> $GITHUB_OUTPUT |
| 34 | + continue-on-error: true |
| 35 | + |
| 36 | + - name: Run tests with output capture |
| 37 | + id: test |
| 38 | + run: | |
| 39 | + echo "test_output<<EOF" >> $GITHUB_OUTPUT |
| 40 | + npx vitest run --reporter=verbose 2>&1 | tee test_output.txt |
| 41 | + if [ ${PIPESTATUS[0]} -ne 0 ]; then |
| 42 | + echo "TEST_FAILED=true" >> $GITHUB_OUTPUT |
| 43 | + echo "$(cat test_output.txt)" >> $GITHUB_OUTPUT |
| 44 | + else |
| 45 | + echo "TEST_PASSED=true" >> $GITHUB_OUTPUT |
| 46 | + echo "$(cat test_output.txt | tail -10)" >> $GITHUB_OUTPUT |
| 47 | + fi |
| 48 | + echo "EOF" >> $GITHUB_OUTPUT |
| 49 | + continue-on-error: true |
| 50 | + |
| 51 | + - name: Run build with output capture |
| 52 | + id: build |
| 53 | + run: | |
| 54 | + echo "build_output<<EOF" >> $GITHUB_OUTPUT |
| 55 | + npm run build 2>&1 || echo "BUILD_FAILED=true" >> $GITHUB_OUTPUT |
| 56 | + echo "EOF" >> $GITHUB_OUTPUT |
| 57 | + continue-on-error: true |
| 58 | + |
| 59 | + - name: Comment PR with detailed results |
| 60 | + uses: thollander/actions-comment-pull-request@v2 |
| 61 | + with: |
| 62 | + message: | |
| 63 | + ## 🔍 Pull Request Detailed Check Results |
| 64 | + |
| 65 | + ### Linting Results |
| 66 | + ${{ env.LINT_FAILED == 'true' && '❌ **Linting Failed**' || '✅ **Linting Passed**' }} |
| 67 | + |
| 68 | + ${{ env.LINT_FAILED == 'true' && format('``` |
| 69 | + {0} |
| 70 | + ```', steps.lint.outputs.lint_output) || '_No linting issues found._' }} |
| 71 | + |
| 72 | + ### Test Results |
| 73 | + ${{ env.TEST_FAILED == 'true' && '❌ **Tests Failed**' || '✅ **Tests Passed**' }} |
| 74 | + |
| 75 | + <details> |
| 76 | + <summary>Click to see test output</summary> |
| 77 | + |
| 78 | + ``` |
| 79 | + ${{ steps.test.outputs.test_output }} |
| 80 | + ``` |
| 81 | + </details> |
| 82 | + |
| 83 | + ### Build Results |
| 84 | + ${{ env.BUILD_FAILED == 'true' && '❌ **Build Failed**' || '✅ **Build Passed**' }} |
| 85 | + |
| 86 | + ${{ env.BUILD_FAILED == 'true' && format('``` |
| 87 | + {0} |
| 88 | + ```', steps.build.outputs.build_output) || '_Build completed successfully._' }} |
| 89 | + |
| 90 | + --- |
| 91 | + |
| 92 | + ${{ (env.LINT_FAILED == 'true' || env.TEST_FAILED == 'true' || env.BUILD_FAILED == 'true') && '### ⚠️ Action Required |
| 93 | + Please address the failing checks above before merging this PR.' || '### 🎉 All Checks Passed! |
| 94 | + This PR is ready to be reviewed and merged.' }} |
| 95 | + |
| 96 | + comment_tag: detailed-pr-check |
| 97 | + |
| 98 | + - name: Set environment variables for next steps |
| 99 | + run: | |
| 100 | + echo "LINT_FAILED=${{ steps.lint.outputs.LINT_FAILED }}" >> $GITHUB_ENV |
| 101 | + echo "TEST_FAILED=${{ steps.test.outputs.TEST_FAILED }}" >> $GITHUB_ENV |
| 102 | + echo "BUILD_FAILED=${{ steps.build.outputs.BUILD_FAILED }}" >> $GITHUB_ENV |
| 103 | + |
| 104 | + - name: Fail workflow if any step failed |
| 105 | + if: env.LINT_FAILED == 'true' || env.TEST_FAILED == 'true' || env.BUILD_FAILED == 'true' |
| 106 | + run: | |
| 107 | + echo "One or more checks failed. See PR comment for details." |
| 108 | + exit 1 |
0 commit comments