Skip to content

Commit 794b081

Browse files
authored
Update CI to cache pipx poetry app install (python-ring-doorbell#372)
1 parent ce921ad commit 794b081

2 files changed

Lines changed: 109 additions & 108 deletions

File tree

.github/actions/setup/action.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
name: Setup Environment
3+
description: Install requested pipx dependencies, configure the system python, and install poetry and the package dependencies
4+
5+
inputs:
6+
poetry-install-options:
7+
default: ""
8+
poetry-version:
9+
default: 1.6.1
10+
python-version:
11+
required: true
12+
cache-pre-commit:
13+
default: false
14+
15+
runs:
16+
using: composite
17+
steps:
18+
- uses: "actions/setup-python@v5"
19+
id: setup-python
20+
with:
21+
python-version: "${{ inputs.python-version }}"
22+
23+
- name: Setup pipx environment Variables
24+
id: pipx-env-setup
25+
# pipx default home and bin dir are not writable by the cache action
26+
# so override them here and add the bin dir to PATH for later steps.
27+
# This also ensures the pipx cache only contains poetry
28+
run: |
29+
SEP="${{ !startsWith(runner.os, 'windows') && '/' || '\\' }}"
30+
PIPX_CACHE="${{ github.workspace }}${SEP}pipx_cache"
31+
echo "pipx-cache-path=${PIPX_CACHE}" >> $GITHUB_OUTPUT
32+
echo "pipx-version=$(pipx --version)" >> $GITHUB_OUTPUT
33+
echo "PIPX_HOME=${PIPX_CACHE}${SEP}home" >> $GITHUB_ENV
34+
echo "PIPX_BIN_DIR=${PIPX_CACHE}${SEP}bin" >> $GITHUB_ENV
35+
echo "PIPX_MAN_DIR=${PIPX_CACHE}${SEP}man" >> $GITHUB_ENV
36+
echo "${PIPX_CACHE}${SEP}bin" >> $GITHUB_PATH
37+
shell: bash
38+
39+
- name: Pipx cache
40+
id: pipx-cache
41+
uses: actions/cache@v4
42+
with:
43+
path: ${{ steps.pipx-env-setup.outputs.pipx-cache-path }}
44+
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-poetry-${{ inputs.poetry-version }}
45+
46+
- name: Install poetry
47+
if: steps.pipx-cache.outputs.cache-hit != 'true'
48+
id: install-poetry
49+
shell: bash
50+
run: |-
51+
pipx install poetry==${{ inputs.poetry-version }} --python "${{ steps.setup-python.outputs.python-path }}"
52+
53+
- name: Read poetry cache location
54+
id: poetry-cache-location
55+
shell: bash
56+
run: |-
57+
echo "poetry-venv-location=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT
58+
59+
- uses: actions/cache@v4
60+
name: Poetry cache
61+
with:
62+
path: |
63+
${{ steps.poetry-cache-location.outputs.poetry-venv-location }}
64+
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}-options-${{ inputs.poetry-install-options }}
65+
66+
- name: "Poetry install"
67+
shell: bash
68+
run: |
69+
poetry install ${{ inputs.poetry-install-options }}
70+
71+
- name: Read pre-commit version
72+
if: inputs.cache-pre-commit == 'true'
73+
id: pre-commit-version
74+
shell: bash
75+
run: >-
76+
echo "pre-commit-version=$(poetry run pre-commit -V | awk '{print $2}')" >> $GITHUB_OUTPUT
77+
78+
- uses: actions/cache@v4
79+
if: inputs.cache-pre-commit == 'true'
80+
name: Pre-commit cache
81+
with:
82+
path: ~/.cache/pre-commit/
83+
key: ${{ runner.os }}-pre-commit-${{ steps.pre-commit-version.outputs.pre-commit-version }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}

.github/workflows/ci.yml

Lines changed: 26 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ on:
77
branches: ["master"]
88

99
env:
10-
POETRY_VERSION: 1.7.1
11-
TOX_VERSION: 4.11.3
12-
COVERALLS_VERSION: 3.3.1
10+
POETRY_VERSION: 1.8.2
1311

