diff --git a/.github/workflows/lockfile.in b/.github/workflows/lockfile.in new file mode 100644 index 0000000..f9a7807 --- /dev/null +++ b/.github/workflows/lockfile.in @@ -0,0 +1 @@ +build == 1.1.1 diff --git a/.github/workflows/lockfile.txt b/.github/workflows/lockfile.txt new file mode 100644 index 0000000..a3dc75a --- /dev/null +++ b/.github/workflows/lockfile.txt @@ -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 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..57b9adc --- /dev/null +++ b/.github/workflows/test.yaml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..22ccc35 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..741f112 --- /dev/null +++ b/README.md @@ -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@ # v0.1.0 + with: + lockfile: "requirements.txt" +``` + +[uv]: https://github.com/astral-sh/uv diff --git a/setup-uv/action.yaml b/setup-uv/action.yaml new file mode 100644 index 0000000..ca7630d --- /dev/null +++ b/setup-uv/action.yaml @@ -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