diff --git a/CHANGELOG.md b/CHANGELOG.md index 071bbd5..162f367 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,3 +7,4 @@ * fix/project-builds: generated projects install, start and build, with a uv.lock, the right colorlog package, a working FastAPI lifespan and a pinned uv in the dev container. * feature/run-script: generated projects ship a run.sh for building, formatting with ruff, testing with pytest and building a wheel and sdist, with starter tests and ruff-clean code. * feature/github-ci: generated projects ship the shared GitHub CI, a VERSION file and the shared Renovate settings, which copier update leaves alone. +* feature/makefile: generated projects ship a Makefile with build, format, format-dry-run, test and release targets in place of run.sh, with make in the dev container and the shared CI calling make. diff --git a/README.md b/README.md index adeab6e..d8cc428 100644 --- a/README.md +++ b/README.md @@ -54,16 +54,16 @@ The workflow is read-only apart from the tag job, which needs write access to cr ### Project Tasks -Every generated project has a `run.sh` at its root: -* `./run.sh --build` installs the locked dependencies and byte-compiles the package. -* `./run.sh --format` formats the Python sources with ruff; `--format-dry-run` lists unformatted files and fails if there are any. -* `./run.sh --test` runs the tests with pytest. -* `./run.sh --release` builds a wheel and an sdist into `dist/`. +Every generated project has a `Makefile` at its root: +* `make build` installs the locked dependencies and byte-compiles the package. +* `make format` formats the Python sources with ruff; `make format-dry-run` lists unformatted files and fails if there are any. +* `make test` runs the tests with pytest. +* `make release` builds a wheel and an sdist into `dist/`. ### GitHub CI -Generated projects ship with the shared workflow from [template-github-ci](https://github.com/karshosphere/template-github-ci), vendored into `template/.github/`. It expects the project's `run.sh` and `.devcontainer/`, requires a `VERSION` bump on every pull request, and publishes a GitHub release on each merge to main. +Generated projects ship with the shared workflow from [template-github-ci](https://github.com/karshosphere/template-github-ci), vendored into `template/.github/`. It expects the project's `Makefile` and `.devcontainer/`, requires a `VERSION` bump on every pull request, and publishes a GitHub release on each merge to main. To bring in a newer release of the workflow, from this repository's root: diff --git a/VERSION b/VERSION index 79127d8..46b105a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v1.2.0 +v2.0.0 diff --git a/template/.github/.copier-ci-answers.yml b/template/.github/.copier-ci-answers.yml index 4a3d4df..66b57a2 100644 --- a/template/.github/.copier-ci-answers.yml +++ b/template/.github/.copier-ci-answers.yml @@ -1,4 +1,4 @@ # .github/.copier-ci-answers.yml.jinja # Changes here will be overwritten by Copier; NEVER EDIT MANUALLY -_commit: v1.1.1 +_commit: v2.0.0 _src_path: gh:karshosphere/template-github-ci diff --git a/template/.github/workflows/ci.yml b/template/.github/workflows/ci.yml index 35a6097..afe7880 100644 --- a/template/.github/workflows/ci.yml +++ b/template/.github/workflows/ci.yml @@ -54,10 +54,10 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - name: run.sh is present and executable + - name: Makefile is present run: | - [ -x run.sh ] || { - echo "::error file=run.sh::run.sh is missing or not executable" + [ -f Makefile ] || { + echo "::error::Makefile is missing from the project root" exit 1 } - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 @@ -67,13 +67,13 @@ jobs: - name: Start the dev container run: devcontainer up --workspace-folder . - name: Format - run: devcontainer exec --workspace-folder . ./run.sh --format-dry-run + run: devcontainer exec --workspace-folder . make format-dry-run - name: Build - run: devcontainer exec --workspace-folder . ./run.sh --build + run: devcontainer exec --workspace-folder . make build - name: Test - run: devcontainer exec --workspace-folder . ./run.sh --test + run: devcontainer exec --workspace-folder . make test - name: Release build - run: devcontainer exec --workspace-folder . ./run.sh --release + run: devcontainer exec --workspace-folder . make release - if: github.event_name == 'push' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: diff --git a/template/Dockerfile b/template/Dockerfile index 047cf0f..d86419a 100644 --- a/template/Dockerfile +++ b/template/Dockerfile @@ -9,6 +9,7 @@ RUN apt update && apt upgrade -y \ && apt install --no-install-recommends -y \ ca-certificates \ bash \ + make \ curl \ && apt clean \ && apt autoremove \ diff --git a/template/Makefile.jinja b/template/Makefile.jinja new file mode 100644 index 0000000..8735163 --- /dev/null +++ b/template/Makefile.jinja @@ -0,0 +1,22 @@ +# Project tasks. CI runs format-dry-run, build, test and release. + +PACKAGE := {{ module_slug }} + +.PHONY: build format format-dry-run test release + +build: + uv sync --locked + uv run --locked python -m compileall -q $(PACKAGE) + +format: + uv run --locked ruff format . + +format-dry-run: + uv run --locked ruff format --check . + +test: + uv run --locked pytest + +release: + rm -rf dist + uv build --out-dir dist diff --git a/template/README.md.jinja b/template/README.md.jinja index bd29787..678c197 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -15,7 +15,7 @@ ### Build ```bash -$ ./run.sh --build +$ make build ``` ### Run @@ -31,14 +31,14 @@ $ uv run main ### Run all tests ```bash -$ ./run.sh --test +$ make test ``` ### Formatting ```bash -$ ./run.sh --format # format in place -$ ./run.sh --format-dry-run # list files that need formatting +$ make format # format in place +$ make format-dry-run # list files that need formatting ``` @@ -52,7 +52,7 @@ $ ./run.sh --format-dry-run # list files that need formatting ## Release -`./run.sh --release` builds a wheel and an sdist into `dist/`. They install on any platform with Python 3.13. +`make release` builds a wheel and an sdist into `dist/`. They install on any platform with Python 3.13. diff --git a/template/run.sh.jinja b/template/run.sh.jinja deleted file mode 100755 index 635fe91..0000000 --- a/template/run.sh.jinja +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env bash -# Project tasks. CI runs --format-dry-run, --build, --test and --release. - -set -euo pipefail -cd "$(dirname "$0")" - -package="{{ module_slug }}" - -usage() { - cat < - - --build install the locked dependencies and byte-compile the package - --format format the Python sources in place - --format-dry-run list unformatted Python sources and fail if there are any - --test run the tests - --release build the wheel and sdist into dist/ -USAGE -} - -build() { - uv sync --locked - uv run --locked python -m compileall -q "$package" -} - -format() { - uv run --locked ruff format . -} - -format_dry_run() { - uv run --locked ruff format --check . -} - -run_tests() { - uv run --locked pytest -} - -release() { - rm -rf dist - uv build --out-dir dist -} - -case "${1:-}" in - --build) build ;; - --format) format ;; - --format-dry-run) format_dry_run ;; - --test) run_tests ;; - --release) release ;; - -h|--help) usage ;; - *) usage >&2; exit 1 ;; -esac