Skip to content

Commit

Permalink
Move from nix-shell to flakes (#53)
Browse files Browse the repository at this point in the history
* Trying vanilla flakes

* Trying flake-parts

* impure test multiple Python versions

* Test `make examples` in nix flake check

* test against all supported python versions in nix flake check

* run pure tests on different Python versions in parallel

* Show how to drop into other Python versions

Also, fix devShell in py39 and py311

* Provide a Docker-based development environment for people not using Nix

Also, remove `examples.md` as prompt is already tested in `README.md`.

* Nicer flake names

* Remove tooling installed by pre-commit-hooks-nix flake from poetry dependencies

* update dev dependencies

* add macOS testing to CI

* gardening

* rename package `appEnv-` to `tesh-`
  • Loading branch information
zupo authored Oct 28, 2023
1 parent 35a817a commit 7893e94
Show file tree
Hide file tree
Showing 18 changed files with 718 additions and 768 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
.direnv
result/
8 changes: 2 additions & 6 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
# Use shell.nix to build the development environment
if [ -x "$(command -v lorri)" ]; then
eval "$(lorri direnv)"
else
use nix
fi
# Use flake.nix to build the development environment
use flake
23 changes: 0 additions & 23 deletions .github/actions/nix-shell/action.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .github/actions/uncommitted-changes/action.yml

This file was deleted.

113 changes: 90 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,106 @@ concurrency:

jobs:

tests:
tests_linux:
name: Tests on Linux

strategy:
matrix:
python: ["python3.9", "python3.10", "python3.11"]

name: Tests

runs-on: ubuntu-latest
steps:
- name: Convert matrix python version to nix python version
run: echo "PYTHON=$(echo ${{ matrix.python }} | tr -d .)" >> $GITHUB_ENV

- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
- uses: cachix/cachix-action@v12
with:
name: oceansprint
authToken: '${{ secrets.CACHIX_AUTH_TOKEN_PUBLIC }}'

- name: Run linters and unit tests the Nix way
run: |
nix build .#checks.x86_64-linux.pre-commit
nix build .#devShells.x86_64-linux.$(echo $PYTHON)
nix build .#packages.x86_64-linux.tesh-$(echo $PYTHON)
nix build .#packages.x86_64-linux.testEnv-$(echo $PYTHON)
nix build .#checks.x86_64-linux.tests-$(echo $PYTHON)
tests_macos:
name: Tests on macOS

strategy:
matrix:
python: ["python3.9", "python3.10", "python3.11"]

runs-on: macos-13
steps:
- name: Convert matrix python version to nix python version
run: echo "PYTHON=$(echo ${{ matrix.python }} | tr -d .)" >> $GITHUB_ENV

- uses: actions/checkout@v3
- uses: ./.github/actions/nix-shell
- uses: cachix/install-nix-action@v22
- uses: cachix/cachix-action@v12
with:
cachix_auth_token: '${{ secrets.CACHIX_AUTH_TOKEN_PUBLIC }}'
name: oceansprint
authToken: '${{ secrets.CACHIX_AUTH_TOKEN_PUBLIC }}'

- name: Install Poetry environment
env:
PYTHON: ${{ matrix.python }}
- name: Run linters and unit tests the Nix way
run: |
nix-shell --run "poetry env use $PYTHON"
nix-shell --run "poetry install"
nix build .#checks.x86_64-darwin.pre-commit
nix build .#devShells.x86_64-darwin.$(echo $PYTHON)
nix build .#packages.x86_64-darwin.tesh-$(echo $PYTHON)
nix build .#packages.x86_64-darwin.testEnv-$(echo $PYTHON)
nix build .#checks.x86_64-darwin.tests-$(echo $PYTHON)
docker_linux:
name: Docker on Linux

- name: Run linters and unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Build Docker image with nix env for tesh development
run: docker build -t tesh .

- name: Start a container
run: docker run -d --rm -v .:/tesh --name tesh -it tesh

- name: Make git happy so that pre-commit checks in `make lint` work
run: docker exec tesh git config --global --add safe.directory /tesh

- name: Run all tests
run: docker exec tesh nix develop -c make tests

docker_macos:
name: Docker on macOS

runs-on: macos-13
steps:
- uses: actions/checkout@v3

- name: Install & start Docker
run: |
nix-shell --run "make lint all=true"
nix-shell --run "make types"
nix-shell --run "make unit"
nix-shell --run "make tesh"
nix-shell --run "make examples"
brew install docker colima
colima start
- uses: ./.github/actions/uncommitted-changes
- name: Build Docker image with nix env for tesh development
run: docker build -t tesh .

- name: Start a container
run: docker run -d --rm -v .:/tesh --name tesh -it tesh

- name: Make git happy so that pre-commit checks in `make lint` work
run: docker exec tesh git config --global --add safe.directory /tesh

- name: Run all tests
run: docker exec tesh nix develop -c make tests

release:
name: Release
needs: tests
needs: [tests_linux, tests_macos]

# To test publishing to testpypi:
# * comment out "verify git tag matches pyproject.toml version"
Expand All @@ -75,15 +141,16 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/nix-shell
- uses: cachix/install-nix-action@v22
- uses: cachix/cachix-action@v12
with:
cachix_auth_token: '${{ secrets.CACHIX_AUTH_TOKEN_PUBLIC }}'
name: oceansprint
authToken: '${{ secrets.CACHIX_AUTH_TOKEN_PUBLIC }}'

- name: Verify git tag matches pyproject.toml version

run: |
GIT_VERSION=$GITHUB_REF_NAME
POETRY_VERSION=`nix-shell --run "poetry version --short"`
POETRY_VERSION=`nix develop -c poetry version --short`
echo $GIT_VERSION
echo $POETRY_VERSION
Expand All @@ -93,7 +160,7 @@ jobs:
- name: Build tesh wheel
run: |
nix-shell --run "poetry build"
nix develop -c poetry build
- name: Upload wheel to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ junit.xml

# pyc
__pycache__

# nix stuff
result
.pre-commit-config.yaml
65 changes: 0 additions & 65 deletions .pre-commit-config.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
rules:
line-length:
max: 88

ignore:
- .pre-commit-config.impure.yaml
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ubuntu:23.10
RUN apt-get update \
&& apt-get install nano git nix -y \
&& echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf \
&& echo "max-jobs = 4" >> /etc/nix/nix.conf
COPY ./. /tesh
RUN nix develop /tesh -c true
WORKDIR /tesh
CMD nix develop
20 changes: 7 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Convenience makefile to build the dev env and run common commands
PYTHON ?= python3.11

.PHONY: all
all: tests
Expand All @@ -14,19 +13,19 @@ lint:
# 3. get all untracked files
# 4. run pre-commit checks on them
ifeq ($(all),true)
@poetry run pre-commit run --hook-stage push --all-files
@pre-commit run --all-files
else
@{ git diff --name-only ./; git diff --name-only --staged ./;git ls-files --other --exclude-standard; } \
| sort -u | uniq | poetry run xargs pre-commit run --hook-stage push --files
| sort -u | uniq | xargs pre-commit run --hook-stage push --files
endif

.PHONY: type
type: types

.PHONY: types
types: .
@poetry run mypy src/tesh
@poetry run typecov 100 ./typecov/linecount.txt
@mypy src/tesh
@typecov 100 ./typecov/linecount.txt


# anything, in regex-speak
Expand Down Expand Up @@ -58,18 +57,14 @@ endif
.PHONY: unit
unit:
ifndef path
@poetry run pytest src/tesh $(verbosity) $(full_suite_args) $(pytest_args)
@pytest src/tesh $(verbosity) $(full_suite_args) $(pytest_args)
else
@poetry run pytest $(path)
@pytest $(path)
endif

.PHONY: tesh
tesh:
@poetry run tesh *.md

.PHONY: examples
examples:
@poetry run tesh examples/
@tesh *.md

.PHONY: test
test: tests
Expand All @@ -80,4 +75,3 @@ tests:
@make types
@make unit
@make tesh
@make examples
Loading

0 comments on commit 7893e94

Please sign in to comment.