vinaigrette/daily-build
2020-05-14 17:14:25 +00:00

140 lines
3.4 KiB
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
readonly THISSCRIPT=$0
readonly BRANCH_NIGHTLY="unstable"
readonly DISTRIBS="stretch buster"
readonly TIMETAG="$(date +%Y%m%d%H%M)"
readonly PACKAGES="moulinette SSOwat yunohost yunohost-admin"
if [ -z "$FORCE" ]
then
readonly FORCE="false"
fi
readonly LAST_BUILDS_CACHE="/var/cache/vinaigrette/last_builds/"
source /home/vinaigrette/config/config
function main()
{
mkdir -p $LAST_BUILDS_CACHE
#if [[ "$(tty)" == "not a tty" ]]
#then
# echo "You aint in a tty (are you in a 'lxc exec' ?)"
# echo "The script can't run because pbuilder won't be happy :|"
# exit
#fi
for PACKAGE in $PACKAGES;
do
for DISTRIB in $DISTRIBS;
do
echo "-------------------------------------"
echo "Looking for update in ${PACKAGE} for ${DISTRIB}... "
build_if_needed $PACKAGE $DISTRIB
done
done
echo "-------------------------------------"
}
function build_if_needed()
{
local PACKAGE=$1
local DISTRIB=$2
local LAST_BUILD_FOR_THIS_PACKAGE=$LAST_BUILDS_CACHE/${DISTRIB}_${BRANCH_NIGHTLY}_${PACKAGE}
cd $GIT_REPOS/$PACKAGE
git fetch origin >/dev/null 2>/dev/null
# Check if there's a branch named distrib-branch (e.g. stretch-unstable)
# By default, keep just 'branch'
BRANCH_NIGHTLY_GIT="$BRANCH_NIGHTLY"
if git branch -ar | grep -q origin/$DISTRIB-$BRANCH_NIGHTLY
then
BRANCH_NIGHTLY_GIT="$DISTRIB-$BRANCH_NIGHTLY"
fi
# If the branch name is an alias to another branch, "resolve" the alias
if grep -q "ref: " .git/refs/heads/$BRANCH_NIGHTLY_GIT 2>/dev/null
then
BRANCH_NIGHTLY_GIT=$(cat .git/refs/heads/$BRANCH_NIGHTLY_GIT | tr '/' ' ' | awk '{print $4}')
fi
git checkout $BRANCH_NIGHTLY_GIT >/dev/null 2>/dev/null
git pull origin $BRANCH_NIGHTLY_GIT >/dev/null 2>/dev/null
git reset --hard origin/$BRANCH_NIGHTLY_GIT
# Check if build is needed
if [ -e $LAST_BUILD_FOR_THIS_PACKAGE ]
then
TIMESTAMP_LASTBUILD=$(stat -c %Y $LAST_BUILD_FOR_THIS_PACKAGE)
else
TIMESTAMP_LASTBUILD=0
fi
TIMESTAMP_HEAD=$(git show -s --format=%ct HEAD)
if [ $TIMESTAMP_HEAD -lt $TIMESTAMP_LASTBUILD ]
then
if ! "$FORCE";
then
echo "Sources up-to-date, nothing to build."
return
else
echo "Sources up-to-date but forcing build anyway."
fi
fi
VERSION=$(dpkg-parsechangelog -S Version 2>/dev/null)
VERSION_NIGHTLY="${VERSION}+${TIMETAG}"
# Tweak the changelog temporarily
echo "> Setting version in changelog to ${VERSION_NIGHTLY}"
rm -f debian/changelog.dch
cp debian/changelog debian/changelog.old
dch --package "${PACKAGE}" \
--force-bad-version \
-v "${VERSION_NIGHTLY}" \
-D "${BRANCH_NIGHTLY}" \
--force-distribution \
"Daily build." \
> /dev/null 2>&1
head -n 5 debian/changelog
# Launch the build using build_deb script
build
touch $LAST_BUILD_FOR_THIS_PACKAGE
# Restore changelog
echo "> Restoring previous changelog"
cd $GIT_REPOS/$PACKAGE
cp debian/changelog.old debian/changelog
rm debian/changelog.old
}
function build()
{
# Create temporary folder
TMP_FOLDER=$(mktemp -d)
# Move files to a tmp folder
echo "> Exporting in $TMP_FOLDER ... "
git ls-files | xargs tar -czf archive.tar.gz
cat archive.tar.gz | tar -xz -C $TMP_FOLDER
rm archive.tar.gz
# Build Debian package
echo "> Starting build ..."
cd $TMP_FOLDER
$BUILD_DEB $DISTRIB $BRANCH_NIGHTLY .
}
main