From 0de05c220cea7ebd960d7cb2d776ce92df9a8796 Mon Sep 17 00:00:00 2001 From: Joshua Bronson Date: Sat, 13 Jan 2024 13:36:43 -0500 Subject: [PATCH] Add 'update dev deps' workflow, etc. --- .github/workflows/lint.yml | 18 +++++++---- .github/workflows/release-to-pypi.yml | 12 +++++--- .github/workflows/release-to-test-pypi.yml | 7 +++-- .github/workflows/test.yml | 16 ++++++---- .github/workflows/update_actions.yml | 10 ++++--- .github/workflows/update_dev_deps.yml | 30 +++++++++++++++++++ .github/workflows/update_flake_lock.yml | 15 +++++----- CONTRIBUTING.rst | 19 ++++++++---- flake.lock | 6 ++-- init_dev_env | 2 +- ...ev-dependencies => update_dev_dependencies | 16 ++++------ 11 files changed, 101 insertions(+), 50 deletions(-) create mode 100644 .github/workflows/update_dev_deps.yml rename upgrade-dev-dependencies => update_dev_dependencies (86%) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index bccd3731..e5c687ca 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: linters +name: lint "on": push: @@ -15,14 +15,20 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c + - name: check out source + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: set up Python + uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c with: python-version: '3.12' - - run: python -m pip install -U pip setuptools wheel + cache: pip + cache-dependency-path: dev-deps/python3.12/test.txt - name: install dependencies - run: pip install pre-commit - - uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507 + run: | + python -m pip install -U pip setuptools wheel + python -m pip install pre-commit + - name: run pre-commit + uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507 with: extra_args: --all-files --verbose diff --git a/.github/workflows/release-to-pypi.yml b/.github/workflows/release-to-pypi.yml index f1ae8bfc..763c5bdc 100644 --- a/.github/workflows/release-to-pypi.yml +++ b/.github/workflows/release-to-pypi.yml @@ -1,19 +1,23 @@ -name: PyPI release +name: release to pypi.org "on": push: tags: - "v[0-9]+.[0-9]+.[0-9]+" + workflow_dispatch: jobs: main: runs-on: ubuntu-latest steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c + - name: check out source + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: set up Python + uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c with: python-version: '3.12' - - run: python -m pip install -U pip setuptools build + - name: install dependencies + run: python -m pip install -U pip setuptools build - run: python -m build - name: Publish uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf diff --git a/.github/workflows/release-to-test-pypi.yml b/.github/workflows/release-to-test-pypi.yml index 550a5125..4ccf7caa 100644 --- a/.github/workflows/release-to-test-pypi.yml +++ b/.github/workflows/release-to-test-pypi.yml @@ -1,7 +1,6 @@ -name: test PyPI release +name: release to test.pypi.org "on": - workflow_dispatch: push: tags: # To publish a test release to test.pypi.org, @@ -14,12 +13,14 @@ name: test PyPI release # git tag -d 0.21.3.rc1 # git push origin :0.21.3.rc1 - "[0-9]+.[0-9]+.[0-9]+.rc[0-9]+" + workflow_dispatch: jobs: main: runs-on: ubuntu-latest steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: check out source + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c with: python-version: '3.12' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 05828d3e..2184e84d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: tests +name: test "on": workflow_dispatch: @@ -38,14 +38,18 @@ jobs: - pyversion: "pypy-3.9" deps_subdir: "pypy3.9" steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c + - name: check out source + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: set up Python ${{ matrix.pyversion }} + uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c with: python-version: ${{ matrix.pyversion }} cache: pip cache-dependency-path: dev-deps/${{ matrix.deps_subdir || format('python{0}', matrix.pyversion) }}/test.txt - - run: python -m pip install -U pip setuptools wheel tox==4.11.4 - - run: python -m pip install -r dev-deps/${{ matrix.deps_subdir || format('python{0}', matrix.pyversion) }}/test.txt + - name: install dependencies + run: | + python -m pip install -U pip setuptools wheel + python -m pip install -r dev-deps/${{ matrix.deps_subdir || format('python{0}', matrix.pyversion) }}/test.txt - name: maybe set --hypothesis-profile=more-examples # See tests/conftest.py if: ${{ github.event_name == 'schedule' }} run: | @@ -72,8 +76,8 @@ jobs: coverage debug data coverage report - name: maybe upload to Codecov # https://github.com/codecov/codecov-action - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d if: matrix.enable_coverage + uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d with: verbose: true fail_ci_if_error: false # https://github.com/codecov/codecov-action/issues/557 diff --git a/.github/workflows/update_actions.yml b/.github/workflows/update_actions.yml index 01abd236..bd652f8b 100644 --- a/.github/workflows/update_actions.yml +++ b/.github/workflows/update_actions.yml @@ -1,6 +1,6 @@ # https://github.com/marketplace/actions/github-actions-version-updater -name: GitHub Actions updater +name: update GitHub Actions "on": workflow_dispatch: @@ -12,14 +12,16 @@ jobs: main: runs-on: ubuntu-latest steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: check out code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 with: token: ${{ secrets.ACTIONS_VERSION_UPDATER_TOKEN }} - - uses: saadmk11/github-actions-version-updater@64be81ba69383f81f2be476703ea6570c4c8686e + - name: update GitHub Actions + uses: saadmk11/github-actions-version-updater@64be81ba69383f81f2be476703ea6570c4c8686e with: token: ${{ secrets.ACTIONS_VERSION_UPDATER_TOKEN }} update_version_with: release-commit-sha - pull_request_labels: "dependencies, automated" + pull_request_labels: "automated, dependencies" permissions: contents: write diff --git a/.github/workflows/update_dev_deps.yml b/.github/workflows/update_dev_deps.yml new file mode 100644 index 00000000..69f5d078 --- /dev/null +++ b/.github/workflows/update_dev_deps.yml @@ -0,0 +1,30 @@ +name: update dev deps + +"on": + schedule: + # First day of each month at noon + - cron: "0 12 1 * *" + workflow_dispatch: + +jobs: + main: + runs-on: ubuntu-latest + steps: + - name: check out code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: install Nix + uses: DeterminateSystems/nix-installer-action@cd46bde16ab981b0a7b2dce0574509104543276e + # - name: set up upterm session + # uses: lhotari/action-upterm@v1 + - name: update development dependencies + run: nix develop --command bash -c './init_dev_env && ./update_dev_dependencies' + - name: create PR + uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 + with: + token: ${{ secrets.ACTIONS_VERSION_UPDATER_TOKEN }} + title: Update development dependencies + labels: automated,dependencies + +permissions: + contents: read + pull-requests: write diff --git a/.github/workflows/update_flake_lock.yml b/.github/workflows/update_flake_lock.yml index d99b76a9..883cdef9 100644 --- a/.github/workflows/update_flake_lock.yml +++ b/.github/workflows/update_flake_lock.yml @@ -1,26 +1,27 @@ -name: flake.lock updater +name: update flake.lock "on": workflow_dispatch: schedule: - # First day of each month at noon - - cron: "0 12 1 * *" + # Third day of each month at noon + - cron: "0 12 3 * *" jobs: main: runs-on: ubuntu-latest steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - name: Install Nix + - name: check out code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: install Nix uses: DeterminateSystems/nix-installer-action@cd46bde16ab981b0a7b2dce0574509104543276e - - name: Update flake.lock + - name: update flake.lock uses: DeterminateSystems/update-flake-lock@da2fd6f2563fe3e4f2af8be73b864088564e263d with: token: ${{ secrets.FLAKE_LOCK_UPDATE_ACTION_TOKEN }} pr-title: "Update flake.lock" pr-labels: | - dependencies automated + dependencies permissions: contents: read diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index b5f268a7..ae2b7775 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -55,12 +55,21 @@ Making Changes - If not using a VSCode devcontainer, you can try the following to set up a development environment manually: - ``./init_dev_env`` - This requires you to either already have Python and pre-commit on your PATH, - or to just have Nix and direnv, in which case all development dependencies - will be auto-installed and added to your PATH in an isolated development environment - every time you cd into your clone (and auto-removed when you cd out of it). + - If you have `Nix `__, you can run + ``nix develop`` from within your clone to start a shell + where all supported Python versions as well as ``pre-commit`` + are installed and added to your PATH. + + Otherwise, manually ensure you have `pre-commit `__ + and at least the latest `stable Python version `__ + installed and on your PATH. + + - Run ``./init_dev_env`` + + This installs the git hooks for ``pre-commit`` in your clone, + creates a virtualenv with all the development dependencies installed, + and reminds you to activate the virtualenv env it just created when ready. - Create a topic branch off of ``main`` for your changes: ``git checkout -b main`` diff --git a/flake.lock b/flake.lock index 033a40a8..c2f5bd16 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1704825482, - "narHash": "sha256-yqnBfOu0//lZnGoeWA8p0R3gO5gnNhE0DahPD4vbkEs=", + "lastModified": 1705175803, + "narHash": "sha256-u+WX/r8j+jKef3IAVNWW8fznj7pn9kkaMtzjten2Qec=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ae34cddb51a9ed2c1c32b0fd7d5d6f8029509c4c", + "rev": "2284e61bd9df081fb2d4cc162b1d6b3d9752b02d", "type": "github" }, "original": { diff --git a/init_dev_env b/init_dev_env index 90838ece..699db8f6 100755 --- a/init_dev_env +++ b/init_dev_env @@ -6,7 +6,7 @@ set -euo pipefail declare -r _default_py_minor_ver="12" export DEV_PY="python3.$_default_py_minor_ver" -declare -r hint="Hint: Use direnv + ./flake.nix to bootstrap a development environment" +declare -r hint="Hint: Use 'nix develop' to bootstrap a development environment" if ! type "$DEV_PY"; then >&2 echo "Error: No $DEV_PY on PATH. $hint" diff --git a/upgrade-dev-dependencies b/update_dev_dependencies similarity index 86% rename from upgrade-dev-dependencies rename to update_dev_dependencies index f102ef3d..a955d6c9 100755 --- a/upgrade-dev-dependencies +++ b/update_dev_dependencies @@ -34,20 +34,14 @@ main() { exit 3 fi - local -r gitbranch=$(git branch --show-current) - if [ "$gitbranch" = "deps" ] || [ "$gitbranch" = "dev" ]; then - log "Already on branch '$gitbranch'" - elif [ "$gitbranch" = "main" ]; then - git checkout -b deps main - else - log "Error: On unsupported branch '$gitbranch'. Switch to 'main' and try again." - exit 3 - fi - - log "Upgrading PyPI dependencies..." local -r pip_compile="pip-compile --strip-extras --generate-hashes --reuse-hashes --upgrade --allow-unsafe" for py in python3.12 python3.11 python3.10 python3.9 python3.8 pypy3.10 pypy3.9; do + if ! $py -m sysconfig >/dev/null; then + log "Detected broken $py installation -> skipping" + continue + fi local manage_deps_env=".venv/deps/$py" + log "Upgrading PyPI dependencies for $manage_deps_env..." [ -e "$manage_deps_env" ] || $py -m venv "$manage_deps_env" "$manage_deps_env/bin/pip" install --upgrade pip "$manage_deps_env/bin/pip" install --upgrade pip-tools