|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ master, develop ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Setup Node.js |
| 18 | + uses: actions/setup-node@v4 |
| 19 | + with: |
| 20 | + node-version: 'lts/*' |
| 21 | + cache: 'npm' |
| 22 | + |
| 23 | + - name: Install dependencies |
| 24 | + run: npm ci |
| 25 | + |
| 26 | + - name: Run linter |
| 27 | + run: npm run lint |
| 28 | + |
| 29 | + - name: Run tests |
| 30 | + run: npm test |
| 31 | + |
| 32 | + coverage: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + if: github.event_name == 'push' |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout code |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Setup Node.js |
| 41 | + uses: actions/setup-node@v4 |
| 42 | + with: |
| 43 | + node-version: 'lts/*' |
| 44 | + cache: 'npm' |
| 45 | + |
| 46 | + - name: Install dependencies |
| 47 | + run: npm ci |
| 48 | + |
| 49 | + - name: Run tests with coverage |
| 50 | + run: npm run test:coverage |
| 51 | + |
| 52 | + - name: Read coverage summary |
| 53 | + id: coverage |
| 54 | + run: | |
| 55 | + echo "pct=$(jq '.total.lines.pct' coverage/coverage-summary.json)" >> $GITHUB_OUTPUT |
| 56 | +
|
| 57 | + - name: Create badges directory |
| 58 | + run: mkdir -p .github/badges |
| 59 | + |
| 60 | + - name: Generate coverage badge |
| 61 | + uses: emibcn/badge-action@v2.0.3 |
| 62 | + with: |
| 63 | + label: 'coverage' |
| 64 | + status: ${{ steps.coverage.outputs.pct }}% |
| 65 | + color: ${{ fromJSON(steps.coverage.outputs.pct) >= 80 && 'green' || fromJSON(steps.coverage.outputs.pct) >= 60 && 'yellow' || 'red' }} |
| 66 | + path: .github/badges/coverage.svg |
| 67 | + |
| 68 | + - name: Commit coverage badge |
| 69 | + run: | |
| 70 | + git config --local user.email "action@github.com" |
| 71 | + git config --local user.name "GitHub Action" |
| 72 | + git add .github/badges/coverage.svg |
| 73 | + git diff --staged --quiet || git commit -m "Update coverage badge" |
| 74 | + git push |
| 75 | +
|
| 76 | + - name: Upload coverage reports |
| 77 | + uses: actions/upload-artifact@v4 |
| 78 | + with: |
| 79 | + name: coverage-report |
| 80 | + path: coverage/ |
0 commit comments