Skip to content

Commit 3dc2b65

Browse files
authored
feat: reusable workflows (#58)
Utiliza workflows definidos en otro repo Closes #57 Closes #53
1 parent 93e8ef9 commit 3dc2b65

File tree

9 files changed

+877
-733
lines changed

9 files changed

+877
-733
lines changed

.github/workflows/pre-commit-main.yml

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,21 @@ name: pre-commit-main
33
on:
44
push:
55
branches: [main]
6+
workflow_dispatch:
7+
inputs:
8+
debug_enabled:
9+
type: boolean
10+
description: "Run with tmate debugging enabled"
11+
required: false
12+
default: false
613

714
concurrency:
815
group: ${{ github.workflow }}-${{ github.ref }}
916
cancel-in-progress: true
1017

1118
jobs:
12-
pre-commit:
13-
runs-on: ubuntu-latest
14-
steps:
15-
- uses: actions/checkout@v4
16-
with:
17-
# required to grab the history of the PR
18-
fetch-depth: 0
19-
# Not needed since uv installs python automatically
20-
# - uses: actions/setup-python@v5
21-
# with:
22-
# python-version-file: ".python-version"
23-
- name: Set up uv
24-
run: curl -LsSf https://astral.sh/uv/0.4.3/install.sh | sh
25-
# Needed for mypy, since the pre-commit hook is run in "system" mode
26-
- name: Install dependencies
27-
run: |
28-
uv sync --dev --frozen
29-
# Workaround to allow pre-commit to find the venv where dependencies are installed
30-
- run: |
31-
echo "$PWD/.venv/bin" >> $GITHUB_PATH
32-
uv pip install pip
33-
- uses: pre-commit/[email protected]
19+
pre-commit-all-files:
20+
uses: Komorebi-AI/github-actions/.github/workflows/pre-commit-uv.yml@main
21+
with:
22+
uv-version: 0.8.0
23+
debug-enabled: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}

.github/workflows/pre-commit-pr.yml

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,22 @@ name: pre-commit-pr
22

33
on:
44
pull_request:
5+
workflow_dispatch:
6+
inputs:
7+
debug_enabled:
8+
type: boolean
9+
description: "Run with tmate debugging enabled"
10+
required: false
11+
default: false
512

613
concurrency:
714
group: ${{ github.workflow }}-${{ github.ref }}
815
cancel-in-progress: true
916

1017
jobs:
1118
pre-commit:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v4
15-
with:
16-
# required to grab the history of the PR
17-
fetch-depth: 0
18-
# Not needed since uv installs python automatically
19-
# - uses: actions/setup-python@v5
20-
# with:
21-
# python-version-file: ".python-version"
22-
- name: Set up uv
23-
run: curl -LsSf https://astral.sh/uv/0.4.3/install.sh | sh
24-
# Needed for mypy, since the pre-commit hook is run in "system" mode
25-
- name: Install dependencies
26-
run: uv sync --dev --frozen
27-
# Workaround to allow pre-commit to find the venv where dependencies are installed
28-
- run: |
29-
echo "$PWD/.venv/bin" >> $GITHUB_PATH
30-
uv pip install pip
31-
- uses: pre-commit/[email protected]
32-
with:
33-
# Ejecutar solo en ficheros que hayan cambiado https://github.com/pre-commit/action/issues/7
34-
extra_args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}
19+
uses: Komorebi-AI/github-actions/.github/workflows/pre-commit-uv.yml@main
20+
with:
21+
uv-version: 0.8.0
22+
debug-enabled: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
23+
pre-commit-args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}

.github/workflows/pytest.yml

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
1-
name: Pytest
1+
name: pytest
22

3-
# Controls when the action will run.
43
on:
5-
# Triggers the workflow on push or pull request events but only for the main branch
64
push:
75
branches: [main]
86
pull_request:
97
branches: [main]
10-
11-
# Allows you to run this workflow manually from the Actions tab
128
workflow_dispatch:
9+
inputs:
10+
debug_enabled:
11+
type: boolean
12+
description: "Run with tmate debugging enabled"
13+
required: false
14+
default: false
1315

1416
concurrency:
1517
group: ${{ github.workflow }}-${{ github.ref }}
1618
cancel-in-progress: true
1719

1820
jobs:
19-
default-shell:
20-
name: Default shell
21-
runs-on: "ubuntu-latest"
22-
strategy:
23-
matrix:
24-
python-version: ["3.9", "3.10", "3.11", "3.12"]
25-
steps:
26-
- uses: actions/checkout@v4
27-
- uses: actions/setup-python@v5
28-
with:
29-
python-version: ${{ matrix.python-version }}
30-
- name: Set up uv
31-
run: curl -LsSf https://astral.sh/uv/0.4.3/install.sh | sh
32-
- name: Test with pytest
33-
run: |
34-
uv sync --dev --frozen
35-
uv run pytest
21+
pytest:
22+
uses: Komorebi-AI/github-actions/.github/workflows/pytest-uv.yml@main
23+
with:
24+
uv-version: 0.8.0
25+
debug-enabled: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}

