rawmind/express-autodoc

View on GitHub
.github/workflows/ci.yml

Summary

Maintainability
Test Coverage
name: Tests CI

on:
  workflow_dispatch:
  push:
    branches:
      - master
  pull_request:

jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18.x'
          cache: 'npm'

      - name: Run jest tests
        id: jest
        run: |
          npm install
          npm run coverage
        env:
          COMPOSE_DOCKER_CLI_BUILD: 1
          COMPOSE_INTERACTIVE_NO_CLI: 1
          DOCKER_BUILDKIT: 1

      - name: Upload coverage artifacts
        uses: actions/upload-artifact@v3
        with:
          name: coverage-report
          path: coverage
          retention-days: 1

      - name: Tests ✅
        if: ${{ success() }}
        run: |
          curl --request POST \
          --url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
          --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
          --header 'content-type: application/json' \
          --data '{
            "context": "tests",
            "state": "success",
            "description": "Tests passed",
            "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
          }'

      - name: Tests 🚨
        if: ${{ failure() }}
        run: |
          curl --request POST \
          --url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
          --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
          --header 'content-type: application/json' \
          --data '{
            "context": "tests",
            "state": "failure",
            "description": "Tests failed",
            "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
          }'

  coverage:
    name: "Upload coverage to Codeclimate"
    runs-on: ubuntu-latest
    needs:
    - tests
    steps:
    - uses: actions/checkout@v3

    - name: Download coverage artifacts
      uses: actions/download-artifact@v3
      with:
        path: coverage

    - name: Report coverage to CodeClimate
      uses: paambaati/codeclimate-action@v5.0.0
      env:
        CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
      with:
        coverageLocations: |
          ${{github.workspace}}/coverage/coverage-report/lcov.info:lcov