Skip to content

Commit

Permalink
Add setup-uv action. (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaander authored Jun 5, 2024
1 parent 1eb6d3f commit 36c0f93
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lockfile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build == 1.1.1
8 changes: 8 additions & 0 deletions .github/workflows/lockfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file was autogenerated by uv via the following command:
# uv pip compile --python-version 3.12 --python-platform linux lockfile.in
build==1.1.1
# via -r lockfile.in
packaging==24.0
# via build
pyproject-hooks==1.1.0
# via build
69 changes: 69 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Test

on:
pull_request:

workflow_dispatch:

push:
branches:
- trunk

jobs:
setup_uv_default:
name: setup-uv [default]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Set up Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: "3.12"
- name: Set up Python environment
uses: ./setup-uv
- run: uv --version

setup_uv_version:
name: setup-uv [version]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Set up Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: "3.12"
- name: Set up Python environment
uses: ./setup-uv
with:
version: 0.2.2
- run: uv --version

setup_uv_lockfile:
name: setup-uv [lockfile]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Set up Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: "3.12"
- name: Set up Python environment
uses: ./setup-uv
with:
lockfile: .github/workflows/lockfile.txt
- run: uv --version
- run: python -m build --version

tests_complete:
name: All tests
if: always()
needs: [setup_uv_default, setup_uv_version, setup_uv_lockfile]
runs-on: ubuntu-latest

steps:
- run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
- name: Done
run: exit 0
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ci:
autoupdate_schedule: quarterly
autoupdate_branch: 'trunk'
autofix_prs: false

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.5.0'
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-json
- id: check-toml
- id: check-yaml
- id: check-case-conflict
- id: mixed-line-ending
- repo: https://github.com/crate-ci/typos
rev: v1.21.0
hooks:
- id: typos
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Workflows

`glotzerlab/workflows` houses reusable GitHub actions and workflows that are in common
use across glotzerlab software packages.

## setup-uv

`setup-uv` installs [uv] and *optionally* installs all the packages in a given
`lockfile`.

To generate a lockfile, run:
```bash
uv pip compile --python-version 3.12 --python-platform linux requirements.in > requirements.txt
```
and add both `requirements.in` and `requirements.txt` to the git repository.

In your action workflow, create a Python environment and then call setup-uv:
```yaml
steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Set up Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: "3.12"
- name: Set up Python environment
uses: glotzerlab/workflows/setup-python@<insert hash of tagged version here> # v0.1.0
with:
lockfile: "requirements.txt"
```
[uv]: https://github.com/astral-sh/uv
24 changes: 24 additions & 0 deletions setup-uv/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Setup uv
description: Install uv and synchronize the environment with a given lock file.

inputs:
version:
description: 'uv version to install.'
required: false
default: '0.2.6'
lockfile:
description: 'Packages to install.'
required: false
default: ''

runs:
using: "composite"
steps:
- name: Install uv
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/${{ inputs.version }}/uv-installer.sh | bash
shell: bash

- name: Install
if: ${{ inputs.lockfile != '' }}
run: "uv pip sync ${{ inputs.lockfile }} --only-binary :all: --system --reinstall"
shell: bash

0 comments on commit 36c0f93

Please sign in to comment.