Skip to content

Commit

Permalink
Add uv support to workflow setup action
Browse files Browse the repository at this point in the history
  • Loading branch information
sdb9696 committed Apr 15, 2024
1 parent 87fa39d commit 9e32611
Showing 1 changed file with 59 additions and 6 deletions.
65 changes: 59 additions & 6 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ inputs:
required: true
cache-pre-commit:
default: false
use-uv-installer:
default: false
uv-version:
default: 0.1.31
uv-install-cmd:
default: "."

runs:
using: composite
Expand All @@ -28,8 +34,10 @@ runs:
run: |
SEP="${{ !startsWith(runner.os, 'windows') && '/' || '\\' }}"
PIPX_CACHE="${{ github.workspace }}${SEP}pipx_cache"
PIPX_CACHE_KEY_SUFFIX=${{ inputs.use-uv-installer == 'false' && format('poetry-{0}', inputs.poetry-version) || format('uv-{0}', inputs.uv-version) }}
echo "pipx-cache-path=${PIPX_CACHE}" >> $GITHUB_OUTPUT
echo "pipx-version=$(pipx --version)" >> $GITHUB_OUTPUT
echo "pipx-cache-key-suffix=${PIPX_CACHE_KEY_SUFFIX}" >> $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
Expand All @@ -41,33 +49,78 @@ runs:
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 }}
key: pipx-cache-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-${{ steps.pipx-env-setup.outputs.pipx-cache-key-suffix }}

- name: Install poetry
if: steps.pipx-cache.outputs.cache-hit != 'true'
if: ${{ (steps.pipx-cache.outputs.cache-hit) != 'true' && ( inputs.use-uv-installer == 'false')
id: install-poetry
shell: bash
run: |-
pipx install poetry==${{ inputs.poetry-version }} --python "${{ steps.setup-python.outputs.python-path }}"
- name: Install uv
if: ${{ (steps.pipx-cache.outputs.cache-hit) != 'true' && ( inputs.use-uv-installer == 'true')
id: install-uv
shell: bash
run: |-
pipx install uv==${{ inputs.uv-version }}
- name: Read poetry cache location
id: poetry-cache-location
if: inputs.use-uv-installer == 'false'
id: poetry-venv-location
shell: bash
run: |-
echo "poetry-venv-location=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT
- name: Read uv cache location
if: inputs.use-uv-installer == 'true'
id: uv-variables-setup
shell: bash
run: |-
echo "uv-cache-location=$(uv cache dir)" >> $GITHUB_OUTPUT
echo "uv-venv-location=.venv" >> $GITHUB_OUTPUT
echo "uv-activate-cmd=${{ !startsWith(runner.os, 'windows') && 'source .venv/bin/activate' || '.venv\\Scripts\\activate' }}" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Poetry cache
if: inputs.use-uv-installer == 'false'
name: Poetry venv 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 }}
${{ steps.poetry-venv-location.outputs.poetry-venv-location }}
key: poetry-venv-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}-options-${{ inputs.poetry-install-options }}


- uses: actions/cache@v4
if: inputs.use-uv-installer == 'true'
name: uv venv
with:
path: |
${{ steps.uv-variables-setup.outputs.uv-venv-location }}
key: uv-${{ inputs.uv-version }}-venv-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}-options-${{ inputs.poetry-install-options }}

- uses: actions/cache@v4
if: inputs.use-uv-installer == 'true'
name: uv cache
with:
save-always: true
path: |
${{ steps.uv-venv-location.outputs.uv-cache-location }}
key: uv-${{ inputs.uv-version }}-cache-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-options-${{ inputs.uv-install-cmd }}

- name: "Poetry install"
if: inputs.use-uv-installer == 'false'
shell: bash
run: |
poetry install ${{ inputs.poetry-install-options }}
- name: "uv install"
if: inputs.use-uv-installer == 'true'
shell: bash
run: |
uv venv ${{ steps.uv-variables-setup.outputs.uv-venv-location }}
${{ steps.uv-variables.outputs.uv-activate-cmd }}
uv pip install -e ${{ inputs.uv-install-cmd }}
- name: Read pre-commit version
if: inputs.cache-pre-commit == 'true'
id: pre-commit-version
Expand Down

0 comments on commit 9e32611

Please sign in to comment.