This repository was archived by the owner on Jul 4, 2026. It is now read-only.
[BUG] fix issue #25 - have workflow use correct token #16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| pull-requests: write | |
| contents: read | |
| strategy: | |
| matrix: | |
| node-version: [18.x, 20.x, 22.x] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests and generate JSON report | |
| run: npm test -- --reporter json --reporter-options output=test-results-${{ matrix.node-version }}.json | |
| - name: Upload test results | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results-${{ matrix.node-version }} | |
| path: test-results-${{ matrix.node-version }}.json | |
| retention-days: 1 | |
| report-status: | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| if: github.event_name == 'pull_request' && always() | |
| permissions: | |
| issues: write | |
| pull-requests: write | |
| contents: read | |
| steps: | |
| - name: Download all test results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: test-results-* | |
| path: test-results | |
| merge-multiple: true | |
| - name: Combine and post comment | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const fs = await import('fs/promises'); | |
| const path = await import('path'); | |
| const testResultsDir = 'test-results'; | |
| let commentBody = '## Test Results Summary\n\n'; | |
| let overallStatus = '✅ All tests passed across all Node.js versions.'; | |
| let hasFailures = false; | |
| const files = await fs.readdir(testResultsDir); | |
| for (const file of files) { | |
| if (file.startsWith('test-results-') && file.endsWith('.json')) { | |
| const nodeVersion = file.replace('test-results-', '').replace('.json', ''); | |
| const filePath = path.join(testResultsDir, file); | |
| const results = JSON.parse(await fs.readFile(filePath, 'utf8')); | |
| commentBody += `### Node.js ${nodeVersion}\n`; | |
| if (results.stats.failures > 0) { | |
| hasFailures = true; | |
| commentBody += `❌ **${results.stats.failures} of ${results.stats.tests} tests failed.**\n`; | |
| overallStatus = '❌ Some tests failed. Please review the logs for details.'; | |
| } else { | |
| commentBody += `✅ **All ${results.stats.tests} tests passed.**\n`; | |
| } | |
| for (const test of results.tests) { | |
| commentBody += `- ${test.state === 'passed' ? '✅' : (test.state === 'failed' ? '❌' : '➖')} ${test.fullTitle}\n`; | |
| if (test.state === 'failed' && test.err && test.err.message) { | |
| commentBody += ` \`\`\`\n ${test.err.message}\n \`\`\`\n`; | |
| } | |
| } | |
| commentBody += '\n'; | |
| } | |
| } | |
| commentBody = `${overallStatus}\n\n${commentBody}`; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: commentBody | |
| }); |