Skip to content

Commit efe703d

Browse files
authored
ci(setup-python): Use v3/v4's caching method (#398)
1 parent 051f185 commit efe703d

File tree

2 files changed

+20
-87
lines changed

2 files changed

+20
-87
lines changed

.github/workflows/docs.yml

+10-47
Original file line numberDiff line numberDiff line change
@@ -34,61 +34,24 @@ jobs:
3434
if: steps.changes.outputs.docs == 'true' || steps.changes.outputs.root_docs == 'true' || steps.changes.outputs.python_files == 'true'
3535
run: echo "PUBLISH=$(echo true)" >> $GITHUB_ENV
3636

37-
- name: Set up Python ${{ matrix.python-version }}
38-
uses: actions/setup-python@v3
39-
if: env.PUBLISH == 'true'
40-
with:
41-
python-version: ${{ matrix.python-version }}
42-
43-
- name: Get full Python version
44-
id: full-python-version
45-
shell: bash
46-
if: env.PUBLISH == 'true'
47-
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
48-
4937
- name: Install poetry
50-
if: env.PUBLISH == 'true'
51-
run: |
52-
curl -O -sSL https://install.python-poetry.org/install-poetry.py
53-
python install-poetry.py -y --version 1.1.14
54-
echo "PATH=${HOME}/.poetry/bin:${PATH}" >> $GITHUB_ENV
55-
rm install-poetry.py
56-
57-
- name: Add ~/.local/bin to PATH
58-
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
59-
if: env.PUBLISH == 'true'
38+
run: pipx install "poetry==1.1.14"
6039

61-
- name: Get poetry cache paths from config
62-
if: env.PUBLISH == 'true'
63-
run: |
64-
echo "poetry_virtualenvs_path=$(poetry config --list | sed -n 's/.*virtualenvs.path = .* # //p' | sed -e 's/^\"//' -e 's/\"$//')" >> $GITHUB_ENV
65-
echo "poetry_virtualenvs_path=$(poetry config --list | sed -n 's/.*virtualenvs.path = .* # //p' | sed -e 's/^\"//' -e 's/\"$//')" >> $GITHUB_ENV
66-
67-
- name: Configure poetry
68-
shell: bash
69-
if: env.PUBLISH == 'true'
70-
run: poetry config virtualenvs.in-project true
71-
72-
- name: Set up cache
73-
uses: actions/cache@v3
74-
if: env.PUBLISH == 'true'
75-
id: cache
40+
- name: Set up Python ${{ matrix.python-version }}
41+
uses: actions/setup-python@v4
7642
with:
77-
path: |
78-
.venv
79-
{{ env.poetry_cache_dir }}
80-
{{ env.poetry_virtualenvs_path }}
81-
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
82-
83-
- name: Ensure cache is healthy
84-
if: steps.cache.outputs.cache-hit == 'true' && env.PUBLISH == 'true'
85-
shell: bash
86-
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
43+
python-version: ${{ matrix.python-version }}
44+
cache: 'poetry'
8745

8846
- name: Install dependencies [w/ docs]
8947
if: env.PUBLISH == 'true'
9048
run: poetry install --extras "docs lint"
9149

50+
- name: Print python versions
51+
run: |
52+
python -V
53+
poetry run python -V
54+
9255
- name: Build documentation
9356
if: env.PUBLISH == 'true'
9457
run: |

.github/workflows/tests.yml

+10-40
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,14 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v3
1717

18-
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v3
20-
with:
21-
python-version: ${{ matrix.python-version }}
22-
23-
- name: Get full Python version
24-
id: full-python-version
25-
shell: bash
26-
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
27-
2818
- name: Install poetry
29-
run: |
30-
curl -O -sSL https://install.python-poetry.org/install-poetry.py
31-
python install-poetry.py -y --version 1.1.14
32-
echo "PATH=${HOME}/.poetry/bin:${PATH}" >> $GITHUB_ENV
33-
rm install-poetry.py
34-
35-
- name: Add ~/.local/bin to PATH
36-
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
37-
38-
- name: Get poetry cache paths from config
39-
run: |
40-
echo "poetry_virtualenvs_path=$(poetry config --list | sed -n 's/.*virtualenvs.path = .* # //p' | sed -e 's/^\"//' -e 's/\"$//')" >> $GITHUB_ENV
41-
echo "poetry_virtualenvs_path=$(poetry config --list | sed -n 's/.*virtualenvs.path = .* # //p' | sed -e 's/^\"//' -e 's/\"$//')" >> $GITHUB_ENV
42-
43-
- name: Configure poetry
44-
shell: bash
45-
run: poetry config virtualenvs.in-project true
19+
run: pipx install "poetry==1.1.14"
4620

47-
- name: Set up poetry cache
48-
uses: actions/cache@v3
49-
id: cache
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v4
5023
with:
51-
path: |
52-
.venv
53-
${{ env.poetry_cache_dir }}
54-
${{ env.poetry_virtualenvs_path }}
55-
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
56-
57-
- name: Ensure cache is healthy
58-
if: steps.cache.outputs.cache-hit == 'true'
59-
shell: bash
60-
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
24+
python-version: ${{ matrix.python-version }}
25+
cache: 'poetry'
6126

6227
- name: Setup tmux build cache for tmux ${{ matrix.tmux-version }}
6328
id: tmux-build-cache
@@ -92,6 +57,11 @@ jobs:
9257
- name: Lint with mypy
9358
run: poetry run mypy .
9459

60+
- name: Print python versions
61+
run: |
62+
python -V
63+
poetry run python -V
64+
9565
- name: Test with pytest
9666
continue-on-error: ${{ matrix.tmux-version == 'master' }}
9767
run: |

0 commit comments

Comments
 (0)