-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtarball_script.sh
executable file
·133 lines (111 loc) · 3.65 KB
/
tarball_script.sh
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/sh
set -e
find_next_version() {
datestamp="${datestamp:-$(date +%Y%m%d)}"
index=1
MILESTONEDIR="${MILESTONEDIR:-$HOME/versions/milestone}"
BRANCH=${BRANCH:-trunk}
milestonefile="${MILESTONEDIR}/${PROJECT}-${BRANCH}"
if [ ! -e "${milestonefile}" ]
then
if [ "$NOMILESTONE" = "true" ]
then
milestonever=""
else
echo "Milestone file ${milestonefile} not found. Bailing out." >&2
exit 1
fi
else
milestonever="$(cat ${milestonefile})"
fi
if false # Because we only need this madness if we're using git, that's why!
then
while true
do
version="$milestonever"
if [ -n "$version" ]
then
version="${version}~"
fi
version="$(printf %s%s.%s%d "${version}" "$datestamp" "$REVNOPREFIX" "$index")"
if grep -q "^$PROJECT $version$" "$RECORDFILE"
then
echo "$version of $PROJECT already exists. Bumping index." >&2
index="$(($index + 1))"
else
break
fi
done
else
version="$milestonever"
if [ -n "$version" ]
then
version="${version}~"
fi
if [ -d .git ]
then
revno="${revno:-$(git log --oneline | wc -l)}"
else
revno="${revno:-$(bzr revno)}"
fi
version="$(printf %s%s.%s%d "$version" "$datestamp" "$REVNOPREFIX" "$revno")"
if grep -q "^$PROJECT $version$" "$RECORDFILE"
then
echo "$version of $PROJECT already exists. Bailing out." >&2
exit 1
fi
fi
printf "%s" "$version"
}
if [ "$1" = "test" ]
then
PROJECT="testproj"
datestamp="12345678"
RECORDFILE=$(mktemp)
MILESTONEDIR=$(mktemp -d)
BRANCH=foo
revno="99923"
REVNOPREFIX="r"
# Verify that we skip already built versions
echo "d2" > "${MILESTONEDIR}/$PROJECT-${BRANCH}"
echo "$PROJECT d2~$datestamp.001" > $RECORDFILE
expected_version="d2~12345678.r99923"
actual_version="$(find_next_version)"
test "${actual_version}" = "${expected_version}" || (echo Got ${actual_version}, expected ${expected_version} ; exit 1)
echo "For a milestoned project, we'd get: ${expected_version}"
PROJECT="testproj2"
NOMILESTONE=true
expected_version="12345678.r99923"
actual_version="$(find_next_version)"
test "${actual_version}" = "${expected_version}" || (echo Got ${actual_version}, expected ${expected_version} ; exit 1)
echo "For a non-milestoned project, we'd get: ${expected_version}"
echo All tests passed
exit 0
fi
if [ -z "$PROJECT" ]
then
echo '$PROJECT not set.'
exit 1
fi
VERSIONDIR="$HOME/versions"
RECORDFILE="$VERSIONDIR/tarballversions"
if [ ! -d "$VERSIONDIR" ]
then
bzr co bzr://jenkins.openstack.org/ "$VERSIONDIR"
else
( cd $VERSIONDIR ; bzr up )
fi
snapshotversion=$(find_next_version)
# Should be ~ if tarball version is the one we're working *toward*. (By far preferred!)
# Should be + if tarball version is already released and we're moving forward after it.
SEPARATOR=${SEPARATOR:-'~'}
rm -f dist/*.tar.gz
python setup.py sdist
# There should only be one, so this should be safe.
tarball=$(echo dist/*.tar.gz)
echo mv "$tarball" "dist/$(basename $tarball .tar.gz)${SEPARATOR}${snapshotversion}.tar.gz"
mv "$tarball" "dist/$(basename $tarball .tar.gz)${SEPARATOR}${snapshotversion}.tar.gz"
echo "$PROJECT ${snapshotversion}" >> "$RECORDFILE"
sort "$RECORDFILE" > "$RECORDFILE".tmp
mv "$RECORDFILE".tmp "$RECORDFILE"
(cd $VERSIONDIR; bzr commit -m"Added $PROJECT ${snapshotversion}")