Skip to content

Commit

Permalink
ci: Use setup-python v3/4's new caching system (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Aug 16, 2022
1 parent 9d19f42 commit f949e3f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 79 deletions.
50 changes: 10 additions & 40 deletions .github/workflows/docs.yml
Expand Up @@ -34,53 +34,23 @@ 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 }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Get full Python version
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
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
run: pipx install "poetry==1.1.14"

- name: Add ~/.local/bin to PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Get poetry cache paths from config
run: |
echo "poetry_virtualenvs_path=$(poetry config --list | sed -n 's/.*virtualenvs.path = .* # //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
shell: bash
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v3
id: cache
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
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
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Install dependencies [w/ docs]
run: poetry install --extras "docs lint"

- name: Print python versions
run: |
python -V
poetry run python -V
- name: Build documentation
run: |
pushd docs; make SPHINXBUILD='poetry run sphinx-build' html; popd
Expand Down
49 changes: 10 additions & 39 deletions .github/workflows/tests.yml
Expand Up @@ -12,53 +12,24 @@ jobs:
python-version: ["3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Get full Python version
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
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

- name: Get poetry cache paths from config
run: |
echo "poetry_virtualenvs_path=$(poetry config --list | sed -n 's/.*virtualenvs.path = .* # //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
shell: bash
run: poetry config virtualenvs.in-project true
run: pipx install "poetry==1.1.14"

- name: Set up cache
uses: actions/cache@v3
id: cache
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
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
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Install dependencies
run: poetry install -E "docs test coverage lint format"

- name: Print python versions
run: |
python -V
poetry run python -V
- name: Lint with flake8
run: poetry run flake8

Expand Down

0 comments on commit f949e3f

Please sign in to comment.