From faaf356c66c226c8a8805317c26229f90a85e14f Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Mon, 28 Oct 2024 09:42:54 -0400 Subject: [PATCH 1/6] Implement update-uv-lockfiles --- .github/workflows/update-uv-lockfiles.yaml | 62 ++++++++++++++++++++++ README.md | 26 +++++++++ 2 files changed, 88 insertions(+) create mode 100644 .github/workflows/update-uv-lockfiles.yaml diff --git a/.github/workflows/update-uv-lockfiles.yaml b/.github/workflows/update-uv-lockfiles.yaml new file mode 100644 index 0000000..0c8015e --- /dev/null +++ b/.github/workflows/update-uv-lockfiles.yaml @@ -0,0 +1,62 @@ +name: Update uv lockfiles + +on: + workflow_call: + inputs: + branch: + required: true + type: string + command: + default: ./update-lockfiles.sh + required: false + type: string + path: + default: .github/workflows/environments + required: false + type: string + +jobs: + update: + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 + with: + path: code + ref: ${{ inputs.branch }} + + - uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0 + id: generate-token + with: + app-id: ${{ secrets.PR_SUBMITTER_APP_ID }} + private-key: ${{ secrets.PR_SUBMITTER_PRIVATE_KEY }} + + - name: Create python environment + uses: mamba-org/setup-micromamba@617811f69075e3fd3ae68ca64220ad065877f246 # v2.0.0 + with: + micromamba-version: '1.5.8-0' + environment-name: update + create-args: >- + python=3.12 + uv + micromamba-root-path: ${{ github.workspace }}/micromamba + + - name: Configure conda environment variables + run: | + echo "$MAMBA_ROOT_PREFIX/envs/update/bin" >> $GITHUB_PATH + + - name: Update lockfiles + run: ${{ inputs.command }} + working-directory: code/${{ inputs.path }} + + - name: Create pull request + uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5 + with: + base: ${{ inputs.branch }} + path: code + commit-message: "Update uv lockfiles" + branch: update-uv-lockfiles + delete-branch: true + title: Update uv lockfiles on ${{ inputs.branch }} + body: Automated changes by `${{ inputs.command }}`. + token: ${{ steps.generate-token.outputs.token }} diff --git a/README.md b/README.md index 31520c6..376ff82 100644 --- a/README.md +++ b/README.md @@ -122,3 +122,29 @@ To automatically update conda lock files monthly: with: branch: ``` + +## update-uv-lockfiles + +To automatically update uv lock files monthly: +1. Prepare a directory with the base `requirements-*.in` files and a script that updates + all lock files (see + https://github.com/glotzerlab/rowan/tree/master/.github/workflows for an example). +2. Ask an organization admin to install the pull request submitter bot. +3. Create a workflow `update-uv-lockfiles.yaml` with the contents: + + ```yaml + name: Update uv lockfiles + + on: + schedule: + - cron: '0 12 1 * *' + + workflow_dispatch: + + jobs: + update: + uses: glotzerlab/workflows/.github/workflows/update-uv-lockfiles.yaml@0d90feacda686e08bfecc451fc04a8596bd295f5 # 0.4.0 + secrets: inherit + with: + branch: + ``` From 48c6a28bd19fa9790e7f5e5af8cbe3f9328e10ea Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Mon, 28 Oct 2024 09:46:17 -0400 Subject: [PATCH 2/6] Test update-uv-lockfiles. --- .github/workflows/test.yaml | 8 ++++++++ test/update-uv-lockfile/requirements.in | 1 + test/update-uv-lockfile/requirements.txt | 8 ++++++++ test/update-uv-lockfile/update-lockfiles.sh | 7 +++++++ 4 files changed, 24 insertions(+) create mode 100644 test/update-uv-lockfile/requirements.in create mode 100644 test/update-uv-lockfile/requirements.txt create mode 100755 test/update-uv-lockfile/update-lockfiles.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3993cc2..f6721df 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -103,6 +103,14 @@ jobs: branch: ${{ github.event.pull_request.head.ref }} path: test/update-conda-lockfile + update_uv_lockfiles: + if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref != 'update-uv-lockfiles' && contains(github.event.pull_request.labels.*.name, 'test-uv-lockfiles') }} + uses: ./.github/workflows/update-uv-lockfiles.yaml + secrets: inherit + with: + branch: ${{ github.event.pull_request.head.ref }} + path: test/update-uv-lockfile + setup_row: name: setup-row [default] runs-on: ubuntu-latest diff --git a/test/update-uv-lockfile/requirements.in b/test/update-uv-lockfile/requirements.in new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/test/update-uv-lockfile/requirements.in @@ -0,0 +1 @@ +build diff --git a/test/update-uv-lockfile/requirements.txt b/test/update-uv-lockfile/requirements.txt new file mode 100644 index 0000000..4022e75 --- /dev/null +++ b/test/update-uv-lockfile/requirements.txt @@ -0,0 +1,8 @@ +# This file was autogenerated by uv via the following command: +# uv pip compile --python-version 3.13 --python-platform linux requirements.in +build==1.2.2.post1 + # via -r requirements.in +packaging==24.1 + # via build +pyproject-hooks==1.2.0 + # via build diff --git a/test/update-uv-lockfile/update-lockfiles.sh b/test/update-uv-lockfile/update-lockfiles.sh new file mode 100755 index 0000000..a37c865 --- /dev/null +++ b/test/update-uv-lockfile/update-lockfiles.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Execute this script to update all lock files to the latest versions of dependencies. + +rm -f requirements*.txt + +uv pip compile --python-version 3.13 --python-platform linux requirements.in > requirements.txt From cd7463010720bdb745eadfca96a21b6a823daafc Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Mon, 28 Oct 2024 09:49:42 -0400 Subject: [PATCH 3/6] Rerun CI checks when a label is added. --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f6721df..1e9d957 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,6 +2,7 @@ name: Test on: pull_request: + types: [opened, labeled, reopened, synchronize] workflow_dispatch: From b656e61f87f339dc5c4a52792864ac0e9a949ae5 Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Mon, 28 Oct 2024 09:58:22 -0400 Subject: [PATCH 4/6] Check the GitHub context. --- .github/workflows/test.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1e9d957..a6a6cb1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,6 +11,12 @@ on: - trunk jobs: + debug: + name: Show debugging information + runs-on: ubuntu-latest + steps: + - run: echo '${{ toJSON(github) }}' + setup_uv_default: name: setup-uv [default] runs-on: ubuntu-latest From f192a5dd2a918aab4c28b26ec15e6ae00834e7b9 Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Mon, 28 Oct 2024 10:04:03 -0400 Subject: [PATCH 5/6] Use `github.head_ref`. --- .github/workflows/test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a6a6cb1..311718b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -103,19 +103,19 @@ jobs: - run: cargo bundle-licenses --version update_conda_lockfiles: - if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref != 'update-conda-lockfiles' && contains(github.event.pull_request.labels.*.name, 'test-conda-lockfiles') }} + if: ${{ github.event_name == 'pull_request' && github.head_ref != 'update-conda-lockfiles' && contains(github.event.pull_request.labels.*.name, 'test-conda-lockfiles') }} uses: ./.github/workflows/update-conda-lockfiles.yaml secrets: inherit with: - branch: ${{ github.event.pull_request.head.ref }} + branch: ${{ github.head_ref }} path: test/update-conda-lockfile update_uv_lockfiles: - if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref != 'update-uv-lockfiles' && contains(github.event.pull_request.labels.*.name, 'test-uv-lockfiles') }} + if: ${{ github.event_name == 'pull_request' && github.head_ref != 'update-uv-lockfiles' && contains(github.event.pull_request.labels.*.name, 'test-uv-lockfiles') }} uses: ./.github/workflows/update-uv-lockfiles.yaml secrets: inherit with: - branch: ${{ github.event.pull_request.head.ref }} + branch: ${{ github.head_ref }} path: test/update-uv-lockfile setup_row: From 125a62c697d68420cd6c969042271714dd02fe3c Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Mon, 28 Oct 2024 10:10:33 -0400 Subject: [PATCH 6/6] Attempt to trigger a test of update-uv-lockfiles. --- test/update-uv-lockfile/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/update-uv-lockfile/requirements.txt b/test/update-uv-lockfile/requirements.txt index 4022e75..9c344d0 100644 --- a/test/update-uv-lockfile/requirements.txt +++ b/test/update-uv-lockfile/requirements.txt @@ -1,6 +1,6 @@ # This file was autogenerated by uv via the following command: # uv pip compile --python-version 3.13 --python-platform linux requirements.in -build==1.2.2.post1 +build==1.1.1 # via -r requirements.in packaging==24.1 # via build