42Atomys/webhooked

View on GitHub
.github/workflows/tests.yaml

Summary

Maintainability
Test Coverage
name: Tests 🛠️
on: 
  pull_request:
  push:
    branches:
    - main
    paths:
    - '**/*.go'
    - '**/*.yaml'
  workflow_dispatch:
permissions:
  contents: read
jobs:
  applications-test-units:
    name: "GoLang test units"
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        goVersion: [ '1.18', '1.19', '1.20' ]
    env:
      WH_DEBUG: 'true'
      REDIS_HOST: '127.0.0.1'
      REDIS_PORT: '6379'
      REDIS_PASSWORD: ''
      RABBITMQ_HOST: '127.0.0.1'
      RABBITMQ_PORT: '5672'
      RABBITMQ_USER: 'rabbitmq'
      RABBITMQ_PASSWORD: 'rabbitmq'
      POSTGRES_HOST: '127.0.0.1'
      POSTGRES_PORT: '5432'
      POSTGRES_USER: 'postgres'
      POSTGRES_PASSWORD: 'postgres'
      POSTGRES_DB: 'postgres'
    steps:
    - name: Checkout project
      uses: actions/checkout@v4
    - name: Start Redis
      uses: supercharge/redis-github-action@1.8.0
      with:
        redis-version: 6
    - name: Setup RabbitMQ
      uses: getong/rabbitmq-action@v1.2
      with:
        rabbitmq version: '3.8.2-management-alpine'
        host port: 5672
        rabbitmq user: 'rabbitmq'
        rabbitmq password: 'rabbitmq'
    - name: Setup PostgreSQL
      uses: harmon758/postgresql-action@v1
      with:
        postgresql version: '11'
        postgresql db: postgres
        postgresql user: postgres
        postgresql password: postgres
    - name: Setup go
      uses: actions/setup-go@v5
      with:
        go-version: ${{ matrix.goVersion }}
        check-latest: true
    - name: golangci-lint
      uses: golangci/golangci-lint-action@v4.0.0
      with:
        version: latest
    - name: Run Unit tests
      run: make test-units
    - name: Quality Gate - Test coverage shall be above threshold
      env:
          TESTCOVERAGE_THRESHOLD: 90
      run: |
        echo "Quality Gate: checking test coverage is above threshold ..."
        echo "Threshold             : $TESTCOVERAGE_THRESHOLD %"
        totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
        echo "Current test coverage : $totalCoverage %"
        if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
            echo "OK"
        else
            echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
            echo "Failed"
            exit 1
        fi
    - uses: codecov/codecov-action@v4
    - name: Run Go Build
      run: make build
  integration-tests:
    name: "Integration tests"
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        goVersion: [ '1.18', '1.19', '1.20' ]
    env:
      WH_DEBUG: 'true'
      REDIS_HOST: '127.0.0.1'
      REDIS_PORT: '6379'
      REDIS_PASSWORD: ''
    steps:
    - name: Checkout project
      uses: actions/checkout@v4
    - name: Start Redis
      uses: supercharge/redis-github-action@1.8.0
      with:
        redis-version: 6
    - name: Run Integration tests
      run: |
        make run-integration >/dev/null 2>&1 &
        until $(curl --output /dev/null --silent --head --fail http://localhost:8080/metrics); do
          printf '.'
          sleep 1
        done
        make test-integrations