diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml new file mode 100644 index 0000000..12e76e9 --- /dev/null +++ b/.github/workflows/test-coverage.yml @@ -0,0 +1,68 @@ +name: Test Coverage + +on: + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm install + + - name: Run tests with coverage + run: | + npm run test:coverage > coverage-output.txt 2>&1 + + - name: Upload coverage report + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: coverage-output.txt + retention-days: 1 + + comment: + runs-on: ubuntu-latest + needs: test + permissions: + pull-requests: write + + steps: + - name: Download coverage report + uses: actions/download-artifact@v4 + with: + name: coverage-report + + - name: Read coverage report + id: coverage + run: | + echo "COVERAGE_REPORT<> $GITHUB_OUTPUT + cat coverage-output.txt >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Post coverage comment + uses: peter-evans/create-or-update-comment@v5 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + ## Test Coverage Report + + ``` + ${{ steps.coverage.outputs.COVERAGE_REPORT }} + ``` + + --- + *Coverage report generated by GitHub Actions*