From e41a2a56207601a1efc3b7cb1b683f26c402b0e0 Mon Sep 17 00:00:00 2001 From: sdb9696 Date: Fri, 12 Apr 2024 14:58:06 +0100 Subject: [PATCH] Update CI to cache pipx poetry app install --- .github/actions/setup/action.yml | 83 +++++++++++++++++++ .github/workflows/ci.yml | 134 ++++++------------------------- 2 files changed, 109 insertions(+), 108 deletions(-) create mode 100644 .github/actions/setup/action.yml diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 00000000..ab6f3139 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,83 @@ +--- +name: Setup Environment +description: Install requested pipx dependencies, configure the system python, and install poetry and the package dependencies + +inputs: + poetry-install-options: + default: "" + poetry-version: + default: 1.6.1 + python-version: + required: true + cache-pre-commit: + default: false + +runs: + using: composite + steps: + - uses: "actions/setup-python@v5" + id: setup-python + with: + python-version: "${{ inputs.python-version }}" + + - name: Setup pipx environment Variables + id: pipx-env-setup + # pipx default home and bin dir are not writable by the cache action + # so override them here and add the bin dir to PATH for later steps. + # This also ensures the pipx cache only contains poetry + run: | + SEP="${{ !startsWith(runner.os, 'windows') && '/' || '\\' }}" + PIPX_CACHE="${{ github.workspace }}${SEP}pipx_cache" + echo "pipx-cache-path=${PIPX_CACHE}" >> $GITHUB_OUTPUT + echo "pipx-version=$(pipx --version)" >> $GITHUB_OUTPUT + echo "PIPX_HOME=${PIPX_CACHE}${SEP}home" >> $GITHUB_ENV + echo "PIPX_BIN_DIR=${PIPX_CACHE}${SEP}bin" >> $GITHUB_ENV + echo "PIPX_MAN_DIR=${PIPX_CACHE}${SEP}man" >> $GITHUB_ENV + echo "${PIPX_CACHE}${SEP}bin" >> $GITHUB_PATH + shell: bash + + - name: Pipx cache + id: pipx-cache + uses: actions/cache@v4 + with: + path: ${{ steps.pipx-env-setup.outputs.pipx-cache-path }} + key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-poetry-${{ inputs.poetry-version }} + + - name: Install poetry + if: steps.pipx-cache.outputs.cache-hit != 'true' + id: install-poetry + shell: bash + run: |- + pipx install poetry==${{ inputs.poetry-version }} --python "${{ steps.setup-python.outputs.python-path }}" + + - name: Read poetry cache location + id: poetry-cache-location + shell: bash + run: |- + echo "poetry-venv-location=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v4 + name: Poetry cache + with: + path: | + ${{ steps.poetry-cache-location.outputs.poetry-venv-location }} + key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}-options-${{ inputs.poetry-install-options }} + + - name: "Poetry install" + shell: bash + run: | + poetry install ${{ inputs.poetry-install-options }} + + - name: Read pre-commit version + if: inputs.cache-pre-commit == 'true' + id: pre-commit-version + shell: bash + run: >- + echo "pre-commit-version=$(poetry run pre-commit -V | awk '{print $2}')" >> $GITHUB_OUTPUT + + - uses: actions/cache@v4 + if: inputs.cache-pre-commit == 'true' + name: Pre-commit cache + with: + path: ~/.cache/pre-commit/ + 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') }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf524810..bcc2eae1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,9 +7,7 @@ on: branches: ["master"] env: - POETRY_VERSION: 1.7.1 - TOX_VERSION: 4.11.3 - COVERALLS_VERSION: 3.3.1 + POETRY_VERSION: 1.8.2 jobs: linting: @@ -20,44 +18,16 @@ jobs: python-version: ["3.12"] steps: - uses: "actions/checkout@v4" - - uses: "actions/setup-python@v5" - id: setup-python + - name: Setup environment + uses: ./.github/actions/setup with: - python-version: "${{ matrix.python-version }}" - cache: 'pip' - cache-dependency-path: | - pyproject.toml - .github/workflows/ci.yml - - name: Install dependencies - run: | - pipx install poetry==$POETRY_VERSION - pipx install tox==$TOX_VERSION - - name: Read poetry cache location - id: poetry-cache-location - shell: bash - run: | - echo "POETRY_VENV_LOCATION=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT - - name: Poetry cache - uses: actions/cache@v3 - with: - path: | - ${{ steps.poetry-cache-location.outputs.POETRY_VENV_LOCATION }} - key: linting-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }} - - name: Read pre-commit version - id: pre-commit-version - run: >- - echo "PRE_COMMIT_VERSION=$(poetry run pre-commit -V | awk '{print $2}')" >> $GITHUB_OUTPUT - - name: Pre-commit cache - uses: actions/cache@v3 - with: - path: ~/.cache/pre-commit/ - 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') }} - - name: Lint with tox + python-version: ${{ matrix.python-version }} + poetry-version: ${{ env.POETRY_VERSION }} + poetry-install-options: "--sync --extras listen --verbose" + cache-pre-commit: true + - name: "Run pre-commit checks" run: | - poetry env use python - tox - env: - TOXENV: lint + poetry run pre-commit run --all-files docs: name: "Build docs" @@ -68,34 +38,15 @@ jobs: python-version: ["3.12"] steps: - uses: "actions/checkout@v4" - - uses: "actions/setup-python@v5" - id: setup-python - with: - python-version: "${{ matrix.python-version }}" - cache: 'pip' - cache-dependency-path: | - pyproject.toml - .github/workflows/ci.yml - - name: Install dependencies - run: | - pipx install poetry==$POETRY_VERSION - pipx install tox==$TOX_VERSION - - name: Read poetry cache location - id: poetry-cache-location - shell: bash - run: | - echo "POETRY_VENV_LOCATION=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT - - uses: actions/cache@v3 + - name: Setup environment + uses: ./.github/actions/setup with: - path: | - ${{ steps.poetry-cache-location.outputs.POETRY_VENV_LOCATION }} - key: docs-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }} - - name: Make docs with tox + python-version: ${{ matrix.python-version }} + poetry-version: ${{ env.POETRY_VERSION }} + poetry-install-options: "--sync --extras docs --without dev" + - name: Make docs poetry run: | - poetry env use python - tox - env: - TOXENV: docs + poetry run make -C docs html tests: name: tests @@ -111,51 +62,18 @@ jobs: - "3.11" - "3.12" steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - id: setup-python + - uses: "actions/checkout@v4" + - name: Setup environment + uses: ./.github/actions/setup with: python-version: ${{ matrix.python-version }} - cache: 'pip' - cache-dependency-path: | - pyproject.toml - .github/workflows/ci.yml - - name: "Install dependencies" - run: | - pipx install poetry==$POETRY_VERSION - pipx install tox==$TOX_VERSION - pipx install coveralls==$COVERALLS_VERSION - - name: Read poetry cache location - id: poetry-cache-location - shell: bash - run: | - echo "POETRY_VENV_LOCATION=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT - - uses: actions/cache@v3 - with: - path: | - ${{ steps.poetry-cache-location.outputs.POETRY_VENV_LOCATION }} - key: test-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }} - - name: Prepare toxenv - id: toxenv - run: | - if [[ '${{ matrix.python-version }}' == '3.8' ]]; then - echo "::set-output name=toxenv::py38" - elif [[ '${{ matrix.python-version }}' == '3.9' ]]; then - echo "::set-output name=toxenv::py39" - elif [[ '${{ matrix.python-version }}' == '3.10' ]]; then - echo "::set-output name=toxenv::py310" - elif [[ '${{ matrix.python-version }}' == '3.11' ]]; then - echo "::set-output name=toxenv::py311" - else - echo "::set-output name=toxenv::py312" - fi - - name: Test with tox - run: | - poetry env use python - tox - env: - TOXENV: ${{ steps.toxenv.outputs.toxenv }} + poetry-version: ${{ env.POETRY_VERSION }} + poetry-install-options: "--sync --extras listen" + - name: Run tests + run: > + poetry run pytest tests/ + --cov=ring_doorbell --cov-report=xml + --cov-report=term-missing --import-mode importlib - name: Coveralls GitHub Action uses: coverallsapp/github-action@v2.2.3 with: