-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathbuild_source_package
executable file
·116 lines (96 loc) · 3.36 KB
/
build_source_package
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
#!/bin/bash -e
#
# Update the Changelog file to create packages with version/release
# that continuously increments (to ensure `apt-get upgrade` works) and
# that contains identifying information about the package's source (to
# indicate who built the package, how, and from what revision).
# Whether to actually build the source
BUILD_SOURCE=$1
if test "$1" != "true" -a "$1" != "false"; then
echo "Usage: $0 [ true | false ]" >&2
exit 1
fi
# Computed variables
SOURCE_DIR=$(readlink -f $(dirname ${0})/..)
test ${TRAVIS_PULL_REQUEST:-false} = false && IS_PR=false || IS_PR=true
case $TAG in
*_8) DISTRO=jessie ;;
*_9) DISTRO=stretch ;;
*_10) DISTRO=buster ;;
esac
COMMIT_TIMESTAMP="$(git log -1 --pretty=format:%at)"
SHA1SHORT="$(git log -1 --pretty=format:%h)"
COMMITTER_NAME="$(git log -1 --pretty=format:%an)"
COMMITTER_EMAIL="$(git log -1 --pretty=format:%ae)"
BRANCH_NAME="$(git rev-parse --symbolic-full-name HEAD)"
BRANCH_NAME="${BRANCH_NAME//*\//}" # convert / to -
# Supplied variables for package configuration
MAJOR_MINOR_VERSION="${MAJOR_MINOR_VERSION:-0.1}"
TRAVIS_REPO=${TRAVIS_REPO_SLUG:+travis.${TRAVIS_REPO_SLUG/\//.}}
PKGSOURCE="${PKGSOURCE:-${TRAVIS_REPO:-$(hostname)}}"
DEBIAN_SUITE="${DEBIAN_SUITE:-experimental}"
REPO_URL="${REPO_URL:-https://github.com/machinekit/machinekit-cnc}"
# Compute version
if ${IS_PR}; then
# Use build timestamp (now) as pkg version patchlevel
TIMESTAMP="$(date +%s)"
PR_OR_BRANCH="pr${TRAVIS_PULL_REQUEST}"
COMMIT_URL="${REPO_URL}/pull/${TRAVIS_PULL_REQUEST}"
else
# Use merge commit timestamp as pkg version patchlevel
TIMESTAMP="$COMMIT_TIMESTAMP"
PR_OR_BRANCH="${TRAVIS_BRANCH:-${BRANCH_NAME:-unk.branch}}"
COMMIT_URL="${REPO_URL}/commit/${SHA1SHORT}"
fi
# sanitize upstream identifier
UPSTREAM_ID=${PKGSOURCE//[-_]/}.${PR_OR_BRANCH//[-_]/}
# Final version
VERSION="${MAJOR_MINOR_VERSION}.${TIMESTAMP}.git${SHA1SHORT}"
# Final release
#RELEASE="1${UPSTREAM_ID}~1${DISTRO}"
RELEASE="1~${DISTRO}"
###########################################################
# Debug output
echo "COMMIT_TIMESTAMP=$COMMIT_TIMESTAMP"
echo "SHA1SHORT=$SHA1SHORT"
echo "COMMITTER_NAME=$COMMITTER_NAME"
echo "COMMITTER_EMAIL=$COMMITTER_EMAIL"
echo "BRANCH_NAME=$BRANCH_NAME"
echo "MAJOR_MINOR_VERSION=$MAJOR_MINOR_VERSION"
echo "TRAVIS_REPO=$TRAVIS_REPO"
echo "PKGSOURCE=$PKGSOURCE"
echo "DEBIAN_SUITE=$DEBIAN_SUITE"
echo "REPO_URL=$REPO_URL"
echo "TIMESTAMP=$TIMESTAMP"
echo "PR_OR_BRANCH=$PR_OR_BRANCH"
echo "COMMIT_URL=$COMMIT_URL"
echo "UPSTREAM_ID=$UPSTREAM_ID"
echo "VERSION=$VERSION"
echo "RELEASE=$RELEASE"
###########################################################
# Generate debian/changelog entry
#
# https://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog
#
cd ${SOURCE_DIR}
rm -f debian/changelog
cat > debian/changelog <<EOF
machinekit-cnc (${VERSION}-${RELEASE}) ${DEBIAN_SUITE}; urgency=low
* Travis CI rebuild
- TAG ${TAG}
- PR/branch ${PR_OR_BRANCH}
- Commit ${SHA1SHORT}
- ${COMMIT_URL}
-- ${COMMITTER_NAME} <${COMMITTER_EMAIL}> $(date -R)
EOF
echo "New changelog entry:"
cat debian/changelog # debug output
cat debian/changelog.in >> debian/changelog
if $BUILD_SOURCE; then
set -x # Let user see what's going on
# create .orig tarball
git archive HEAD | \
bzip2 -z | dd of=../machinekit-cnc_${VERSION}.orig.tar.bz2
# build source package
dpkg-source -b .
fi