mirror of
https://github.com/YunoHost/vinaigrette.git
synced 2024-09-03 20:06:11 +02:00
Refactor/clean a bit ynh-build
This commit is contained in:
parent
dc64d109f1
commit
d1f799991d
1 changed files with 117 additions and 67 deletions
158
ynh-build
158
ynh-build
|
@ -1,102 +1,152 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
readonly THISSCRIPT=$0
|
||||||
|
readonly PROJECT=$1
|
||||||
|
readonly BRANCH=$2
|
||||||
|
readonly DISTRIB=$3
|
||||||
|
readonly VERSION=$4
|
||||||
|
readonly TAG="debian/$VERSION"
|
||||||
|
|
||||||
source /home/vinaigrette/config/config
|
source /home/vinaigrette/config/config
|
||||||
|
|
||||||
# ##### #
|
# ##### #
|
||||||
# Usage #
|
# Usage #
|
||||||
# ##### #
|
# ##### #
|
||||||
|
|
||||||
usage() {
|
function usage()
|
||||||
|
{
|
||||||
cat << EOF
|
cat << EOF
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
`basename $0` <project> <branch> <version>
|
$THISSCRIPT <project> <branch> <version>
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
<project> moulinette, yunohost, yunohost-admin or SSOwat
|
<project> moulinette, yunohost, yunohost-admin or SSOwat
|
||||||
<branch> testing or stable
|
<branch> testing or stable
|
||||||
<distrib> jessie or stretch
|
<distrib> jessie or stretch
|
||||||
<version> x.y.z (ex: 2.6.1)
|
<version> x.y.z (ex: 2.6.1)
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $1 == "-h" ]]; then
|
|
||||||
usage
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ################# #
|
# ################# #
|
||||||
# Check user inputs #
|
# Check user inputs #
|
||||||
# ################# #
|
# ################# #
|
||||||
|
|
||||||
PROJECT=$1
|
function validate_arguments()
|
||||||
BRANCH=$2
|
{
|
||||||
DISTRIB=$3
|
|
||||||
VERSION=$4
|
|
||||||
|
|
||||||
## Project
|
## Project
|
||||||
if [[ ! $PROJECT =~ ^yunohost|yunohost-admin|moulinette|SSOwat$ ]]; then
|
if [[ ! $PROJECT =~ ^yunohost|yunohost-admin|moulinette|SSOwat$ ]]; then
|
||||||
echo "Invalid project $PROJECT"
|
echo "Invalid project $PROJECT"
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Branch
|
## Branch
|
||||||
if [[ ! $BRANCH =~ ^testing|stable$ ]]; then
|
if [[ ! $BRANCH =~ ^testing|stable|unstable$ ]]; then
|
||||||
echo "Invalid branch $BRANCH"
|
echo "Invalid branch $BRANCH"
|
||||||
usage
|
usage
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Distribution
|
# Distribution
|
||||||
if [[ ! $DISTRIB =~ ^jessie|stretch$ ]]; then
|
if [[ ! $DISTRIB =~ ^jessie|stretch$ ]]; then
|
||||||
echo "Invalid distribution $DISTRIB"
|
echo "Invalid distribution $DISTRIB"
|
||||||
usage
|
usage
|
||||||
exit 3
|
exit 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Version
|
# Version
|
||||||
if [ -z "$VERSION" ]; then
|
if [ -z "$VERSION" ]; then
|
||||||
echo "Invalid version $VERSION"
|
echo "Invalid version $VERSION"
|
||||||
usage
|
usage
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Sum up configuration
|
function checkout_tag()
|
||||||
echo "## #################################################### ##"
|
{
|
||||||
echo "## Building $PROJECT $BRANCH release - $VERSION version"
|
# Update project's repository
|
||||||
echo "## #################################################### ##"
|
echo ""
|
||||||
|
echo "> Updating $GIT_REPOS/$PROJECT repository ... "
|
||||||
|
echo ""
|
||||||
|
|
||||||
# Update project's repository
|
cd $GIT_REPOS/$PROJECT
|
||||||
echo ""
|
git fetch --quiet
|
||||||
echo "## Updating $GIT_REPOS/$PROJECT repository ..."
|
git fetch --tags --quiet
|
||||||
cd $GIT_REPOS/$PROJECT
|
git checkout $DISTRIB-$BRANCH --quiet
|
||||||
git fetch --quiet
|
#git checkout $BRANCH --quiet
|
||||||
git fetch --tags --quiet
|
#git pull origin $BRANCH --quiet
|
||||||
git checkout $BRANCH --quiet
|
|
||||||
git pull origin $BRANCH --quiet
|
|
||||||
|
|
||||||
# Check if tag really exists
|
LASTVERSIONCHANGELOG=$(dpkg-parsechangelog -S Version 2>/dev/null)
|
||||||
if git rev-parse "debian/$VERSION" >/dev/null 2>&1; then
|
|
||||||
TAG="debian/$VERSION"
|
if [[ "$VERSION" != "$LASTVERSIONCHANGELOG" ]]
|
||||||
else
|
then
|
||||||
echo "Invalid version $VERSION (there's no debian/$VERSION tag in the git repo !)"
|
echo "Version $VERSION is not the last version in changelog"
|
||||||
usage
|
|
||||||
exit
|
exit
|
||||||
fi
|
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
|
||||||
|
|
||||||
|
|
||||||
# Create temporary folder
|
}
|
||||||
TMP_FOLDER=$(mktemp -d)
|
|
||||||
|
|
||||||
# Extract git archive a desired tag
|
function build()
|
||||||
echo ""
|
{
|
||||||
echo "## Exporting in $TMP_FOLDER ..."
|
# Create temporary folder
|
||||||
git archive $TAG --format=tar | tar -x -C $TMP_FOLDER
|
TMP_FOLDER=$(mktemp -d)
|
||||||
|
|
||||||
# Build Debian package
|
# Extract git archive a desired tag
|
||||||
echo ""
|
echo ""
|
||||||
echo "## Building Debian package ..."
|
echo "> Exporting in $TMP_FOLDER ... "
|
||||||
echo ""
|
echo ""
|
||||||
cd $TMP_FOLDER
|
git archive $TAG --format=tar | tar -x -C $TMP_FOLDER
|
||||||
$BUILD_DEB -d $BRANCH -c $DISTRIB .
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Sum up configuration
|
||||||
|
echo "########################################################"
|
||||||
|
echo "# Building $PROJECT $BRANCH release - $VERSION version "
|
||||||
|
echo "########################################################"
|
||||||
|
|
||||||
|
checkout_tag
|
||||||
|
build
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
main
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue