summaryrefslogtreecommitdiffstats
path: root/scripts/make_release.sh
blob: 7c1013a3c5bf04ebc77a6008d166874748c8ade8 (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
#!/bin/bash

set -e

origin=origin
v="v"

branch="$(git symbolic-ref HEAD)"
branch="${branch##refs/heads/}"

trap_exit_handler() {
    if [ -n "${tmp}" -a -d "${tmp}" ]; then
	rm -rf "${tmp}"
    fi
}
trap 'trap_exit_handler' 0 1 15

# Update index only on r/w media
if [ -w . ]; then
    git update-index --refresh --unmerged > /dev/null || true
fi

# Check for uncommitted changes
if git diff-index --name-only HEAD \
    | read dummy; then
    echo "tree dirty, refusing to make a release" >&2
    exit 1
fi

# guess if we're going to make a new or stable release
case "${branch}" in
    master)
	release="${v}$(date +%Y.%m).0"
	prev_release="${v}*.0"
	;;
    stable/*)
	release="${v}${branch##stable/*-}"
	release="${release%.x}"
	inc="$(git tag -l "${release}.*" | wc -l)"
	if [ ${inc} -eq 0 ]; then
	    echo "about to make stable a release for '${release}', but no '.0' found" >&2
	    exit 1
	fi
	prev_release="${release}.$((inc - 1))"
	release="${release}.${inc}"
	;;
    *)
	echo "please checkout either master or stable branch" >&2
	exit 1
	;;
esac

# get previous release
prev_release=( $(git tag -l "${prev_release}" | sort -r -n) )
if [ -z "${prev_release}" ]; then
    echo "previous release not found" >&2
    exit 1
fi

# check if to-be-made release already exists
if git rev-parse -q --verify "refs/tags/$release" >/dev/null 2>&1; then
    echo "release '${release}' already exists" >&2
    exit 1
fi

config_release="$(sed -n 's/^PTXCONF_PROJECT="OSELAS.Toolchain-\(.*\)"/\1/p' ptxconfigs/*.ptxconfig | sort -u)"
if [ "${release#${v}}" != "${config_release}" ]; then
	echo "release version(s) from the ptxconfigs (${config_release}) do not match '${release#${v}}'" >&2
	exit 1
fi

if grep -q UNRELEASED debian/changelog; then
	echo "debian changelog entry must not be UNRELEASED" >&2
	exit 1
fi

if [ "${1}" == "--test" ]; then
	echo "test mode: all checks ok -- stopping"
	exit
fi

tmp="$(mktemp -d /tmp/${0##*/}.XXXXXX)"
log="${tmp}/log"

# create tag message
printf "${release}\n\n" > "${log}"
git shortlog "${prev_release}"..HEAD >> "${log}"
echo "creating tag '${release}'"
git tag -s -F "${log}" "${release}"

# create tarball
here="$(pwd)"
pushd "${tmp}" >/dev/null
git clone "${here}" "${release}"
cd "${release}"
git checkout "${release}"

make dist
popd >/dev/null

# now push to origin
echo
echo "pushing '${release}' to $origin, press '[Ctrl] + c' to abort"
echo
read
git push "${origin}" "${branch}"
git push "${origin}" "${release}"
mv "${tmp}/${release}/"*tar.bz2* "${here}"