Skip to content

Commit

Permalink
Add 'update dev deps' workflow, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
jab committed Jan 13, 2024
1 parent 734622b commit 0de05c2
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 50 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: linters
name: lint

"on":
push:
Expand All @@ -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

Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/release-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/release-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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'
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: tests
name: test

"on":
workflow_dispatch:
Expand Down Expand Up @@ -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: |
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/update_actions.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://github.com/marketplace/actions/github-actions-version-updater

name: GitHub Actions updater
name: update GitHub Actions

"on":
workflow_dispatch:
Expand All @@ -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
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/update_dev_deps.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 8 additions & 7 deletions .github/workflows/update_flake_lock.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 14 additions & 5 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://nixos.org>`__, 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 <https://pre-commit.com>`__
and at least the latest `stable Python version <https://python.org/downloads/>`__
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 <topic> main``
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion init_dev_env
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 5 additions & 11 deletions upgrade-dev-dependencies → update_dev_dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0de05c2

Please sign in to comment.