diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c5db1ae..0b4e9f7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -8,6 +8,7 @@ jobs: publish: name: Publish runs-on: ubuntu-latest + environment: Publish permissions: contents: write # required for pushing git tags id-token: write # required for npm provenance @@ -33,7 +34,14 @@ jobs: run: pnpm format:lint - name: Test - run: pnpm test + run: pnpm test:coverage + + - name: Parse coverage + id: coverage + run: | + PCT=$(node -e "const c=require('./coverage/coverage-summary.json');console.log(Math.round(c.total.lines.pct))") + echo "pct=$PCT" >> $GITHUB_OUTPUT + echo "color=$([ $PCT -ge 80 ] && echo green || [ $PCT -ge 60 ] && echo yellow || echo red)" >> $GITHUB_OUTPUT - name: Build run: pnpm build @@ -53,6 +61,18 @@ jobs: env: NODE_AUTH_TOKEN: ${{ secrets.RSTACKIO_NPM_TOKEN }} + - name: Update coverage badge + if: steps.publish.outputs.published == 'true' + continue-on-error: true + uses: schneegans/dynamic-badges-action@v1.7.0 + with: + auth: ${{ secrets.GIST_SECRET }} + gistID: ${{ secrets.TEST_COVERAGE_GIST_ID }} + filename: coverage.json + label: coverage + message: ${{ steps.coverage.outputs.pct }}% + color: ${{ steps.coverage.outputs.color }} + - name: Push git tag if: steps.publish.outputs.published == 'true' run: | diff --git a/README.md b/README.md index 745ca4e..4af38e8 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ [![npm](https://img.shields.io/npm/v/@rstackio/services)](https://www.npmjs.com/package/@rstackio/services) [![CI](https://github.com/rstackio/services/actions/workflows/publish.yml/badge.svg)](https://github.com/rstackio/services/actions/workflows/publish.yml) +[![coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/rkovalov/c73854c806277dbac2ab2b6936c39518/raw/coverage.json)](https://github.com/rstackio/services/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/rstackio/services/blob/main/LICENSE) [![TypeScript](https://img.shields.io/badge/TypeScript-5.0%2B-blue)](https://www.typescriptlang.org/)