summaryrefslogtreecommitdiff
path: root/release.sh
blob: 1438ff47f9763092e1a64934b02a692c1ae8d029 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash

set -xeuo pipefail

usage() {
	echo "Usage: $0 REMOTE VERSION"
	echo ""
	echo "where REMOTE is the remote for gitlab.com and VERSION is the new version number"
	echo ""
}

msg() {
	echo "$*"
}

die() {
	echo "ERROR: $*" 1>&2
	exit 1
}

current_branch() {
	git status --branch --short | awk '/^##/ { print $2 }'
}

crates() {
	git ls-files | grep Cargo.toml | sed 's,Cargo\.toml$,,' | sed 's,^$,.,'
}

# [ "$(current_branch)" == main ] || die "current branch is not 'main'"

[ "$#" = 2 ] || (
	usage
	die " command line arguments"
)
remote="$1"
version="$2"

if ! echo "$version" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' >/dev/null; then
	die "version number must be numbers and dots only"
fi

# Check that we can publish.
msg "checking that all crates seem OK"
cargo check -q --release --workspace
cargo build -q --release --workspace

# This is disabled, for now, because it fails, because ordering of
# crate publishing matters. Also, a crate can't be mock-published,
# until it's dependencies are published.
if false; then
	msg "checking that all crates can be published"
	for crate in $(crates); do
		(cd "$crate" && msg "mock publishing in $(pwd)" && cargo publish -q --dry-run)
	done
fi

# The actual release.
msg "making actual release"
echo git tag -sam "Subplot release $version" "$version"
echo git push --tags "$remote"
echo cargo publish

msg ""
msg "Subplot version $version has been tagged and published on "
msg "gitlab.com and crates.io. Ask Lars or Daniel to push the tag"
msg "git.liw.fi. Please tell everyone about the new hotness."