From 2603c8a8db23c1765a79cdef7752c68f9b407cbe Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Wed, 11 Sep 2024 17:12:25 +0200 Subject: [PATCH] Don't install pipx again --- .github/actions/setup-environment/action.yml | 43 +++++++++++++++ .github/workflows/build.yml | 56 +++++++++++++++++--- .github/workflows/linting-and-testing.yaml | 6 +-- .github/workflows/publish.yml | 6 +-- 4 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 .github/actions/setup-environment/action.yml diff --git a/.github/actions/setup-environment/action.yml b/.github/actions/setup-environment/action.yml new file mode 100644 index 0000000..30eec2a --- /dev/null +++ b/.github/actions/setup-environment/action.yml @@ -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 }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a58abe5..b6c7037 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,8 +27,48 @@ 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: | @@ -36,18 +76,18 @@ 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-${{ 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 diff --git a/.github/workflows/linting-and-testing.yaml b/.github/workflows/linting-and-testing.yaml index abbdb3f..baa6d04 100644 --- a/.github/workflows/linting-and-testing.yaml +++ b/.github/workflows/linting-and-testing.yaml @@ -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 @@ -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 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4d8ef02..e633613 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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