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