.pre-commit-config.yaml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ci:
55

66
repos:
77
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: v4.6.0
8+
rev: v5.0.0
99
hooks:
1010
- id: check-added-large-files
1111
args: [--maxkb=50000]
@@ -29,26 +29,15 @@ repos:
2929
hooks:
3030
- id: python-use-type-annotations
3131
- repo: https://github.com/astral-sh/ruff-pre-commit
32-
rev: v0.6.1
32+
rev: v0.12.4
3333
hooks:
3434
- id: ruff
3535
types_or: [python, pyi, jupyter]
3636
args: [--fix, --show-fixes, --exit-non-zero-on-fix]
3737
- id: ruff-format
3838
types_or: [python, pyi, jupyter]
39-
- repo: https://github.com/pre-commit/mirrors-mypy
40-
rev: v1.11.1
41-
hooks:
42-
- id: mypy
43-
language: system
44-
args: ["--install-types", "--non-interactive"]
45-
# Esto tiene la desventaja de que siempre se va a ejecutar mypy
46-
# sobre todos los ficheros del repo (incluidos en la conf de mypy)
47-
# Se puede sustituir por `files:`
48-
# Ref: https://www.kianmeng.org/2022/09/excluding-files-with-mypy-hook-for-pre.html
49-
pass_filenames: false
5039
- repo: https://github.com/codespell-project/codespell
51-
rev: v2.3.0
40+
rev: v2.4.1
5241
hooks:
5342
- id: codespell
5443
additional_dependencies:
@@ -60,7 +49,7 @@ repos:
6049
types_or: [markdown, yaml]
6150
- repo: https://github.com/astral-sh/uv-pre-commit
6251
# uv version.
63-
rev: 0.4.9
52+
rev: 0.8.0
6453
hooks:
6554
# Update the uv lockfile
6655
- id: uv-lock

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ hooks:
2323
hooks-update:
2424
uv run pre-commit autoupdate
2525

26+
# Specific packages can be upgrade with `--upgrade-package PKG`
27+
upgrade:
28+
uv lock --upgrade
29+
2630
ruff:
2731
uv run ruff format .
2832
uv run ruff check --fix --show-fixes .

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<!-- markdownlint-disable MD059 -->
2+
13
# Template
24

35
![testing workflow](https://github.com/Komorebi-AI/python-template/actions/workflows/pytest.yml/badge.svg)
@@ -23,7 +25,6 @@ Tools:
2325

2426
- [uv](https://docs.astral.sh/uv/): manage dependencies, Python versions and virtual environments
2527
- [ruff](https://docs.astral.sh/ruff/): lint and format Python code
26-
- [mypy](https://mypy.readthedocs.io/): check types
2728
- [pytest](https://docs.pytest.org/en/): run unit tests
2829
- [pre-commit](https://pre-commit.com/): manage pre-commit hooks
2930
- [prettier](https://prettier.io/): format YAML and Markdown
@@ -59,12 +60,18 @@ Install package and pinned dependencies with the [`uv`](https://docs.astral.sh/u
5960

6061
### Library
6162

62-
Install a specific version of the package with `pip` or `uv pip`:
63+
If using `pip` or `uv pip`, a specific version of the package can be installed with:
6364

6465
```{bash}
6566
pip install git+ssh://[email protected]/Komorebi-AI/[email protected]
6667
```
6768

69+
It can also be added to the `requirements.in` or `pyproject.toml`. If using `uv`, it can be added as a dependency with:
70+
71+
```{bash}
72+
uv add "python-template @ git+https://github.com/Komorebi-AI/[email protected]"
73+
```
74+
6875
## Setup development environment (Unix)
6976

7077
Install [`uv`](https://docs.astral.sh/uv/getting-started/installation/) and pre-commit hooks:
@@ -95,6 +102,18 @@ Remove dependency with:
95102
uv remove <PACKAGE>
96103
```
97104

105+
Upgrade all dependencies:
106+
107+
```{bash}
108+
uv lock --upgrade
109+
```
110+
111+
or a single package:
112+
113+
```{bash}
114+
uv lock --upgrade-package ruff
115+
```
116+
98117
In all cases `uv` will automatically update the `uv.lock` file and sync the virtual environment. This can also be done manually with:
99118

100119
```{bash}
@@ -122,9 +141,3 @@ make ruff
122141
```{bash}
123142
make test
124143
```
125-
126-
#### Run type checker
127-
128-
```{bash}
129-
make mypy
130-
```

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ filterwarnings = ["error", "ignore::DeprecationWarning"]
8080
dev-dependencies = [
8181
"pytest",
8282
"ruff",
83-
"mypy",
8483
"pre-commit",
8584
"ipykernel",
85+
"pre-commit-uv>=4.1.4",
8686
]
8787

8888

template/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python
2-
from __future__ import annotations
2+
from __future__ import annotations # noqa: I001
33

44
from importlib.metadata import PackageNotFoundError, version
55

6-
import typer
6+
import typer # type: ignore
77

88
try:
99
__version__: str | None = version("template")

0 commit comments

Comments
 (0)