summaryrefslogtreecommitdiff
path: root/jenkins-makesources
blob: bd497944f64728b870116028eb175b0dff854f09 (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
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
#!/bin/bash

# makes a source package out of a git tree and packaging git tree
# usage:
#   jenkins-makesources conffile
# 
# conffile:
# 
# upstream_source     = source package name
# upstream_repo       = git url to upstream 
#
# packaging_dir       = directory of the debian/ contents
# packaging_repo      = git url to packaging
# packaging_tar       = do package in tar mode
# base_version        = base version for package
# distribution        = target distro
# output_file         = file to output dsc filename to - defaults to upstream_source.dsc
# 
# variables may already by set, in that case just call this with 
#   ./jenkins-makesources
# 

set -e 

if [ -r "$1" ];
then
    source "$1"
fi

base_version=${base_version:-0}
distribution=${distribution:-sid}
BUILD_NUMBER=${BUILD_NUMBER:-1}
output_file=${output_file:-${upstream_source}.dsc}

if [ ! -d $upstream_source ]
then
    git clone $upstream_repo $upstream_source
fi
(cd $upstream_source && git fetch --tags)

if [ -z $packaging_tar ]
then

    if [ ! -d $packaging_dir ]
    then
        git clone $packaging_repo $packaging_dir
    fi
    packaging_commit=`cd $packaging_dir && git log -n1 --pretty=format:%h`
else
    rm -f *debian.tar*
    wget $packaging_tar
    tar xaf *debian.tar*
    packaging_commit=""
    packaging_dir=debian/

fi

upstream_commit=`cd $upstream_source && git log -n1 --pretty=format:%h`

git_version=`cd $upstream_source && git describe --match='v*'`||git_version=$base_version.`date +%Y%m%d`
pkg_version=`echo $git_version|sed  -e 's/^v//' -e 's/-rc/~rc/' -e 's/-\([0-9]*\)-/+git\1+/'`

currentdate=`date -R`
pkg_dir=${upstream_source}-${pkg_version}

cp -a $upstream_source "${pkg_dir}.orig"
rm -rf "${pkg_dir}.orig/.git"
cp -a "${pkg_dir}.orig" "${pkg_dir}"
cp -a $packaging_dir "${pkg_dir}"
tar caf ${upstream_source}_${pkg_version}.orig.tar.xz ${pkg_dir}.orig

version=${pkg_version}-${BUILD_NUMBER}linaro+${distribution}

echo "Preparing ${version}"

cat > ${pkg_dir}/debian/changelog << EOF
${upstream_source} (${version}) ${distribution}; urgency=low

  * CI - ${upstream_source} snapshot:
    - repository: ${upstream_repo}
    - commit: ${upstream_commit}
    - build: ${BUILD_URL}

    - debian/ repository: ${packaging_repo}
    - debian/ commit: ${packaging_commit}

 -- Linaro Packagers <linaro-pkg@lists.launchpad.net>  ${currentdate}

EOF

cd ${pkg_dir}
dpkg-buildpackage -d -nc -us -uc -rfakeroot -S
cd ..
rm -rf ${pkg_dir}

echo ${upstream_source}_${version}.dsc > ${output_file}