|
8 | 8 | branches: |
9 | 9 | - master |
10 | 10 |
|
11 | | -# https://jacobian.org/til/github-actions-poetry/ |
12 | 11 | jobs: |
13 | | - flake8-lint: |
| 12 | + run-tests: |
| 13 | + name: python |
14 | 14 | runs-on: ubuntu-latest |
15 | | - name: Lint |
16 | | - steps: |
17 | | - - name: Check out source repository |
18 | | - uses: actions/checkout@v2 |
19 | | - - name: Set up Python environment |
20 | | - uses: actions/setup-python@v1 |
21 | | - with: |
22 | | - python-version: "3.9" |
23 | | - - name: flake8 Lint |
24 | | - uses: py-actions/flake8@v2 |
25 | | - with: |
26 | | - # custom ignores start at w504, before are the default ones |
27 | | - ignore: "E121,E123,E126,E226,E24,E704,W503,W504,E203,E402,E501,F401,F841" |
28 | | - exclude: "logs/*,data/*,furuta/logging/protobuf/*" |
29 | 15 |
|
30 | | - test: |
31 | | - runs-on: ubuntu-latest |
32 | 16 | steps: |
33 | 17 | - uses: actions/checkout@v4 |
34 | 18 |
|
35 | | - # If you wanted to use multiple Python versions, you'd have specify a matrix in the job and |
36 | | - # reference the matrixe python version here. |
37 | | - - uses: actions/setup-python@v5 |
38 | | - with: |
39 | | - python-version: 3.9 |
40 | | - |
41 | | - # Cache the installation of Poetry itself, e.g. the next step. This prevents the workflow |
42 | | - # from installing Poetry every time, which can be slow. Note the use of the Poetry version |
43 | | - # number in the cache key, and the "-0" suffix: this allows you to invalidate the cache |
44 | | - # manually if/when you want to upgrade Poetry, or if something goes wrong. This could be |
45 | | - # mildly cleaner by using an environment variable, but I don't really care. |
46 | | - - name: cache poetry install |
47 | | - uses: actions/cache@v4 |
48 | | - with: |
49 | | - path: ~/.local |
50 | | - key: poetry-1.4.0-0 |
51 | | - |
52 | | - # Install Poetry. You could do this manually, or there are several actions that do this. |
53 | | - # `snok/install-poetry` seems to be minimal yet complete, and really just calls out to |
54 | | - # Poetry's default install script, which feels correct. I pin the Poetry version here |
55 | | - # because Poetry does occasionally change APIs between versions and I don't want my |
56 | | - # actions to break if it does. |
57 | | - # |
58 | | - # The key configuration value here is `virtualenvs-in-project: true`: this creates the |
59 | | - # venv as a `.venv` in your testing directory, which allows the next step to easily |
60 | | - # cache it. |
61 | | - - uses: snok/install-poetry@v1 |
62 | | - with: |
63 | | - version: 1.4.0 |
64 | | - virtualenvs-create: true |
65 | | - virtualenvs-in-project: true |
66 | | - |
67 | | - # Cache your dependencies (i.e. all the stuff in your `pyproject.toml`). Note the cache |
68 | | - # key: if you're using multiple Python versions, or multiple OSes, you'd need to include |
69 | | - # them in the cache key. I'm not, so it can be simple and just depend on the poetry.lock. |
70 | | - - name: cache deps |
71 | | - id: cache-deps |
72 | | - uses: actions/cache@v4 |
| 19 | + - name: Install uv |
| 20 | + uses: astral-sh/setup-uv@v6 |
73 | 21 | with: |
74 | | - path: .venv |
75 | | - key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} |
| 22 | + enable-cache: true |
76 | 23 |
|
77 | | - # Install dependencies. `--no-root` means "install all dependencies but not the project |
78 | | - # itself", which is what you want to avoid caching _your_ code. The `if` statement |
79 | | - # ensures this only runs on a cache miss. |
80 | | - - run: poetry install --no-interaction --no-root |
81 | | - if: steps.cache-deps.outputs.cache-hit != 'true' |
| 24 | + - name: Install the project |
| 25 | + run: uv sync --locked --all-extras --dev |
82 | 26 |
|
83 | | - # Now install _your_ project. This isn't necessary for many types of projects -- particularly |
84 | | - # things like Django apps don't need this. But it's a good idea since it fully-exercises the |
85 | | - # pyproject.toml and makes that if you add things like console-scripts at some point that |
86 | | - # they'll be installed and working. |
87 | | - - run: poetry install --no-interaction |
| 27 | + - name: Lint |
| 28 | + run: uv run pre-commit run --all-files --config ./.pre-commit-config.yaml |
88 | 29 |
|
89 | | - # And finally run tests. I'm using pytest and all my pytest config is in my `pyproject.toml` |
90 | | - # so this line is super-simple. But it could be as complex as you need. |
91 | | - - run: poetry run pytest |
| 30 | + - name: Run tests |
| 31 | + run: uv run pytest tests |
0 commit comments