1412
jobs:
1513
linting:
@@ -20,44 +18,16 @@ jobs:
2018
python-version: ["3.12"]
2119
steps:
2220
- uses: "actions/checkout@v4"
23-
- uses: "actions/setup-python@v5"
24-
id: setup-python
21+
- name: Setup environment
22+
uses: ./.github/actions/setup
2523
with:
26-
python-version: "${{ matrix.python-version }}"
27-
cache: 'pip'
28-
cache-dependency-path: |
29-
pyproject.toml
30-
.github/workflows/ci.yml
31-
- name: Install dependencies
32-
run: |
33-
pipx install poetry==$POETRY_VERSION
34-
pipx install tox==$TOX_VERSION
35-
- name: Read poetry cache location
36-
id: poetry-cache-location
37-
shell: bash
38-
run: |
39-
echo "POETRY_VENV_LOCATION=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT
40-
- name: Poetry cache
41-
uses: actions/cache@v3
42-
with:
43-
path: |
44-
${{ steps.poetry-cache-location.outputs.POETRY_VENV_LOCATION }}
45-
key: linting-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}
46-
- name: Read pre-commit version
47-
id: pre-commit-version
48-
run: >-
49-
echo "PRE_COMMIT_VERSION=$(poetry run pre-commit -V | awk '{print $2}')" >> $GITHUB_OUTPUT
50-
- name: Pre-commit cache
51-
uses: actions/cache@v3
52-
with:
53-
path: ~/.cache/pre-commit/
54-
key: ${{ runner.os }}-pre-commit-${{ steps.pre-commit-version.outputs.PRE_COMMIT_VERSION }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
55-
- name: Lint with tox
24+
python-version: ${{ matrix.python-version }}
25+
poetry-version: ${{ env.POETRY_VERSION }}
26+
poetry-install-options: "--sync --extras listen --verbose"
27+
cache-pre-commit: true
28+
- name: "Run pre-commit checks"
5629
run: |
57-
poetry env use python
58-
tox
59-
env:
60-
TOXENV: lint
30+
poetry run pre-commit run --all-files
6131
6232
docs:
6333
name: "Build docs"
@@ -68,34 +38,15 @@ jobs:
6838
python-version: ["3.12"]
6939
steps:
7040
- uses: "actions/checkout@v4"
71-
- uses: "actions/setup-python@v5"
72-
id: setup-python
73-
with:
74-
python-version: "${{ matrix.python-version }}"
75-
cache: 'pip'
76-
cache-dependency-path: |
77-
pyproject.toml
78-
.github/workflows/ci.yml
79-
- name: Install dependencies
80-
run: |
81-
pipx install poetry==$POETRY_VERSION
82-
pipx install tox==$TOX_VERSION
83-
- name: Read poetry cache location
84-
id: poetry-cache-location
85-
shell: bash
86-
run: |
87-
echo "POETRY_VENV_LOCATION=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT
88-
- uses: actions/cache@v3
41+
- name: Setup environment
42+
uses: ./.github/actions/setup
8943
with:
90-
path: |
91-
${{ steps.poetry-cache-location.outputs.POETRY_VENV_LOCATION }}
92-
key: docs-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}
93-
- name: Make docs with tox
44+
python-version: ${{ matrix.python-version }}
45+
poetry-version: ${{ env.POETRY_VERSION }}
46+
poetry-install-options: "--sync --extras docs --without dev"
47+
- name: Make docs poetry
9448
run: |
95-
poetry env use python
96-
tox
97-
env:
98-
TOXENV: docs
49+
poetry run make -C docs html
9950
10051
tests:
10152
name: tests
@@ -111,51 +62,18 @@ jobs:
11162
- "3.11"
11263
- "3.12"
11364
steps:
114-
- uses: actions/checkout@v4
115-
- name: Set up Python ${{ matrix.python-version }}
116-
uses: actions/setup-python@v5
117-
id: setup-python
65+
- uses: "actions/checkout@v4"
66+
- name: Setup environment
67+
uses: ./.github/actions/setup
11868
with:
11969
python-version: ${{ matrix.python-version }}
120-
cache: 'pip'
121-
cache-dependency-path: |
122-
pyproject.toml
123-
.github/workflows/ci.yml
124-
- name: "Install dependencies"
125-
run: |
126-
pipx install poetry==$POETRY_VERSION
127-
pipx install tox==$TOX_VERSION
128-
pipx install coveralls==$COVERALLS_VERSION
129-
- name: Read poetry cache location
130-
id: poetry-cache-location
131-
shell: bash
132-
run: |
133-
echo "POETRY_VENV_LOCATION=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT
134-
- uses: actions/cache@v3
135-
with:
136-
path: |
137-
${{ steps.poetry-cache-location.outputs.POETRY_VENV_LOCATION }}
138-
key: test-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}
139-
- name: Prepare toxenv
140-
id: toxenv
141-
run: |
142-
if [[ '${{ matrix.python-version }}' == '3.8' ]]; then
143-
echo "::set-output name=toxenv::py38"
144-
elif [[ '${{ matrix.python-version }}' == '3.9' ]]; then
145-
echo "::set-output name=toxenv::py39"
146-
elif [[ '${{ matrix.python-version }}' == '3.10' ]]; then
147-
echo "::set-output name=toxenv::py310"
148-
elif [[ '${{ matrix.python-version }}' == '3.11' ]]; then
149-
echo "::set-output name=toxenv::py311"
150-
else
151-
echo "::set-output name=toxenv::py312"
152-
fi
153-
- name: Test with tox
154-
run: |
155-
poetry env use python
156-
tox
157-
env:
158-
TOXENV: ${{ steps.toxenv.outputs.toxenv }}
70+
poetry-version: ${{ env.POETRY_VERSION }}
71+
poetry-install-options: "--sync --extras listen"
72+
- name: Run tests
73+
run: >
74+
poetry run pytest tests/
75+
--cov=ring_doorbell --cov-report=xml
76+
--cov-report=term-missing --import-mode importlib
15977
- name: Coveralls GitHub Action
16078
uses: coverallsapp/github-action@v2.2.3
16179
with:

0 commit comments

Comments
 (0)