Skip to content

Commit

Permalink
Ci tweaks (mostly caching) (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianPugh authored Sep 3, 2024
1 parent cd0ecda commit 948a6f3
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 65 deletions.
69 changes: 36 additions & 33 deletions .github/workflows/build_wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,45 @@ on:
jobs:
build_sdist:
name: "sdist"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
runs-on: ubuntu-latest
env:
PYTHON: 3.12
POETRY_HOME: "~/poetry"

steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up python 3.12
- name: Set up python ${{ env.PYTHON }}
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: ${{ env.PYTHON }}

- name: Cache Poetry Install
uses: actions/cache@v4
id: cached-poetry
with:
path: ${{ env.POETRY_HOME }}
key: poetry-cache-${{ runner.os }}-${{ env.PYTHON }}-${{ hashFiles('.github/workflows/build_wheels.yaml') }}

- name: Install poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1

- name: Add Poetry to PATH # Needs to be separate from install-poetry because cache.
run: |
echo "$POETRY_HOME/bin" >> $GITHUB_PATH
- name: Configure Poetry # Needs to be separate from install-poetry because cache.
run: |
poetry self add poetry-dynamic-versioning[plugin]
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: Build sdist
run: |
poetry self add "poetry-dynamic-versioning[plugin]"
poetry build --format=sdist
- uses: actions/upload-artifact@v4
Expand All @@ -52,6 +69,8 @@ jobs:
- os: windows-latest
cibw_build: "cp38-*"
cibw_archs: "ARM64"
env:
PYTHON: 3.12

steps:
- name: "Set environment variables (Windows)"
Expand All @@ -69,17 +88,10 @@ jobs:
with:
fetch-depth: 0

- name: Set up python 3.12
- name: Set up python ${{ env.PYTHON }}
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: false
virtualenvs-in-project: false
installer-parallel: false # Currently there seems to be some race-condition in windows
python-version: ${{ env.PYTHON }}

- name: Build wheels
uses: pypa/[email protected]
Expand All @@ -104,6 +116,8 @@ jobs:
os: [ubuntu-latest]
cibw_build: ["cp38-*", "cp39-*", "cp310-*", "cp311-*", "cp312-*"]
cibw_archs: ["x86_64", "i686", "aarch64", "ppc64le"]
env:
PYTHON: 3.12

steps:
- name: Check out repository
Expand All @@ -122,16 +136,10 @@ jobs:
with:
platforms: all

- name: Set up python 3.12
- name: Set up python ${{ env.PYTHON }}
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: false
virtualenvs-in-project: false
python-version: ${{ env.PYTHON }}

- name: Build wheels
uses: pypa/[email protected]
Expand All @@ -156,6 +164,7 @@ jobs:
cibw_build: ["cp38-*", "cp39-*", "cp310-*", "cp311-*", "cp312-*"]
cibw_archs: ["x86_64"]
env:
PYTHON: 3.12
SYSTEM_VERSION_COMPAT: 0 # https://github.com/actions/setup-python/issues/469#issuecomment-1192522949
steps:
- name: Check out repository
Expand All @@ -168,16 +177,10 @@ jobs:
run: echo "CIBW_BUILD_SANITIZED=$(echo '${{ matrix.cibw_build }}' | sed 's/\*/_/g')" >> $GITHUB_ENV
shell: bash

- name: Set up python 3.12
- name: Set up python ${{ env.PYTHON }}
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: false
virtualenvs-in-project: false
python-version: ${{ env.PYTHON }}

- name: Build wheels
uses: pypa/[email protected]
Expand Down
47 changes: 26 additions & 21 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,52 @@ on:
jobs:
build:
runs-on: ubuntu-latest
env:
PYTHON: 3.12
POETRY_HOME: "~/poetry"

steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Includes getting tags

- name: Cache $HOME/.local # Significantly speeds up Poetry Install
uses: actions/cache@v4
- name: Set up python ${{ env.PYTHON }}
id: setup-python
uses: actions/setup-python@v5
with:
path: ~/.local
key: dotlocal-${{ runner.os }}-${{ hashFiles('.github/workflows/deploy.yml') }}
python-version: ${{ env.PYTHON }}

- name: Set up python 3.12
uses: actions/setup-python@v5
- name: Cache Poetry Install
uses: actions/cache@v4
id: cached-poetry
with:
python-version: "3.12"
path: ${{ env.POETRY_HOME }}
key: poetry-cache-${{ runner.os }}-${{ env.PYTHON }}-${{ hashFiles('.github/workflows/deploy.yaml') }}

- name: Install poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
if: steps.cached-poetry.outputs.cache-hit != 'true'

- name: Add Poetry to PATH # Needs to be separate from install-poetry because cache.
run: |
echo "$POETRY_HOME/bin" >> $GITHUB_PATH
- name: Add Poetry Plugins
- name: Configure Poetry # Needs to be separate from install-poetry because cache.
run: |
poetry self add poetry-dynamic-versioning[plugin]
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: Load cached venv
id: cached-poetry-dependencies
- name: Cache venv
uses: actions/cache@v4
id: cached-venv
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --without=dev
path: .venv/
key: venv-cache-${{ runner.os }}-${{ env.PYTHON }}-${{ hashFiles('.github/workflows/deploy.yaml') }}

- name: Install project
run: poetry install --no-interaction --without=dev
run: poetry install --no-interaction

- name: Build package
run: poetry build
Expand Down
40 changes: 29 additions & 11 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
POETRY_HOME: "~/poetry"

steps:
- name: Set OS Environment Variables (Windows)
Expand All @@ -44,31 +45,48 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Cache $HOME/.local # Significantly speeds up Poetry Install
uses: actions/cache@v4
with:
path: ~/.local
key: dotlocal-${{ runner.os }}-${{matrix.python-version}}-${{ hashFiles('.github/workflows/tests.yaml') }}

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

- name: Cache Poetry Install
uses: actions/cache@v4
id: cached-poetry
with:
path: ${{ env.POETRY_HOME }}
key: poetry-cache-${{ runner.os }}-${{ env.PYTHON }}-${{ hashFiles('.github/workflows/tests.yaml') }}

- name: Install poetry
uses: snok/install-poetry@v1
if: steps.cached-poetry.outputs.cache-hit != 'true'

- name: Add Poetry to PATH # Needs to be separate from install-poetry because cache.
run: |
echo "$POETRY_HOME/bin" >> $GITHUB_PATH
- name: Configure Poetry # Needs to be separate from install-poetry because cache.
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
poetry config installer.parallel ${{ runner.os != 'Windows' }} # Currently there seems to be some race-condition in windows
- name: Cache venv
uses: actions/cache@v4
id: cached-venv
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: false # Currently there seems to be some race-condition in windows
path: .venv/
key: venv-cache-${{ runner.os }}-${{ env.PYTHON }}-${{ hashFiles('.github/workflows/tests.yaml') }}

- name: Install library
run: poetry install --no-interaction

- uses: actions/cache@v4
- name: Cache pre-commit
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit/
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
key: pre-commit-${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Pre-commit run
run: |
Expand Down

0 comments on commit 948a6f3

Please sign in to comment.