|
| 1 | +# Action: Setup Project (composite action) |
| 2 | +# |
| 3 | +# Purpose: Bootstrap a Python project in GitHub Actions by: |
| 4 | +# - Installing Task, uv, and uvx into a local ./bin directory |
| 5 | +# - Detecting presence of pyproject.toml and exposing it as an output |
| 6 | +# - Creating a virtual environment with uv and syncing dependencies |
| 7 | +# |
| 8 | +# Inputs: |
| 9 | +# - python-version: Python version used for the virtual environment (default: 3.12) |
| 10 | +# |
| 11 | +# Outputs: |
| 12 | +# - pyproject_exists: "true" if pyproject.toml exists, otherwise "false" |
| 13 | +# |
| 14 | +# Notes: |
| 15 | +# - Safe to run in repositories without pyproject.toml; dependency sync will be skipped. |
| 16 | +# - Used by workflows such as CI, Book, Marimo, and Release. |
| 17 | + |
| 18 | +name: 'Setup Project' |
| 19 | +description: 'Setup the project' |
| 20 | + |
| 21 | +inputs: |
| 22 | + python-version: |
| 23 | + description: 'Python version to use' |
| 24 | + required: false |
| 25 | + default: '3.12' |
| 26 | + |
| 27 | +outputs: |
| 28 | + pyproject_exists: |
| 29 | + description: 'Flag indicating whether pyproject.toml exists' |
| 30 | + value: ${{ steps.check_pyproject.outputs.exists }} |
| 31 | + |
| 32 | +runs: |
| 33 | + using: 'composite' |
| 34 | + steps: |
| 35 | + - name: Set up task, uv, uvx and the venv |
| 36 | + shell: bash |
| 37 | + run: | |
| 38 | + mkdir -p bin |
| 39 | +
|
| 40 | + # Add ./bin to the PATH |
| 41 | + echo "Adding ./bin to PATH" |
| 42 | + echo "$(pwd)/bin" >> $GITHUB_PATH |
| 43 | +
|
| 44 | + # Install Task |
| 45 | + curl -fsSL https://taskfile.dev/install.sh | sh -s -- -d -b ./bin |
| 46 | +
|
| 47 | + # Install uv and uvx |
| 48 | + curl -fsSL https://astral.sh/uv/install.sh | UV_INSTALL_DIR="./bin" sh |
| 49 | +
|
| 50 | + - name: Check version for task |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + task --version |
| 54 | +
|
| 55 | + - name: Check version for uv |
| 56 | + shell: bash |
| 57 | + run: | |
| 58 | + uv --version |
| 59 | +
|
| 60 | + - name: Check for pyproject.toml |
| 61 | + id: check_pyproject |
| 62 | + shell: bash |
| 63 | + run: | |
| 64 | + if [ -f "pyproject.toml" ]; then |
| 65 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 66 | + else |
| 67 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 68 | + fi |
| 69 | +
|
| 70 | + - name: Build the virtual environment |
| 71 | + shell: bash |
| 72 | + run: uv venv --python ${{ inputs.python-version }} |
| 73 | + |
| 74 | + - name: "Sync the virtual environment for ${{ github.repository }} if pyproject.toml exists" |
| 75 | + shell: bash |
| 76 | + run: | |
| 77 | + if [ -f "pyproject.toml" ]; then |
| 78 | + uv sync --all-extras |
| 79 | + else |
| 80 | + echo "No pyproject.toml found, skipping package installation" |
| 81 | + fi |
0 commit comments