aboutsummaryrefslogtreecommitdiff
path: root/aux/workflow/dist.sh
blob: 48a9d57906221adf304205ffd0a9bd0a2e769ce6 (about) (plain) (blame)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh
set -eu

PROJECT_UC=
while getopts 'd:V:n:N:m:' flag; do
	case "$flag" in
		d)
			DATE="$OPTARG"
			;;
		V)
			VVERSION="v$OPTARG"
			;;
		n)
			PROJECT="$OPTARG"
			;;
		N)
			PROJECT_UC="$OPTARG"
			;;
		m)
			MAILING_LIST="$OPTARG"
			;;
		*)
			exit 2
			;;
	esac
done
shift $((OPTIND - 1))

assert_arg() {
	if [ -z "$1" ]; then
		echo "Missing $2" >&2
		exit 2
	fi
}

assert_arg "${DATE:-}"         '-d DATE'
assert_arg "${VVERSION:-}"     '-V VERSION'
assert_arg "${PROJECT:-}"      '-n PROJECT'
assert_arg "${MAILING_LIST:-}" '-m MAILING_LIST'

if [ -z "${PROJECT_UC:-}" ]; then
	PROJECT_UC="$PROJECT"
fi


if [ "$(git rev-parse --abbrev-ref HEAD)" != 'main' ]; then
	echo 'Not on branch "main".' >&2
	exit 1
fi

if git show "$VVERSION" 1>/dev/null 2>/dev/null; then
	echo "Version '$VVERSION' already exists." >&2
	exit 1
fi

if [ "v$(awk '/^VERSION *=/{print $3; exit}' Makefile)" != "$VVERSION" ]; then
	echo "Version '$VVERSION' mismatch with \$(VERSION) in Makefile." >&2
	echo 'Make sure to invoke this script with "make dist".' >&2
	exit 1
fi

if ! printf '%s\n%s\n' "$(git tag)" "$VVERSION" | sort -nct. -k1 -k2 -k3; then
	echo 'New tag is not bigger than existing ones.' >&2
	exit 1
fi

if [ "$DATE" != "$(git log -1 --format=%cd --date=short HEAD)" ]; then
	echo "Date '$DATE' is not up-to-date." >&2
	exit 1
fi

if [ "$(awk '/^DATE *=/{print $3; exit}' Makefile)" != "$DATE" ]; then
	echo "Date '$DATE' mismatch with \$(DATE) in Makefile." >&2
	echo 'Make sure to invoke this script with "make dist".' >&2
	exit 1
fi

if [ "Release $VVERSION" != "$(git log --format=%B -1 HEAD | head -n1)" ]; then
	echo "Commit message isn't 'Release $VVERSION'." >&2
	exit 1
fi

make clean
make dev-check EXTRA_VERSION="$VVERSION"

if ! (git diff --quiet && git diff --quiet --staged); then
	echo 'Dirty repository.'
	exit 1
fi


git tag "$VVERSION"
sh aux/workflow/sign-tarballs.sh -n "$PROJECT"


printf 'Publish version? [Y/n]: ' >&2
read -r publish

if [ "$publish" = 'n' ]; then
	cat <<EOF >&2
Now push the tag and the signature before pushing the commit:

git push origin refs/notes/signatures/tar.gz -o skip-ci --no-verify
git push --tags -o skip-ci --no-verify
git push

EOF
else
	git push origin refs/notes/signatures/tar.gz -o skip-ci --no-verify
	git push --tags -o skip-ci --no-verify
	git push
fi