vinaigrette/ynh-build

160 lines
3.2 KiB
Text
Raw Normal View History

2017-08-29 17:17:25 +02:00
#!/bin/bash
2017-09-09 17:26:11 +02:00
readonly THISSCRIPT=$0
readonly PROJECT=$1
readonly BRANCH=$2
readonly DISTRIB=$3
readonly VERSION=$4
readonly TAG="debian/$VERSION"
2017-08-30 05:51:28 +02:00
source /home/vinaigrette/config/config
2017-08-29 17:17:25 +02:00
# ##### #
# Usage #
# ##### #
2017-09-09 17:26:11 +02:00
function usage()
{
cat << EOF
2017-09-09 17:26:11 +02:00
2017-08-29 17:17:25 +02:00
Usage:
2017-09-09 17:26:11 +02:00
$THISSCRIPT <project> <branch> <version>
2017-08-29 17:17:25 +02:00
Arguments:
<project> moulinette, yunohost, yunohost-admin or SSOwat
<branch> testing or stable
<distrib> stretch (can only build for stretch, no jessie)
2017-08-29 17:17:25 +02:00
<version> x.y.z (ex: 2.6.1)
2017-09-09 17:26:11 +02:00
EOF
2017-08-29 17:17:25 +02:00
}
# ################# #
# Check user inputs #
# ################# #
2017-09-09 17:26:11 +02:00
function validate_arguments()
{
## Project
if [[ ! $PROJECT =~ ^yunohost|yunohost-admin|moulinette|SSOwat$ ]]; then
echo "Invalid project $PROJECT"
usage
exit 1
fi
## Branch
if [[ ! $BRANCH =~ ^testing|stable|unstable$ ]]; then
echo "Invalid branch $BRANCH"
usage
exit 2
fi
# Distribution
if [[ ! $DISTRIB =~ ^stretch$ ]]; then
2017-09-09 17:26:11 +02:00
echo "Invalid distribution $DISTRIB"
usage
exit 3
fi
# Version
if [ -z "$VERSION" ]; then
echo "Invalid version $VERSION"
usage
exit 4
fi
}
function checkout_tag()
{
# Update project's repository
echo ""
echo "> Updating $GIT_REPOS/$PROJECT repository ... "
echo ""
cd $GIT_REPOS/$PROJECT
git fetch --quiet
git fetch --tags --quiet
git checkout $DISTRIB-$BRANCH --quiet
#git checkout $BRANCH --quiet
#git pull origin $BRANCH --quiet
LASTVERSIONCHANGELOG=$(dpkg-parsechangelog -S Version 2>/dev/null)
if [[ "$VERSION" != "$LASTVERSIONCHANGELOG" ]]
then
echo "Version $VERSION is not the last version in changelog"
exit
fi
# Check if tag really exists
if ! git rev-parse "$TAG" >/dev/null 2>&1;
then
echo "Invalid version $VERSION (there's no tag $TAG in the git repo !)"
exit
fi
# Get commit for the tag and for HEAD
TAGCOMMIT=$(git rev-parse "$TAG")
HEADCOMMIT=$(git rev-parse "HEAD")
if [[ "$TAGCOMMIT" != "$HEADCOMMIT" ]]
then
echo "Tag $TAG is not the HEAD of the branch :/"
exit
fi
}
function build()
{
# Create temporary folder
TMP_FOLDER=$(mktemp -d)
# Extract git archive a desired tag
echo ""
echo "> Exporting in $TMP_FOLDER ... "
echo ""
git archive $TAG --format=tar | tar -x -C $TMP_FOLDER
# Build Debian package
echo "###############################"
echo "# Building Debian package ... #"
echo "###############################"
cd $TMP_FOLDER
$BUILD_DEB -d $BRANCH -c $DISTRIB .
}
function main()
{
# If used asked for help, show usage
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
usage
exit 0
fi
validate_arguments
2018-04-26 18:35:52 +02:00
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
2017-09-09 17:26:11 +02:00
# Sum up configuration
echo "########################################################"
echo "# Building $PROJECT $BRANCH release - $VERSION version "
echo "########################################################"
checkout_tag
build
}
main
2017-08-29 17:17:25 +02:00