1+ # This workflow will install Python dependencies, run tests and lint with a single version of Python
2+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+ name : NHL-API-PY
5+
6+ on :
7+ push :
8+ branches : [ "main" ]
9+ pull_request :
10+ branches : [ "main" ]
11+
12+ permissions :
13+ contents : read
14+
15+ jobs :
16+ test :
17+ runs-on : ubuntu-latest
18+ steps :
19+ - uses : actions/checkout@v4
20+
21+ # If you wanted to use multiple Python versions, you'd have specify a matrix in the job and
22+ # reference the matrixe python version here.
23+ - uses : actions/setup-python@v5
24+ with :
25+ python-version : 3.9.18
26+
27+ # Cache the installation of Poetry itself, e.g. the next step. This prevents the workflow
28+ # from installing Poetry every time, which can be slow. Note the use of the Poetry version
29+ # number in the cache key, and the "-0" suffix: this allows you to invalidate the cache
30+ # manually if/when you want to upgrade Poetry, or if something goes wrong. This could be
31+ # mildly cleaner by using an environment variable, but I don't really care.
32+ - name : cache poetry install
33+ uses : actions/cache@v4
34+ with :
35+ path : ~/.local
36+ key : poetry-1.5.1-0
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.5.1
50+ virtualenvs-create : true
51+ virtualenvs-in-project : true
52+
53+ # Cache your dependencies (i.e. all the stuff in your `pyproject.toml`). Note the cache
54+ # key: if you're using multiple Python versions, or multiple OSes, you'd need to include
55+ # them in the cache key. I'm not, so it can be simple and just depend on the poetry.lock.
56+ - name : cache deps
57+ id : cache-deps
58+ uses : actions/cache@v3
59+ with :
60+ path : .venv
61+ key : pydeps-${{ hashFiles('**/poetry.lock') }}
62+
63+ # Install dependencies. `--no-root` means "install all dependencies but not the project
64+ # itself", which is what you want to avoid caching _your_ code. The `if` statement
65+ # ensures this only runs on a cache miss.
66+ - run : poetry install --no-interaction --no-root
67+ if : steps.cache-deps.outputs.cache-hit != 'true'
68+
69+ # Now install _your_ project. This isn't necessary for many types of projects -- particularly
70+ # things like Django apps don't need this. But it's a good idea since it fully-exercises the
71+ # pyproject.toml and makes that if you add things like console-scripts at some point that
72+ # they'll be installed and working.
73+ - run : poetry install --no-interaction
74+
75+ # And finally run tests. I'm using pytest and all my pytest config is in my `pyproject.toml`
76+ # so this line is super-simple. But it could be as complex as you need.
77+ - run : poetry run pytest
78+
79+ # run a check for black
80+ - name : poetry run black . --check
81+ run : poetry run black . --check
82+
83+ # run a lint check with ruff
84+ - name : poetry run ruff check .
85+ run : poetry run ruff check .
0 commit comments