Skip to content

Commit

Permalink
ci(python): Bump CI to use setup-python@v3/4 caching
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Aug 16, 2022
1 parent 8d20c21 commit 0503d3d
Showing 1 changed file with 6 additions and 49 deletions.
55 changes: 6 additions & 49 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,60 +37,16 @@ jobs:
if: steps.changes.outputs.docs == 'true' || steps.changes.outputs.root_docs == 'true' || steps.changes.outputs.python_files == 'true'
run: echo "PUBLISH=$(echo true)" >> $GITHUB_ENV

- name: Set up Python ${{ matrix.python-version }}
if: env.PUBLISH == 'true'
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Get full Python version
if: env.PUBLISH == 'true'
id: full-python-version
shell: bash
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")

- name: Install poetry
if: env.PUBLISH == 'true'
run: |
curl -O -sSL https://install.python-poetry.org/install-poetry.py
python install-poetry.py -y --version 1.1.14
echo "PATH=${HOME}/.poetry/bin:${PATH}" >> $GITHUB_ENV
rm install-poetry.py
- name: Add ~/.local/bin to PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
run: pipx install "poetry==1.1.14"

- name: Get poetry cache paths from config
if: env.PUBLISH == 'true'
run: |
echo "poetry_cache_dir=$(poetry config --list | sed -n 's/.*cache-dir = //p' | sed -e 's/^\"//' -e 's/\"$//')" >> $GITHUB_ENV
echo "poetry_virtualenvs_path=$(poetry config --list | sed -n 's/.*virtualenvs.path = .* # //p' | sed -e 's/^\"//' -e 's/\"$//')" >> $GITHUB_ENV
- name: Configure poetry
if: env.PUBLISH == 'true'
shell: bash
run: poetry config virtualenvs.in-project true

- name: Set up cache
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
if: env.PUBLISH == 'true'
uses: actions/cache@v3
id: cache
with:
path: |
.venv
{{ env.poetry_cache_dir }}
{{ env.poetry_virtualenvs_path }}
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'
shell: bash
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv

- name: Upgrade pip
if: env.PUBLISH == 'true'
shell: bash
run: poetry run python -m pip install pip -U
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Install dependencies [w/ docs]
if: env.PUBLISH == 'true'
Expand All @@ -115,6 +71,7 @@ jobs:
SOURCE_DIR: '_build/html' # optional: defaults to entire repository

- name: Purge cache on Cloudflare
if: env.PUBLISH == 'true'
uses: jakejarvis/cloudflare-purge-action@v0.3.0
env:
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
Expand Down

0 comments on commit 0503d3d

Please sign in to comment.