Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gh640/233a6daf68e9e937115371c0ecd39c61 to your computer and use it in GitHub Desktop.
Save gh640/233a6daf68e9e937115371c0ecd39c61 to your computer and use it in GitHub Desktop.
Sample: Use Python Poetry cache on GitHub Actions workflow
name: Use Python Poetry cache on GitHub Actions workflow
on:
push:
branches:
- main
env:
PYTHON_VERSION: "3.11"
POETRY_VERSION: "1.4.2"
POETRY_URL: https://install.python-poetry.org
jobs:
use_cache:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
id: setup_python
# Poetry cache depends on OS, Python version and Poetry version.
- name: Cache Poetry cache
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
# virtualenv cache should depends on OS, Python version and `poetry.lock` (and optionally workflow files).
- name: Cache Packages
uses: actions/cache@v3
with:
path: ~/.local
key: poetry-local-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
- name: Install Poetry ${{ env.POETRY_VERSION }}
run: |
curl -sSL ${{ env.POETRY_URL }} | python - --version ${{ env.POETRY_VERSION }}
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install Dependencies
run: poetry install
# Write actual actions here.
@hongbo-miao
Copy link

You are welcome, @radzek15 ! However, you should run poetry lock --no-update locally and commit the change in your git instead of running in the CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment