|
| 1 | +--- |
| 2 | +name: tests |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + paths-ignore: |
| 7 | + - "**.md" |
| 8 | + - "LICENSE" |
| 9 | + - ".gitignore" |
| 10 | + - ".pre-commit-config.yaml" |
| 11 | + |
| 12 | +env: |
| 13 | + CACHE_DIR: /tmp/.workflow_cache |
| 14 | + POETRY_CACHE_DIR: /tmp/.workflow_cache/.pip_packages |
| 15 | + POETRY_VIRTUALENVS_PATH: /tmp/.workflow_cache/.venvs |
| 16 | + POETRY_HOME: /tmp/.workflow_cache/.poetry |
| 17 | + PIP_CACHE_DIR: /tmp/.workflow_cache/.pip_packages |
| 18 | + MYPY_CACHE_DIR: /tmp/.workflow_cache/.mypy |
| 19 | + |
| 20 | +jobs: |
| 21 | + tests: |
| 22 | + runs-on: ${{ matrix.os }} |
| 23 | + strategy: |
| 24 | + matrix: |
| 25 | + os: ["ubuntu-latest"] |
| 26 | + python-version: ["3.x"] |
| 27 | + steps: |
| 28 | + - name: Checkout repository |
| 29 | + uses: actions/checkout@v3 |
| 30 | + |
| 31 | + - name: Set up Python ${{ matrix.python-version }} |
| 32 | + uses: actions/setup-python@v4 |
| 33 | + with: |
| 34 | + python-version: ${{ matrix.python-version }} |
| 35 | + |
| 36 | + - name: Cache dependencies |
| 37 | + uses: actions/cache@v3 |
| 38 | + id: cache |
| 39 | + with: |
| 40 | + path: ${{ env.CACHE_DIR }} |
| 41 | + key: tests-${{ matrix.os }}-${{ matrix.python-version }}--${{ hashFiles('**/poetry.lock') }} |
| 42 | + |
| 43 | + - name: Install dependencies |
| 44 | + run: | |
| 45 | + curl -sSL https://install.python-poetry.org | python - |
| 46 | + $POETRY_HOME/bin/poetry install -n -E speedups |
| 47 | + if: steps.cache.outputs.cache-hit != 'true' |
| 48 | + |
| 49 | + - name: Python code style |
| 50 | + run: $POETRY_HOME/bin/poetry run black . --check --diff --preview |
| 51 | + if: ${{ always() }} |
| 52 | + |
| 53 | + - name: Python code quality |
| 54 | + run: $POETRY_HOME/bin/poetry run flake8 --docstring-convention google |
| 55 | + if: ${{ always() }} |
| 56 | + |
| 57 | + - name: Python code typing |
| 58 | + run: $POETRY_HOME/bin/poetry run mypy --strict --install-types --non-interactive . |
| 59 | + if: ${{ always() }} |
| 60 | + |
| 61 | + - name: Python code complexity |
| 62 | + run: $POETRY_HOME/bin/poetry run radon cc -n C starlette_aws_lambda_api_client 1>&2 |
| 63 | + if: ${{ always() }} |
| 64 | + |
| 65 | + - name: Python code maintainability |
| 66 | + run: $POETRY_HOME/bin/poetry run radon mi -n B starlette_aws_lambda_api_client 1>&2 |
| 67 | + if: ${{ always() }} |
| 68 | + |
| 69 | + - name: Python code security |
| 70 | + run: $POETRY_HOME/bin/poetry run bandit starlette_aws_lambda_api_client -rs B404,B603 |
| 71 | + if: ${{ always() }} |
| 72 | + |
| 73 | + - name: YAML code style |
| 74 | + run: $POETRY_HOME/bin/poetry run yamllint -s . |
| 75 | + if: ${{ always() }} |
| 76 | + |
| 77 | + - name: Test |
| 78 | + run: $POETRY_HOME/bin/poetry run pytest --junitxml=test-results.xml --cov-report xml |
| 79 | + if: ${{ always() }} |
| 80 | + |
| 81 | + - name: Collect coverage report |
| 82 | + uses: codecov/codecov-action@v3 |
| 83 | + |
| 84 | + publish: |
| 85 | + runs-on: ${{ matrix.os }} |
| 86 | + strategy: |
| 87 | + matrix: |
| 88 | + os: ["ubuntu-latest"] |
| 89 | + python-version: ["3.x"] |
| 90 | + if: ${{ github.repository == 'JGoutin/starlette_aws_lambda_api_client' && github.ref_type == 'tag' }} |
| 91 | + needs: [tests] |
| 92 | + environment: PyPI |
| 93 | + permissions: |
| 94 | + contents: write |
| 95 | + steps: |
| 96 | + - name: Checkout repository |
| 97 | + uses: actions/checkout@v3 |
| 98 | + |
| 99 | + - name: Set up Python ${{ matrix.python-version }} |
| 100 | + uses: actions/setup-python@v4 |
| 101 | + with: |
| 102 | + python-version: ${{ matrix.python-version }} |
| 103 | + |
| 104 | + - name: Cache dependencies |
| 105 | + uses: actions/cache@v3 |
| 106 | + id: cache |
| 107 | + with: |
| 108 | + path: ${{ env.CACHE_DIR }} |
| 109 | + key: tests-${{ matrix.os }}-${{ matrix.python-version }}--${{ hashFiles('**/poetry.lock') }} |
| 110 | + |
| 111 | + - name: Build packages |
| 112 | + run: $POETRY_HOME/bin/poetry version $(echo -e "${{ github.ref_name }}" | tr -d 'v') |
| 113 | + |
| 114 | + - name: Publish packages on PyPI |
| 115 | + run: $POETRY_HOME/bin/poetry publish --build |
| 116 | + env: |
| 117 | + POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} |
| 118 | + |
| 119 | + - name: Publish release on GitHub |
| 120 | + run: | |
| 121 | + go install github.com/tcnksm/ghr@latest |
| 122 | + ~/go/bin/ghr -generatenotes $PRERELEASE -c ${{ github.sha }} ${{ github.ref_name }} |
| 123 | + env: |
| 124 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 125 | + PRERELEASE: ${{ contains(github.ref_name, '-') && '-prerelease' || '' }} |
0 commit comments