Skip to content

Commit

Permalink
Don't install pipx again
Browse files Browse the repository at this point in the history
  • Loading branch information
KapJI committed Sep 11, 2024
1 parent c31a2eb commit 2543cd8
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 16 deletions.
43 changes: 43 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "Setup Python Environment"
description: "Sets up pipx and Python environment paths for both bash and pwsh."

runs:
using: "composite"
steps:
- name: Setup environment in bash (Linux, macOS)
id: env-bash
shell: bash
if: runner.os != 'Windows'
run: |
PIPX_HOME="$HOME/.pipx"
PIPX_BIN_DIR="$PIPX_HOME/bin"
echo "PIPX_HOME=$PIPX_HOME" >> $GITHUB_ENV
echo "PIPX_BIN_DIR=$PIPX_BIN_DIR" >> $GITHUB_ENV
echo "$PIPX_BIN_DIR" >> $GITHUB_PATH
PYTHON_USER_BASE="$(python3 -m site --user-base)"
echo "$PYTHON_USER_BASE/bin" >> $GITHUB_PATH
echo "python-user-base=$PYTHON_USER_BASE" >> $GITHUB_OUTPUT
echo "pipx-home=$PIPX_HOME" >> $GITHUB_OUTPUT
- name: Setup environment in pwsh (Windows)
id: env-pwsh
shell: pwsh
if: runner.os == 'Windows'
run: |
$PIPX_HOME = "$env:USERPROFILE\.pipx"
$PIPX_BIN_DIR = "$PIPX_HOME\bin"
echo "PIPX_HOME=$PIPX_HOME" | Out-File -Append -FilePath $env:GITHUB_ENV
echo "PIPX_BIN_DIR=$PIPX_BIN_DIR" | Out-File -Append -FilePath $env:GITHUB_ENV
echo "$PIPX_BIN_DIR" | Out-File -Append -FilePath $env:GITHUB_PATH
$PYTHON_USER_BASE = (python -m site --user-base)
echo "$PYTHON_USER_BASE\Scripts" | Out-File -Append -FilePath $env:GITHUB_PATH
echo "python-user-base=$PYTHON_USER_BASE" | Out-File -Append -FilePath $env:GITHUB_OUTPUT
echo "pipx-home=$PIPX_HOME" | Out-File -Append -FilePath $env:GITHUB_OUTPUT
outputs:
python-user-base:
description: "The Python user base path"
value: ${{ steps.env-bash.outputs.python-user-base || steps.env-pwsh.outputs.python-user-base }}
pipx-home:
description: "Home directory of pipx"
value: ${{ steps.env-bash.outputs.pipx-home || steps.env-pwsh.outputs.pipx-home }}
56 changes: 48 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,67 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: abatilo/actions-poetry@v3
- name: Setup Python Environment
uses: ./.github/actions/setup-environment
id: environment

- name: Get pipx and poetry latest versions
id: latest-versions
shell: bash
run: |
pipx_version=$(curl -s https://pypi.org/pypi/pipx/json | jq -r .info.version)
poetry_version=$(curl -s https://pypi.org/pypi/poetry/json | jq -r .info.version)
echo "pipx=$pipx_version" >> $GITHUB_OUTPUT
echo "poetry=$poetry_version" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Cache pipx
with:
path: ${{ steps.environment.outputs.python-user-base }}
key: >
${{ format('pip-user-{0}-{1}-{2}',
matrix.os,
matrix.python-version,
steps.latest-versions.outputs.pipx
) }}
- uses: actions/cache@v4
name: Cache Poetry
with:
path: ${{ steps.environment.outputs.pipx-home }}
key: >
${{ format('pipx-home-{0}-{1}-{2}',
matrix.os,
matrix.python-version,
steps.latest-versions.outputs.poetry
) }}
- name: Install pipx
run: pip install --user pipx

- name: Install or update Poetry
run: |
pipx install poetry==${{ steps.latest-versions.outputs.poetry }}
pipx list
- name: Use local virtual environment
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v4
id: cache-poetry-deps
name: Cache Poetry dependencies
with:
path: ./.venv
key: venv-${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
key: deps-${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
venv-${{ matrix.os }}-${{ matrix.python-version }}-
deps-${{ matrix.os }}-${{ matrix.python-version }}-
- name: Install dependencies with Poetry
if: steps.cache-poetry-deps.outputs.cache-hit != 'true'
run: poetry install
run: |
poetry env use python3
poetry install
- name: Test package building
- name: Check if package builds
run: |
poetry build
6 changes: 2 additions & 4 deletions .github/workflows/linting-and-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ jobs:
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v4
id: cache-poetry-deps
name: Cache Poetry dependencies
with:
path: ./.venv
key: venv-${{ env.RUNS_ON }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
key: deps-${{ env.RUNS_ON }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
venv-${{ env.RUNS_ON }}-${{ matrix.python-version }}-
deps-${{ env.RUNS_ON }}-${{ matrix.python-version }}-
- uses: actions/cache@v4
name: Cache pre-commit hooks
Expand All @@ -57,7 +56,6 @@ jobs:
pre-commit-${{ env.RUNS_ON }}-
- name: Install dependencies with Poetry
if: steps.cache-poetry-deps.outputs.cache-hit != 'true'
run: poetry install

- name: Run pre-commit on all files
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ jobs:
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v4
id: cache-poetry-deps
name: Cache Poetry dependencies
with:
path: ./.venv
key: venv-${{ env.RUNS_ON }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
key: deps-${{ env.RUNS_ON }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
venv-${{ env.RUNS_ON }}-${{ matrix.python-version }}-
deps-${{ env.RUNS_ON }}-${{ matrix.python-version }}-
- name: Install dependencies with Poetry
if: steps.cache-poetry-deps.outputs.cache-hit != 'true'
run: poetry install

- name: Set version
Expand Down

0 comments on commit 2543cd8

Please sign in to comment.