2024-04-13 17:56:55 +00:00
|
|
|
---
|
|
|
|
name: Setup Environment
|
2024-09-06 14:48:43 +00:00
|
|
|
description: Install requested pipx dependencies, configure the system python, and install uv and the package dependencies
|
2024-04-13 17:56:55 +00:00
|
|
|
|
|
|
|
inputs:
|
2024-09-06 14:48:43 +00:00
|
|
|
uv-install-options:
|
2024-04-13 17:56:55 +00:00
|
|
|
default: ""
|
2024-09-06 14:48:43 +00:00
|
|
|
uv-version:
|
|
|
|
default: 0.4.5
|
2024-04-13 17:56:55 +00:00
|
|
|
python-version:
|
|
|
|
required: true
|
|
|
|
cache-pre-commit:
|
|
|
|
default: false
|
2024-09-06 14:48:43 +00:00
|
|
|
cache-version:
|
|
|
|
default: "v0.1"
|
2024-04-13 17:56:55 +00:00
|
|
|
|
|
|
|
runs:
|
|
|
|
using: composite
|
|
|
|
steps:
|
|
|
|
- uses: "actions/setup-python@v5"
|
|
|
|
id: setup-python
|
|
|
|
with:
|
|
|
|
python-version: "${{ inputs.python-version }}"
|
2024-08-06 19:03:35 +00:00
|
|
|
allow-prereleases: true
|
2024-04-13 17:56:55 +00:00
|
|
|
|
|
|
|
- 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.
|
2024-09-06 14:48:43 +00:00
|
|
|
# This also ensures the pipx cache only contains uv
|
2024-04-13 17:56:55 +00:00
|
|
|
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 }}
|
2024-09-06 14:48:43 +00:00
|
|
|
key: cache-${{ inputs.cache-version }}-${{ runner.os }}-${{ runner.arch }}-python-${{ inputs.python-version }}-${{ steps.setup-python.outputs.python-version }}-pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-uv-${{ inputs.uv-version }}
|
2024-04-13 17:56:55 +00:00
|
|
|
|
2024-09-06 14:48:43 +00:00
|
|
|
- name: Install uv
|
2024-04-13 17:56:55 +00:00
|
|
|
if: steps.pipx-cache.outputs.cache-hit != 'true'
|
2024-09-06 14:48:43 +00:00
|
|
|
id: install-uv
|
2024-04-13 17:56:55 +00:00
|
|
|
shell: bash
|
|
|
|
run: |-
|
2024-09-06 14:48:43 +00:00
|
|
|
pipx install uv==${{ inputs.uv-version }} --python "${{ steps.setup-python.outputs.python-path }}"
|
2024-04-13 17:56:55 +00:00
|
|
|
|
2024-09-06 14:48:43 +00:00
|
|
|
- name: Read uv cache location
|
|
|
|
id: uv-cache-location
|
2024-04-13 17:56:55 +00:00
|
|
|
shell: bash
|
|
|
|
run: |-
|
2024-09-06 14:48:43 +00:00
|
|
|
echo "uv-cache-location=$(uv cache dir)" >> $GITHUB_OUTPUT
|
2024-04-13 17:56:55 +00:00
|
|
|
|
|
|
|
- uses: actions/cache@v4
|
2024-09-06 14:48:43 +00:00
|
|
|
name: uv cache
|
2024-04-13 17:56:55 +00:00
|
|
|
with:
|
|
|
|
path: |
|
2024-09-06 14:48:43 +00:00
|
|
|
${{ steps.uv-cache-location.outputs.uv-cache-location }}
|
|
|
|
key: cache-${{ inputs.cache-version }}-${{ runner.os }}-${{ runner.arch }}-python-${{ steps.setup-python.outputs.python-version }}-uv-${{ inputs.uv-version }}-${{ hashFiles('uv.lock') }}-options-${{ inputs.uv-install-options }}
|
2024-04-13 17:56:55 +00:00
|
|
|
|
2024-09-06 14:48:43 +00:00
|
|
|
- name: "uv install"
|
2024-04-13 17:56:55 +00:00
|
|
|
shell: bash
|
|
|
|
run: |
|
2024-09-06 14:48:43 +00:00
|
|
|
uv sync --python "${{ steps.setup-python.outputs.python-path }}" ${{ inputs.uv-install-options }}
|
2024-04-13 17:56:55 +00:00
|
|
|
|
|
|
|
- name: Read pre-commit version
|
|
|
|
if: inputs.cache-pre-commit == 'true'
|
|
|
|
id: pre-commit-version
|
|
|
|
shell: bash
|
|
|
|
run: >-
|
2024-09-06 14:48:43 +00:00
|
|
|
echo "pre-commit-version=$(uv run pre-commit -- -V | awk '{print $2}')" >> $GITHUB_OUTPUT
|
2024-04-13 17:56:55 +00:00
|
|
|
|
|
|
|
- uses: actions/cache@v4
|
|
|
|
if: inputs.cache-pre-commit == 'true'
|
|
|
|
name: Pre-commit cache
|
|
|
|
with:
|
|
|
|
path: ~/.cache/pre-commit/
|
2024-09-06 14:48:43 +00:00
|
|
|
key: cache-${{ inputs.cache-version }}-${{ runner.os }}-${{ runner.arch }}-pre-commit-${{ steps.pre-commit-version.outputs.pre-commit-version }}-python-${{ inputs.python-version }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
|