From 9baeace9b460207ed12ecb70146a9db4ff66bd6e 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 ++++++++++++++++++-- 2 files changed, 94 insertions(+), 5 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..d4b3681 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,8 +27,53 @@ 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: Display python user base and pipx home + run: | + echo "Python user base: ${{ steps.environment.outputs.python-user-base }}" + echo "Pipx home: ${{ steps.environment.outputs.pipx-home }}" + + - 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-{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-{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: | @@ -45,9 +90,10 @@ jobs: venv-${{ 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