~nskaggs/juju-ci-tools/add-essential-operations

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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
#
# Create source and binary packages using a source package branch and
# a release tarball.

set -e

HERE=$(pwd)
TMP_DIR=$(mktemp -d --tmpdir=$HERE)
PACKAGING_DIR="$TMP_DIR/packaging"
BUILD_DIR="$TMP_DIR/build"
DEFAULT_STABLE_PACKAGING_BRANCH="lp:ubuntu/juju-core"
DEFAULT_DEVEL_PACKAGING_BRANCH="lp:~juju-qa/juju-core/devel-packaging"
DEFAULT_1_16_PACKAGING_BRANCH="lp:~juju-qa/juju-core/1.16-packaging"
DEVEL_SERIES=$(distro-info --devel --codename)
DEVEL_VERSION=$(distro-info --release --devel | cut -d ' ' -f1)
EXTRA_RELEASES="saucy:13.10 precise:12.04"


usage() {
    echo "usage: $0 <PURPOSE> tarball 'name-email' [bug-number ...]"
    echo "  PURPOSE: stable, devel, or testing,"
    echo "     which selects the packaging branch."
    echo "  tarball: The path to the juju-core tarball."
    echo "  name-email: The 'name <email>' string used in the changelog."
    echo "  bug-number: Zero or more Lp bug numbers"
    exit 1
}


check_deps() {
    echo "Phase 0: Checking requirements."
    has_deps=1
    which dch || has_deps=0
    which bzr || has_deps=0
    bzr plugins | grep builddeb || has_deps=0
    if [[ $has_deps == 0 ]]; then
        echo "Install devscripts, bzr, and bzr-builddeb"
        exit 2
    fi
}


make_source_package_branch() {
    echo "Phase 1: Updating the source package branch."
    echo "Using $PACKAGING_BRANCH"
    bzr branch $PACKAGING_BRANCH $PACKAGING_DIR
    cd $PACKAGING_DIR
    bzr import-upstream $VERSION $TARBALL
    bzr merge . -r upstream-${VERSION}
    if [[ $PURPOSE == "stable" ]]; then
        if [[ $VERSION =~ .*\.0$ ]]; then
            message="New upstream stable release."
        else
            message="New upstream point release."
        fi
        distro=$DEVEL_SERIES
    elif [[ $PURPOSE == "devel" ]]; then
        message="New upstream devel release."
        distro=$DEVEL_SERIES
    else
        message="New upstream release candidate."
        distro="UNRELEASED"
    fi
    if [[ $BUGS != "" ]]; then
        message="$message (LP: $BUGS)"
    fi
    DEBEMAIL=$DEBEMAIL dch --newversion $UBUNTU_VERSION -D $distro "$message"
    bzr ci -m "$message"
    bzr tag $UBUNTU_VERSION
}


make_source_package() {
    echo "Phase 2: Creating the source package for ubuntu devel."
    cd $PACKAGING_DIR
    bzr bd -S --build-dir=$BUILD_DIR
    cd $BUILD_DIR
    echo "The source package can be uploaded:"
    echo "  cd $TMP_DIR"
    echo "  dput $PPA juju-core_${UBUNTU_VERSION}_source.changes"
}


make_binary_package() {
    package_version=$1
    package_series=$2
    echo "Phase 3: Creating the binary package for $package_series."
    cd $PACKAGING_DIR
    bzr bd --build-dir=$BUILD_DIR -- -uc -us
    new_package=$(ls ${TMP_DIR}/juju-core_${package_version}*.deb)
    echo "Made $new_package"
    ln -s $new_package ${TMP_DIR}/new-${package_series}.deb
    echo "linked $new_package to ${TMP_DIR}/new-${package_series}.deb"
}


update_source_package_branch() {
    package_version=$1
    package_series=$2
    echo "Phase 4: Backport the source package branch to $package_series."
    cd $PACKAGING_DIR
    message="New upstream release candidate."
    distro="UNRELEASED"
    DEBEMAIL=$DEBEMAIL dch -b --newversion $package_version \
        -D $distro "$message"
    bzr ci -m "$message"
    bzr tag $package_version
}


test $# -ge 3 || usage

PURPOSE=$1
TARBALL=$(readlink -f $2)
if [[ ! -f "$TARBALL" ]]; then
    echo "Tarball not found."
    usage
fi

VERSION=$(basename $TARBALL .tar.gz | cut -d '_' -f2)
UBUNTU_VERSION="${VERSION}-0ubuntu1"

DEBEMAIL=$3

shift; shift; shift
BUGS=$(echo "$@" | sed  -e 's/ /, /g; s/\([0-9]\+\)/#\1/g;')

if [[ $VERSION =~ ^1\.16\.* ]]; then
    PACKAGING_BRANCH=$DEFAULT_1_16_PACKAGING_BRANCH
    PPA="ppa:juju-packaging/stable"
elif [[ $PURPOSE == "stable" ]]; then
    PACKAGING_BRANCH=$DEFAULT_STABLE_PACKAGING_BRANCH
    PPA="ppa:juju-packaging/stable"
elif [[ $PURPOSE == "devel" || $PURPOSE == "testing" ]]; then
    PACKAGING_BRANCH=$DEFAULT_DEVEL_PACKAGING_BRANCH
    PPA="ppa:juju-packaging/devel"
else
    usage
fi

check_deps
make_source_package_branch
if [[ $PURPOSE == "testing" ]]; then
    make_binary_package $UBUNTU_VERSION $DEVEL_SERIES
    PACKAGE=$(ls ${TMP_DIR}/juju-core_*.deb)
    echo "The binary package can be installed:"
    echo "  sudo dpkg -i $PACKAGE"
    # Make extra packages for supported series.
    for series_release in $EXTRA_RELEASES; do
        this_series=$(echo "$series_release" | cut -d ':' -f1)
        this_release=$(echo "$series_release" | cut -d ':' -f2)
        package_version="${UBUNTU_VERSION}~ubuntu${this_release}.1"
        update_source_package_branch $package_version $this_series
        make_binary_package $package_version $this_series
    done
    NEW_PACKAGES=$(ls ${TMP_DIR}/new-*.deb)
    echo "New packages for testing: $NEW_PACKAGES"
else
    make_source_package
fi
echo "You can delete this directory when you are done:"
echo "  $TMP_DIR"