diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64bdf32..b2a9b39 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,17 +28,14 @@ jobs: steps: - uses: actions/checkout@v7 - - uses: actions/setup-python@v6 + - uses: ./setup-uv with: python-version: ${{ matrix.python-version }} - - - uses: astral-sh/setup-uv@v7 - with: - enable-cache: false + activate-environment: true - name: Install dependencies run: | - uv pip install --system -e ".[dev]" + uv pip install -e ".[dev]" - name: Run Python tests uses: ultralytics/actions/retry@main diff --git a/README.md b/README.md index d9c21da..e4d38c0 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,19 @@ Check every pull request commit author against the central Ultralytics CLA signa [**📖 Full Documentation →**](cla/README.md) +### 6. Setup uv Action + +Install the latest uv with retry support on Linux and macOS and optionally activate a Python environment. + +```yaml +- uses: ultralytics/actions/setup-uv@main + with: + python-version: "3.14" + activate-environment: true +``` + +[**📖 Full Documentation →**](setup-uv/README.md) + ## Python Package Install the `ultralytics-actions` package for programmatic access to action utilities, including all [requirements](https://github.com/ultralytics/actions/blob/main/pyproject.toml), in a [**Python>=3.8**](https://www.python.org/) environment. diff --git a/setup-uv/README.md b/setup-uv/README.md new file mode 100644 index 0000000..6b04de0 --- /dev/null +++ b/setup-uv/README.md @@ -0,0 +1,19 @@ +# Setup uv Action + +Installs the latest [uv](https://docs.astral.sh/uv/) release with retry support on Linux and macOS and optionally activates a Python virtual environment. + +## Usage + +```yaml +- uses: ultralytics/actions/setup-uv@main + with: + python-version: "3.14" + activate-environment: true +``` + +## Inputs + +| Input | Description | Required | Default | +| ---------------------- | ----------------------------------------- | -------- | ------- | +| `python-version` | Python version for uv commands | No | - | +| `activate-environment` | Create and activate a `.venv` environment | No | `false` | diff --git a/setup-uv/action.yml b/setup-uv/action.yml new file mode 100644 index 0000000..d7ad321 --- /dev/null +++ b/setup-uv/action.yml @@ -0,0 +1,48 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +name: "Setup uv" +description: "Install the latest uv with retry on Linux and macOS and optionally activate a Python environment" +inputs: + python-version: + description: "Python version for uv commands" + required: false + default: "" + activate-environment: + description: "Create and activate a .venv environment" + required: false + default: "false" + +runs: + using: "composite" + steps: + - name: Validate platform + shell: bash + run: | + if [ "$RUNNER_OS" = "Windows" ]; then + echo "::error::setup-uv supports Linux and macOS runners" + exit 1 + fi + + - name: Install uv + uses: ultralytics/actions/retry@main + with: + run: | + set -o pipefail + curl -LsSf https://astral.sh/uv/install.sh | env UV_UNMANAGED_INSTALL="$RUNNER_TEMP/uv-bin" sh + echo "$RUNNER_TEMP/uv-bin" >> "$GITHUB_PATH" + + - name: Configure environment + shell: bash + env: + ACTIVATE_ENVIRONMENT: ${{ inputs.activate-environment }} + INPUT_PYTHON_VERSION: ${{ inputs.python-version }} + run: | + if [ -n "$INPUT_PYTHON_VERSION" ]; then + export UV_PYTHON="$INPUT_PYTHON_VERSION" + echo "UV_PYTHON=$INPUT_PYTHON_VERSION" >> "$GITHUB_ENV" + fi + if [ "$ACTIVATE_ENVIRONMENT" = "true" ]; then + uv venv --clear + echo "VIRTUAL_ENV=$PWD/.venv" >> "$GITHUB_ENV" + echo "$PWD/.venv/bin" >> "$GITHUB_PATH" + fi