arichr/gophient

View on GitHub
.github/workflows/python.yml

Summary

Maintainability
Test Coverage
name: Python workflow

on:
  push:
    branches:
     - '**'

jobs:
  cache:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false

    steps:
      - uses: actions/checkout@v3
      - name: Set up Python 3.10
        uses: actions/setup-python@v4
        with:
          python-version: "3.10"

      - name: Load cached venv
        id: cached-poetry-dependencies
        uses: actions/cache@v3
        with:
          path: .venv
          key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

      - name: Install Poetry
        if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
        uses: snok/install-poetry@v1
        with:
          virtualenvs-create: true
          virtualenvs-in-project: true
          installer-parallel: true

      - name: Install dependencies
        if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
        run: poetry install --with=ci --without=docs --no-interaction --no-root

  test:
    runs-on: ubuntu-latest
    needs: cache
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.8", "3.9", "3.10"]

    steps:
      - uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}

      - name: Load cached venv
        id: cached-poetry-dependencies
        uses: actions/cache@v3
        with:
          path: .venv
          key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

      - name: Linting
        run: |
          source .venv/bin/activate
          ruff check . --output-format=full

  coverage:
    runs-on: ubuntu-latest
    needs: test
    concurrency:
      group: "coverage"
      cancel-in-progress: true
    env:
      CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}

    steps:
      - uses: actions/checkout@v3
      - name: Load cached venv
        id: cached-poetry-dependencies
        uses: actions/cache@v3
        with:
          path: .venv
          key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

      - name: Testing
        run: |
          source .venv/bin/activate
          MODULE_DIR=$(dirname "$(ls */__init__.py)")
          coverage run --source "$MODULE_DIR" -m pytest
          coverage report --skip-covered --fail-under=80
          coverage xml --ignore-errors

      - name: Publish code coverage
        if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' }}
        uses: paambaati/codeclimate-action@v5.0.0
        env:
          CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
        with:
          coverageLocations: coverage.xml:coverage.py

  build:
    runs-on: ubuntu-latest
    needs: test
    if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' }}
    concurrency:
      group: "build"
      cancel-in-progress: true

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: "3.10"

      - name: Install Poetry
        uses: snok/install-poetry@v1
        with:
          virtualenvs-create: true
          virtualenvs-in-project: true
          installer-parallel: true

      - name: Load cached venv
        id: cached-poetry-dependencies
        uses: actions/cache@v3
        with:
          path: .venv
          key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

      - name: Build a package
        run: |
          source .venv/bin/activate
          poetry build

      - name: Publish as an artifact
        uses: actions/upload-artifact@v3
        with:
          name: Wheel (Python 3.10)
          path: dist/*.whl