generated from LizardByte/template-base
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopr-ci.sh
74 lines (62 loc) · 1.98 KB
/
copr-ci.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
#! /bin/sh -x
set -e
resultdir="${COPR_RESULTDIR}"
git clone "https://github.com/${COPR_OWNER}/${COPR_PACKAGE}.git" --depth 1
cd "${COPR_PACKAGE}"
# get info from the webhook payload
if test -z "$REVISION"; then
# the hook_payload file contains webhook JSON payload (copr creates it for us);
# it is created only if the build is triggered by Custom webhook.
if test -f "$resultdir"/hook_payload; then
git clone https://github.com/praiskup/copr-ci-tooling \
"$resultdir/cct" --depth 1
export PATH="$resultdir/cct:$PATH"
echo "---"
cat "$resultdir"/hook_payload
echo "---"
# use jq to get the pr_id from the hook_payload
PR=$(jq -r '.pr_id // empty' "$resultdir"/hook_payload)
if [ -z "$PR" ]; then
BRANCH="master"
else
BRANCH="pr/${PR}"
fi
copr-travis-checkout "$resultdir"/hook_payload
fi
else
git checkout "$REVISION"
fi
# initialize the submodules
git submodule update --init --recursive
# get the tag of this commit IF it has one
TAG=$(git tag --points-at HEAD | head -n1)
if [ -z "$TAG" ]; then
TAG="0.0.$PR"
fi
TAG=$(echo "$TAG" | sed 's/^v//') # remove v prefix from the tag
echo "TAG=$TAG"
# get the commit
COMMIT=$(git rev-parse HEAD)
echo "COMMIT=$COMMIT"
# move spec file to the correct location
directories=(
"."
"./packaging/linux/fedora"
)
for dir in "${directories[@]}"; do
if [ -f "${dir}/${COPR_PACKAGE}.spec" ]; then
mv "${dir}/${COPR_PACKAGE}.spec" "${resultdir}"
break
fi
done
# fail if the spec file is not in the resultdir
if [ ! -f "${resultdir}/${COPR_PACKAGE}.spec" ]; then
echo "ERROR: ${COPR_PACKAGE}.spec not found"
exit 1
fi
# use sed to replace these values in the spec file
sed -i "s|%global build_version 0|%global build_version ${TAG}|" "${resultdir}"/*.spec
sed -i "s|%global branch 0|%global branch ${BRANCH}|" "${resultdir}"/*.spec
sed -i "s|%global commit 0|%global commit ${COMMIT}|" "${resultdir}"/*.spec
# create a tarball of the source code
tar -czf "${resultdir}/tarball.tar.gz" .