Skip to content

Commit f13cd87

Browse files
committed
initial commit
0 parents  commit f13cd87

4 files changed

Lines changed: 134 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 D Software Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# GitHub Action - Setup and Cache Python Poetry
2+
3+
This action simplifies the setup and caching of Poetry,
4+
and provides the following functionality for GitHub Actions users:
5+
6+
When a job using this action runs for the first time, this action will download Poetry and the required project
7+
dependencies, then save it to the cache.
8+
9+
For the following runs (whether it's on a different
10+
workflow/job [with the same cached commit](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache))
11+
this action will restore the cache, which is much faster than downloading everything again.
12+
13+
## Basic Usage
14+
15+
* Make sure you have `pyproject.toml`, `poetry.lock`.
16+
17+
```yaml
18+
name: ci
19+
20+
on:
21+
push:
22+
branches: [ master ]
23+
24+
jobs:
25+
test:
26+
runs-on: ubuntu-latest
27+
steps:
28+
# Deal with environment setup and caching
29+
- name: Check out the repository
30+
uses: actions/checkout@v4
31+
- name: "Setup Python, Poetry and Dependencies"
32+
uses: dsoftwareinc/setup-python-poetry-action@v1
33+
with:
34+
python-version: 3.11
35+
poetry-version: 1.7.1
36+
37+
# Run what you want in the poetry environment
38+
- name: Run tests
39+
run: |
40+
poetry run python manage.py test
41+
```
42+
43+
## Notes
44+
45+
* You can see the list of cache entries by going to:
46+
`Repo` -> `Actions` tab -> `Caches` under `Managements` (left navbar, at the bottom).
47+
* [Don't forget the limitation of cache](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy).
48+
49+
## Dependencies
50+
51+
* Python setup using [`actions/setup-python`](https://github.com/actions/setup-python).
52+
* Poetry install using [`snok/install-poetry`](https://github.com/snok/install-poetry).
53+
* Poetry binary and dependency caching using [`actions/cache`](https://github.com/actions/cache).
54+
55+
## License
56+
57+
The scripts and documentation in this project are released under the [MIT License](LICENSE).

action.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: "Setup Python Poetry with Cache"
2+
description: "Setup Python & Poetry, using cache for dependencies and Poetry installation."
3+
branding:
4+
icon: "play"
5+
color: "purple"
6+
7+
inputs:
8+
python-version:
9+
description: Python Version
10+
required: true
11+
poetry-version:
12+
description: Poetry Version
13+
required: true
14+
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Set up python ${{ inputs.python-version }}
19+
id: setup-python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ inputs.python-version }}
23+
24+
# Install Poetry
25+
- name: Load cached Poetry Binary
26+
id: cached-poetry-binary
27+
uses: actions/cache@v3
28+
with:
29+
path: ~/.local
30+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ inputs.poetry-version }}
31+
32+
- name: Install Poetry
33+
uses: snok/install-poetry@v1
34+
with:
35+
version: ${{ inputs.poetry-version }}
36+
virtualenvs-create: true
37+
virtualenvs-in-project: true
38+
39+
# Load cached venv if cache exists
40+
- name: Load cached venv
41+
id: cached-poetry-dependencies
42+
uses: actions/cache@v3
43+
with:
44+
path: .venv
45+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
46+
# If the exact match is not found, the cache will be restored from the key with the prefix.
47+
# Note cache-hit returns false in this case, so the below step will run
48+
restore-keys: |
49+
venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-
50+
51+
# Install dependencies on cache miss
52+
- name: Install dependencies
53+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
54+
shell: sh
55+
run: poetry install --no-interaction --no-root

0 commit comments

Comments
 (0)