Skip to content

Commit 9fee731

Browse files
committed
feat: python ci
1 parent 6186253 commit 9fee731

File tree

5 files changed

+242
-0
lines changed

5 files changed

+242
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: Format Code
3+
description: Checks and ensures the code is formatted according to the defined style guidelines.
4+
5+
inputs:
6+
python_version:
7+
description: Python version to use
8+
default: "3.12"
9+
required: false
10+
poetry_install_options:
11+
description: Options for installing dependencies via poetry
12+
required: false
13+
default: "--only=code_quality --no-root"
14+
poetry_export_options:
15+
description: Options for exporting dependencies to check for hash
16+
changes for cache invalidation
17+
required: false
18+
default: "--only=code_quality"
19+
20+
runs:
21+
using: composite
22+
steps:
23+
- name: Check out repository
24+
uses: actions/checkout@v4
25+
26+
- name: Set up environment
27+
uses: ./actions/python/setup/poetry
28+
with:
29+
python-version: ${{ inputs.python_version }}
30+
poetry-install-options: ${{ inputs.poetry_install_options }}
31+
poetry-export-options: ${{ inputs.poetry_export_options }}
32+
33+
- name: Check code style
34+
shell: bash
35+
run: poetry run ruff format --check
36+
...
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: Lint Code
3+
description: Lints the code to ensure code quality and adherence to standards.
4+
5+
inputs:
6+
python_version:
7+
description: Python version to use
8+
default: "3.12"
9+
required: false
10+
poetry_install_options:
11+
description: Options for installing dependencies via poetry
12+
required: false
13+
default: "--only=code_quality --no-root"
14+
poetry_export_options:
15+
description: Options for exporting dependencies to check for hash
16+
changes for cache invalidation
17+
required: false
18+
default: "--only=code_quality"
19+
20+
runs:
21+
using: composite
22+
steps:
23+
- name: Check out repository
24+
uses: actions/checkout@v4
25+
26+
- name: Set up environment
27+
uses: ./actions/python/setup/poetry
28+
with:
29+
python-version: ${{ inputs.python_version }}
30+
poetry-install-options: ${{ inputs.poetry_install_options }}
31+
poetry-export-options: ${{ inputs.poetry_export_options }}
32+
33+
- name: Check code quality
34+
shell: bash
35+
run: poetry run ruff check .
36+
...
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: Spell Check
3+
description: Runs a spell check on the codebase to identify spelling errors.
4+
5+
inputs:
6+
python_version:
7+
description: Python version to use
8+
default: "3.12"
9+
required: false
10+
poetry_install_options:
11+
description: Options for installing dependencies via poetry
12+
required: false
13+
default: "--only=code_quality --no-root"
14+
poetry_export_options:
15+
description: Options for exporting dependencies to check for hash
16+
changes for cache invalidation
17+
required: false
18+
default: "--only=code_quality"
19+
20+
runs:
21+
using: composite
22+
steps:
23+
- name: Check out repository
24+
uses: actions/checkout@v4
25+
26+
- name: Set up environment
27+
uses: ./.github/actions/setup/poetry
28+
with:
29+
python-version: ${{ inputs.python_version }}
30+
poetry-install-options: ${{ inputs.poetry_install_options }}
31+
poetry-export-options: ${{ inputs.poetry_export_options }}
32+
33+
- name: Check spellings
34+
shell: bash
35+
run: poetry run typos .
36+
...
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
name: Type Check
3+
description: Runs a type check on the codebase to ensure type safety and
4+
correctness.
5+
6+
inputs:
7+
python_version:
8+
description: Python version to use
9+
default: "3.12"
10+
required: false
11+
poetry_install_options:
12+
description: Options for installing dependencies via poetry
13+
required: false
14+
default: "--with=code_quality --with=types --no-root"
15+
poetry_export_options:
16+
description: Options for exporting dependencies to check for hash
17+
changes for cache invalidation
18+
required: false
19+
default: "--with=code_quality --with=types"
20+
file_path:
21+
description: The path to the file or directory to type check
22+
required: false
23+
default: " . "
24+
25+
26+
runs:
27+
using: composite
28+
steps:
29+
- name: Check out repository
30+
uses: actions/checkout@v4
31+
32+
- name: Set up environment
33+
uses: ./.github/actions/setup/poetry
34+
with:
35+
python-version: ${{ inputs.python_version }}
36+
poetry-install-options: ${{ inputs.poetry_install_options }}
37+
poetry-export-options: ${{ inputs.poetry_export_options }}
38+
39+
- name: Check types
40+
shell: bash
41+
run: poetry run mypy ${{ inputs.file_path }}
42+
...
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
name: Setup Python and Poetry Action
3+
description: Configure system, Python, Poetry and deps and cache management.
4+
5+
inputs:
6+
os:
7+
default: ubuntu-latest
8+
description: The operating system to use
9+
python_version:
10+
default: '3.11'
11+
description: The version of Python to use
12+
poetry_version:
13+
default: '1.8.2'
14+
description: The version of Poetry to install
15+
poetry_install_options:
16+
default: ''
17+
description: Additional options to pass to poetry install
18+
poetry_export_options:
19+
default: ''
20+
description: Options to pass to poetry export for hash generation for cache
21+
invalidation
22+
23+
runs:
24+
using: composite
25+
steps:
26+
- uses: 'actions/setup-python@v5'
27+
id: setup-python
28+
with:
29+
python_version: '${{ inputs.python_version }}'
30+
31+
- name: Setup pipx environment Variables
32+
id: pipx-env-setup
33+
# pipx default home and bin dir are not writable by the cache action
34+
# so override them here and add the bin dir to PATH for later steps.
35+
# This also ensures the pipx cache only contains poetry
36+
run: |
37+
SEP="${{ !startsWith(runner.os, 'windows') && '/' || '\\' }}"
38+
PIPX_CACHE="${{ github.workspace }}${SEP}pipx_cache"
39+
echo "pipx-cache-path=${PIPX_CACHE}" >> $GITHUB_OUTPUT
40+
echo "pipx-version=$(pipx --version)" >> $GITHUB_OUTPUT
41+
echo "PIPX_HOME=${PIPX_CACHE}${SEP}home" >> $GITHUB_ENV
42+
echo "PIPX_BIN_DIR=${PIPX_CACHE}${SEP}bin" >> $GITHUB_ENV
43+
echo "PIPX_MAN_DIR=${PIPX_CACHE}${SEP}man" >> $GITHUB_ENV
44+
echo "${PIPX_CACHE}${SEP}bin" >> $GITHUB_PATH
45+
shell: bash
46+
47+
- name: Pipx cache
48+
id: pipx-cache
49+
uses: actions/cache@v4
50+
with:
51+
path: ${{ steps.pipx-env-setup.outputs.pipx-cache-path }}
52+
key: ${{ runner.os }}-python-
53+
${{ steps.setup-python.outputs.python_version }}-
54+
pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-
55+
poetry-${{ inputs.poetry_version }}
56+
57+
- name: Install poetry
58+
if: steps.pipx-cache.outputs.cache-hit != 'true'
59+
id: install-poetry
60+
shell: bash
61+
run: |
62+
pipx install poetry \
63+
--python "${{ steps.setup-python.outputs.python-path }}"
64+
65+
- name: Read poetry cache location
66+
id: poetry-cache-location
67+
shell: bash
68+
run: |
69+
echo "poetry-venv-location=$(poetry config virtualenvs.path)" \
70+
>> $GITHUB_OUTPUT
71+
72+
- name: Generate hash only for required deps
73+
run: |
74+
poetry export ${{ inputs.poetry_export_options }} \
75+
--format=requirements.txt --output=requirements.txt
76+
echo "DEP_HASH=$(sha256sum requirements.txt | cut -d ' ' -f 1)" \
77+
>> $GITHUB_ENV
78+
shell: bash
79+
80+
- name: Poetry cache
81+
uses: actions/cache@v4
82+
with:
83+
path: ${{ steps.poetry-cache-location.outputs.poetry-venv-location }}
84+
key: ${{ runner.os }}-[python-
85+
${{ steps.setup-python.outputs.python_version }}]-[
86+
${{ env.DEP_HASH }}]-[${{ inputs.poetry_install_options }}]
87+
88+
- name: Poetry install
89+
if: steps.poetry-cache.outputs.cache-hit != 'true'
90+
shell: bash
91+
run: poetry install ${{ inputs.poetry_install_options }} --no-interaction
92+
...

0 commit comments

Comments
 (0)