1+ # inspired by https://jacobian.org/til/github-actions-poetry/
2+
3+ on :
4+ push :
5+ branches : [main]
6+ pull_request :
7+
8+ env :
9+ POETRY_VERSION : 1.8.3
10+ FMP_API_KEY : ${{ secrets.FMP_API_KEY }}
11+ jobs :
12+ build :
13+ runs-on : ${{ matrix.os }}
14+ strategy :
15+ max-parallel : 1
16+ fail-fast : false
17+ matrix :
18+ python-version : ["3.12"]
19+ os : [ubuntu-latest, macOS-latest]
20+ env :
21+ POETRY_VIRTUALENVS_IN_PROJECT : true
22+ steps :
23+ - uses : actions/checkout@v3
24+ - uses : actions/setup-python@v5
25+ with :
26+ python-version : ${{ matrix.python-version }}
27+
28+ # Cache the installation of Poetry itself, e.g. the next step. This prevents the workflow
29+ # from installing Poetry every time, which can be slow. Note the use of the Poetry version
30+ # number in the cache key, and the "-0" suffix: this allows you to invalidate the cache
31+ # manually if/when you want to upgrade Poetry, or if something goes wrong.
32+ - name : cache poetry install
33+ uses : actions/cache@v4
34+ with :
35+ path : ~/.local
36+ key : poetry-cache-${{ runner.os }}-${{ matrix.python-version }}-${{ env.POETRY_VERSION }}
37+
38+ # Install Poetry. You could do this manually, or there are several actions that do this.
39+ # `snok/install-poetry` seems to be minimal yet complete, and really just calls out to
40+ # Poetry's default install script, which feels correct. I pin the Poetry version here
41+ # because Poetry does occasionally change APIs between versions and I don't want my
42+ # actions to break if it does.
43+ #
44+ # The key configuration value here is `virtualenvs-in-project: true`: this creates the
45+ # venv as a `.venv` in your testing directory, which allows the next step to easily
46+ # cache it.
47+ - uses : snok/install-poetry@v1
48+ with :
49+ version : 1.8.3
50+ virtualenvs-create : true
51+ virtualenvs-in-project : true
52+
53+ # Cache your dependencies (i.e. all the stuff in your `pyproject.toml`)
54+ - name : cache venv
55+ uses : actions/cache@v4
56+ with :
57+ path : .venv
58+ key : venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
59+ - run : poetry install --no-interaction --no-root
60+ if : steps.cache-deps.outputs.cache-hit != 'true'
61+ - run : poetry install --no-interaction
62+ - run : poetry run ruff check --fix
63+ - run : poetry run pytest
0 commit comments