Skip to content

Commit

Permalink
build: switch from semver to justfile
Browse files Browse the repository at this point in the history
Rather than doing releases via an out-of-band tool [[1]], encapsulate
all the release scripts in a justfile.

The release script is basically my version of Drew Devault's semver
script [[2]].

[1]: https://github.com/lukehsiao/tool
[2]: lukehsiao/dotfiles@f80f707
Ref: https://just.systems/man/en/
Inspired-by: https://git.sr.ht/~sircmpwn/dotfiles/tree/master/bin/semver
  • Loading branch information
lukehsiao committed Jul 17, 2023
1 parent 0024f9a commit d7e4695
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 22 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## [0.1.9] - 2023-07-17

### Build and Dependencies
- (deps) Update lockfile
- (deps) Bump clap from 4.3.8 to 4.3.9
- (deps) Bump clap from 4.3.9 to 4.3.10
- Switch from semver to justfile

### CI/CD
- Only run dependabot monthly


[0.1.9]: https://github.com/lukehsiao/git-stats/compare/v0.1.8...v0.1.9


## 0.1.8 - 2023-06-26

This release essentially just relicenses to BlueOak-1.0.0.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "git-stats"
version = "0.1.8"
version = "0.1.9"
edition = "2021"
authors = ["Luke Hsiao <luke@hsiao.dev>"]
description = "A script for grabbing more thorough shortlog stats"
Expand Down
115 changes: 115 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# 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 'nexttest 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
_shortlog describe version:
# Format git-cliff output friendly for the tag
@git cliff --unreleased --tag {{version}} | sd "(^## .*\n\s+|^See the.*|^\[.*|^\s*$|^###\s)" ""
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", "_shortlog", describe, new_version],
stdout=subprocess.PIPE, stderr=sys.stdout.buffer)
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
3 changes: 1 addition & 2 deletions cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ header = """
# https://tera.netlify.app/docs/#introduction
body = """
{% if version -%}
## {{ version | trim_start_matches(pat="v") }} - {{ timestamp | date(format="%Y-%m-%d") }}
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else -%}
## [Unreleased]
{%- endif %}
Expand All @@ -25,7 +25,6 @@ body = """
{% endif -%}
{% endfor %}
{% endfor -%}
See the commits here: [{{ version | trim_start_matches(pat="v") }}]
{% if previous.version %}
{% if version -%}
[{{ version | trim_start_matches(pat="v") }}]: https://github.com/lukehsiao/git-stats/compare/{{ previous.version }}...{{ version }}
Expand Down
18 changes: 0 additions & 18 deletions contrib/_incr_version

This file was deleted.

0 comments on commit d7e4695

Please sign in to comment.