Skip to content

Commit 4b073be

Browse files
committed
feat: first version
1 parent 3747226 commit 4b073be

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Python Poetry Test Action
2+
3+
Test Poetry-based projects using ruff, mypy, and pytest.
4+
5+
1. Install Python
6+
2. Installs Poetry
7+
3. Installs dependencies
8+
4. Runs `ruff check` on source directories
9+
5. Runs `ruff format --check` on source directories
10+
6. Runs `mypy` on source directories
11+
7. Runs `pytest`
12+
13+
## Inputs
14+
15+
| Input | Description | Required | Default |
16+
|-------|-------------|----------|---------|
17+
| `python-version` | Python version to use | No | `3.14` |
18+
| `poetry-version` | Poetry version to install | No | `2.2.1` |
19+
| `src-dirs` | Source directories for linting (space-separated) | No | `src tests` |
20+
21+
## Usage
22+
23+
```yaml
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v6
27+
28+
- name: Test with Poetry
29+
uses: CVector-Energy/python-test@main
30+
```
31+
32+
### With custom Python version
33+
34+
```yaml
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v6
38+
39+
- name: Test with Poetry
40+
uses: CVector-Energy/python-test@main
41+
with:
42+
python-version: "3.12"
43+
```
44+
45+
### Matrix testing
46+
47+
```yaml
48+
jobs:
49+
test:
50+
runs-on: ubuntu-24.04
51+
strategy:
52+
matrix:
53+
python-version: ["3.10", "3.11", "3.12", "3.14"]
54+
55+
steps:
56+
- name: Checkout
57+
uses: actions/checkout@v6
58+
59+
- name: Test with Poetry
60+
uses: your-org/python-test@main
61+
with:
62+
python-version: ${{ matrix.python-version }}
63+
```

action.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Test
2+
description: Setup Poetry and run ruff, mypy, and pytest for Python projects
3+
4+
inputs:
5+
python-version:
6+
description: Python version to use
7+
required: false
8+
default: "3.14"
9+
poetry-version:
10+
description: Poetry version to install
11+
required: false
12+
default: "2.2.1"
13+
src-dirs:
14+
description: Source directories for linting (space-separated)
15+
required: false
16+
default: "src tests"
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Setup Python ${{ inputs.python-version }}
22+
id: setup
23+
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
24+
with:
25+
python-version: ${{ inputs.python-version }}
26+
27+
- name: Load cached Poetry installation
28+
id: cached-poetry
29+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
30+
with:
31+
path: ~/.local
32+
key: poetry-${{ inputs.poetry-version }}
33+
34+
- name: Install Poetry
35+
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
36+
with:
37+
version: ${{ inputs.poetry-version }}
38+
virtualenvs-path: ~/.venv
39+
40+
- name: Load cached venv
41+
id: venv
42+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
43+
with:
44+
path: ~/.venv
45+
key: venv-${{ runner.os }}-${{ steps.setup.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
46+
restore-keys: |
47+
venv-${{ runner.os }}-${{ steps.setup.outputs.python-version }}-
48+
49+
- name: Sync dependencies
50+
if: steps.venv.outputs.cache-hit != 'true'
51+
shell: bash
52+
run: poetry sync --no-interaction --no-root
53+
54+
- name: Install project
55+
shell: bash
56+
run: poetry install --no-interaction --only-root
57+
58+
- name: Run ruff check
59+
shell: bash
60+
run: poetry run ruff check ${{ inputs.src-dirs }}
61+
62+
- name: Run ruff format check
63+
shell: bash
64+
run: poetry run ruff format --check ${{ inputs.src-dirs }}
65+
66+
- name: Run mypy
67+
shell: bash
68+
run: poetry run mypy ${{ inputs.src-dirs }}
69+
70+
- name: Run pytest
71+
shell: bash
72+
run: poetry run pytest

0 commit comments

Comments
 (0)