diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..3d96015 --- /dev/null +++ b/Justfile @@ -0,0 +1,114 @@ +# just manual: https://github.com/casey/just + +_default: + @just --list + +# Runs clippy on the sources +check: + cargo clippy --locked -- -D warnings + +# Runs nextest +test: + cargo nextest run + +# Sets up a watcher that lints, tests, and builds +watch: + cargo watch -x 'clippy --all-targets --all-features -- -D warnings' -x 'nextest run' -x 'build --release' + +# Update the changelog using git-cliff +_update_changelog version: + #!/usr/bin/env bash + set -euxo pipefail + + # Update changelog + if ! command -v git-cliff &> /dev/null + then + echo "Please install git-cliff: https://github.com/orhun/git-cliff#installation" + exit + fi + + git-cliff --unreleased --tag {{version}} --prepend CHANGELOG.md + ${EDITOR:-vi} CHANGELOG.md + git commit CHANGELOG.md -m "docs(CHANGELOG): add entry for {{version}}" + +# Increment the version +_incr_version version: (_update_changelog version) + #!/usr/bin/env bash + set -euxo pipefail + + # Update version + cargo set-version {{trim_start_match(version, "v")}} + cargo build --release + git commit Cargo.toml Cargo.lock -m "chore(release): bump version to {{version}}" + +# Get the changelog and git stats for the release +_tlog describe version: + # Format git-cliff output friendly for the tag + @git cliff --unreleased --tag {{version}} | sd "(^## .*\n\s+|^See the.*|^\[.*|^\s*$|^###\s)" "" + @echo "$ git stats -r {{describe}}..{{version}}" + @git stats -r {{describe}}..HEAD + +# Target can be ["major", "minor", "patch", or a version] +release target: + #!/usr/bin/env python3 + # Inspired-by: https://git.sr.ht/~sircmpwn/dotfiles/tree/master/bin/semver + import os + import subprocess + import sys + import tempfile + + if subprocess.run(["git", "branch", "--show-current"], stdout=subprocess.PIPE + ).stdout.decode().strip() != "main": + print("WARNING! Not on the main branch.") + + subprocess.run(["git", "pull", "--rebase"]) + p = subprocess.run(["git", "describe", "--abbrev=0"], stdout=subprocess.PIPE) + describe = p.stdout.decode().strip() + old_version = describe[1:].split("-")[0].split(".") + if len(old_version) == 2: + [major, minor] = old_version + [major, minor] = map(int, [major, minor]) + patch = 0 + else: + [major, minor, patch] = old_version + [major, minor, patch] = map(int, [major, minor, patch]) + + new_version = None + + if "{{target}}" == "patch": + patch += 1 + elif "{{target}}" == "minor": + minor += 1 + patch = 0 + elif "{{target}}" == "major": + major += 1 + minor = patch = 0 + else: + new_version = "{{target}}" + + if new_version is None: + if len(old_version) == 2 and patch == 0: + new_version = f"v{major}.{minor}" + else: + new_version = f"v{major}.{minor}.{patch}" + + p = subprocess.run(["just", "_tlog", describe, new_version], + stdout=subprocess.PIPE) + shortlog = p.stdout.decode() + + p = subprocess.run(["just", "_incr_version", new_version]) + if p and p.returncode != 0: + print("Error: _incr_version returned nonzero exit code") + sys.exit(1) + + with tempfile.NamedTemporaryFile() as f: + basename = os.path.basename(os.getcwd()) + f.write(f"{basename} {new_version}\n\n".encode()) + f.write(shortlog.encode()) + f.flush() + subprocess.run(["git", "tag", "-e", "-F", f.name, "-a", new_version]) + print(new_version) + +# Publish a new version on crates.io +publish: + cargo publish diff --git a/contrib/_incr_version b/contrib/_incr_version deleted file mode 100755 index dc56ec2..0000000 --- a/contrib/_incr_version +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -set -e - -# Update changelog -if ! command -v git-cliff &> /dev/null -then - echo "Please install git-cliff: https://github.com/orhun/git-cliff#installation" - exit -fi - -git-cliff --unreleased --tag $2 --prepend CHANGELOG.md -${EDITOR:-vi} CHANGELOG.md -git commit CHANGELOG.md -m "docs(CHANGELOG): add entry for $2" - -# Update version -cargo set-version ${2:1} -cargo build --release -git commit Cargo.toml Cargo.lock -m "chore(release): bump version to $2"