Skip to content

Commit

Permalink
Merge branch 'main' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JaeAeich committed May 24, 2024
2 parents e9cedba + cabf21c commit 0babf25
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 71 deletions.
79 changes: 79 additions & 0 deletions .github/actions/setup/poetry/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Setup Python and Poetry Action
description: Install and configure the system, Python, Poetry and requested deps with cache management.

inputs:
os:
default: ubuntu-latest
description: The operating system to use
python-version:
default: "3.11"
description: The version of Python to use
poetry-version:
default: "1.8.2"
description: The version of Poetry to install
poetry-install-options:
default: ""
description: Additional options to pass to poetry install
poetry-export-options:
default: ""
description: Options to pass to poetry export for hash generation for cache invalidation

runs:
using: composite
steps:
- uses: "actions/setup-python@v5"
id: setup-python
with:
python-version: "${{ inputs.python-version }}"

- name: Setup pipx environment Variables
id: pipx-env-setup
# pipx default home and bin dir are not writable by the cache action
# so override them here and add the bin dir to PATH for later steps.
# This also ensures the pipx cache only contains poetry
run: |
SEP="${{ !startsWith(runner.os, 'windows') && '/' || '\\' }}"
PIPX_CACHE="${{ github.workspace }}${SEP}pipx_cache"
echo "pipx-cache-path=${PIPX_CACHE}" >> $GITHUB_OUTPUT
echo "pipx-version=$(pipx --version)" >> $GITHUB_OUTPUT
echo "PIPX_HOME=${PIPX_CACHE}${SEP}home" >> $GITHUB_ENV
echo "PIPX_BIN_DIR=${PIPX_CACHE}${SEP}bin" >> $GITHUB_ENV
echo "PIPX_MAN_DIR=${PIPX_CACHE}${SEP}man" >> $GITHUB_ENV
echo "${PIPX_CACHE}${SEP}bin" >> $GITHUB_PATH
shell: bash

- name: Pipx cache
id: pipx-cache
uses: actions/cache@v4
with:
path: ${{ steps.pipx-env-setup.outputs.pipx-cache-path }}
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-poetry-${{ inputs.poetry-version }}

- name: Install poetry
if: steps.pipx-cache.outputs.cache-hit != 'true'
id: install-poetry
shell: bash
run: |-
pipx install poetry --python "${{ steps.setup-python.outputs.python-path }}"
- name: Read poetry cache location
id: poetry-cache-location
shell: bash
run: echo "poetry-venv-location=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT

- name: Generate hash only for required deps
run: |
poetry export ${{ inputs.poetry-export-options }} --format=requirements.txt --output=requirements.txt
echo "DEP_HASH=$(sha256sum requirements.txt | cut -d ' ' -f 1)" >> $GITHUB_ENV
shell: bash

- uses: actions/cache@v4
name: Poetry cache
with:
path: ${{ steps.poetry-cache-location.outputs.poetry-venv-location }}
key: ${{ runner.os }}-[python-${{ steps.setup-python.outputs.python-version }}]-[${{ env.DEP_HASH }}]-[${{ inputs.poetry-install-options }}]

- name: "Poetry install"
if: steps.poetry-cache.outputs.cache-hit != 'true'
shell: bash
run: poetry install ${{ inputs.poetry-install-options }} --no-interaction
62 changes: 21 additions & 41 deletions .github/workflows/code_quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v5
id: cq
- name: Set up environment
uses: ./.github/actions/setup/poetry
with:
os: ${{ job.os }}
python-version: '3.11'
cache: 'poetry'

- name: Install lint dependencies
run: poetry install --only=lint --no-interaction --no-root
poetry-install-options: "--only=lint --no-root"
poetry-export-options: "--only=lint"

- name: Check code quality
run: poetry run ruff check .
Expand All @@ -39,18 +34,13 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v5
id: cq
- name: Set up environment
uses: ./.github/actions/setup/poetry
with:
os: ${{ job.os }}
python-version: '3.11'
cache: 'poetry'

- name: Install lint dependencies
run: poetry install --only=lint --no-interaction --no-root
poetry-install-options: "--only=lint --no-root"
poetry-export-options: "--only=lint"

- name: Check code style
run: poetry run ruff format --check
Expand All @@ -62,18 +52,13 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up python
id: cqtc
uses: actions/setup-python@v5
- name: Set up environment
uses: ./.github/actions/setup/poetry
with:
os: ${{ job.os }}
python-version: '3.11'
cache: 'poetry'

- name: Install types and mypy dependencies
run: poetry install --only=types --no-interaction --no-root
poetry-install-options: "--only=types --no-root"
poetry-export-options: "--only=types"

- name: Check types
run: poetry run mypy tesk/
Expand All @@ -85,18 +70,13 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v5
id: cq
- name: Set up environment
uses: ./.github/actions/setup/poetry
with:
os: ${{ job.os }}
python-version: '3.11'
cache: 'poetry'

- name: Install lint dependencies
run: poetry install --only=lint --no-interaction --no-root
poetry-install-options: "--only=lint --no-root"
poetry-export-options: "--only=lint"

- name: Check spellings
run: poetry run typos .
run: poetry run typos .
15 changes: 5 additions & 10 deletions .github/workflows/code_test_unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v5
id: ct
- name: Set up environment
uses: ./.github/actions/setup/poetry
with:
os: ${{ job.os }}
python-version: '3.11'
cache: 'poetry'

- name: Install test dependencies
run: poetry install --only=test --no-interaction
poetry-install-options: "--with=test"
poetry-export-options: "--with=test"

- name: Run tests and generate coverage as test_unit.xml
run: poetry run pytest --cov-report term --cov-report xml:test_unit.xml --cov=tests/test_unit
Expand Down
30 changes: 10 additions & 20 deletions .github/workflows/vulnerabilities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up python
id: vt
uses: actions/setup-python@v5
- name: Set up environment
uses: ./.github/actions/setup/poetry
with:
os: ${{ job.os }}
python-version: '3.11'
cache: 'poetry'

- name: Install vulnerabilities check dependencies
run: poetry install --only=security --no-interaction --no-root
poetry-install-options: "--only=security --no-root"
poetry-export-options: "--only=security"

- name: Check code vulnerabilities with bandit
run: poetry run bandit -c pyproject.toml -r tesk/
Expand All @@ -39,18 +34,13 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up python
id: vt
uses: actions/setup-python@v5
- name: Set up environment
uses: ./.github/actions/setup/poetry
with:
os: ${{ job.os }}
python-version: '3.11'
cache: 'poetry'

- name: Install vulnerabilities check dependencies
run: poetry install --only=security --no-interaction --no-root
poetry-install-options: "--only=security --no-root"
poetry-export-options: "--only=security"

- name: Check dependency vulnerabilities with safety
run: poetry run safety check --full-report

0 comments on commit 0babf25

Please sign in to comment.