Skip to content

Commit

Permalink
ci/gha: simplify poetry setup and caching
Browse files Browse the repository at this point in the history
(cherry picked from commit 2f6a553)
  • Loading branch information
abn committed Mar 24, 2024
1 parent 392adbf commit cc36871
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 43 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
cache: poetry

- name: Setup Node
uses: actions/setup-node@v4
Expand All @@ -54,7 +55,7 @@ jobs:

- name: Fetch Documentation
run: |
python -m pip install poetry
pipx install poetry
poetry install --no-root --only main
poetry run python bin/website build --local ./poetry
Expand Down
39 changes: 7 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,14 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Bootstrap poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Get full Python version
id: full-python-version
run: echo version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") >> $GITHUB_OUTPUT

- name: Bootstrap poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y
- name: Update PATH
if: ${{ matrix.os != 'Windows' }}
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Update Path for Windows
if: ${{ matrix.os == 'Windows' }}
run: echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH
cache: poetry

- name: Enable long paths for git on Windows
if: ${{ matrix.os == 'Windows' }}
Expand All @@ -71,23 +59,10 @@ jobs:
run: git config --system core.longpaths true

- name: Configure poetry
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v4
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}

- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
run: |
# `timeout` is not available on macOS, so we define a custom function.
[ "$(command -v timeout)" ] || function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
# Using `timeout` is a safeguard against the Poetry command hanging for some reason.
timeout 10s poetry run pip --version || rm -rf .venv
poetry config virtualenvs.in-project true
poetry config virtualenvs.options.no-pip true
poetry config virtualenvs.options.no-setuptools true
- name: Check lock file
run: poetry check --lock
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y
run: pipx install poetry

- name: Update PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: poetry

- name: Build project for distribution
run: poetry build
Expand Down

0 comments on commit cc36871

Please sign in to comment.