From 08fda0099349b46164addfd148b8b6b23d4032d7 Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 13 Jul 2015 09:02:17 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20script=20de=20completion=20du=20manifes?= =?UTF-8?q?te=20via=20metadonn=C3=A9es=20Git?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- get-updated-manifest-from-git.sh | 78 ++++++++++++++++++++++++++++++++ lib/build.sh | 32 +++++++++++-- lib/util.sh | 4 +- 3 files changed, 108 insertions(+), 6 deletions(-) create mode 100755 get-updated-manifest-from-git.sh diff --git a/get-updated-manifest-from-git.sh b/get-updated-manifest-from-git.sh new file mode 100755 index 0000000..310bed3 --- /dev/null +++ b/get-updated-manifest-from-git.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +function show_usage { + echo + echo "Usage: $0 " + echo + echo "Paramètres: " + echo + echo " - Chemin vers le répertoire des sources du projet. Le projet doit être un dépôt Git valide." + echo +} + +function main { + + cd $SRC_DIR + + git status 2>&1 1>/dev/null + + if [ $? != 0 ]; then + fatal "The directory $SRC_DIR seems not to be a valid Git repository." + fi + + MANIFEST=$(cat tamarin.json 2>/dev/null) + + if [ -z "$MANIFEST" ]; then + MANIFEST="{}" + fi + + # Extract project info from Git + repo_name=$(basename `git rev-parse --show-toplevel`) + current_commit=$(git log -n 1 --pretty=format:"%h") + logs=$(git log --pretty=format:"%an - %h : %s" | sed 's/"/\\"/g') + git_maintainer=$(git shortlog -s -n -e 2>&1 | sed 's/^\s*[0-9]*\s*//g' | head -n 1) + + # Get current version from manifest + current_name=$(echo "$MANIFEST" | jq -r ".name" | sed 's/null//') + current_version=$(echo "$MANIFEST" | jq -r ".version" | sed 's/null//') + current_changelog=$(echo "$MANIFEST" | jq -r ".changelog" | sed 's/null//') + current_maintainer=$(echo "$MANIFEST" | jq -r ".maintainer" | sed 's/null//') + + # Complete manifest + + # Add commit number to version + MANIFEST=$(echo "$MANIFEST" | jq -r ".version = \"${current_version:-0.0.0}~$current_commit\"") + # Set name if not defined + MANIFEST=$(echo "$MANIFEST" | jq -r ".name = \"${current_name:-$repo_name}\"") + # Set maintainer if not defined + MANIFEST=$(echo "$MANIFEST" | jq -r ".maintainer = \"${current_maintainer:-$git_maintainer}\"") + + # Set changelog from git log if not defined + if [ -z "$current_changelog" ]; then + + MANIFEST=$(echo "$MANIFEST" | jq -r ".changelog = []") + + while read -r entry; do + MANIFEST=$(echo "$MANIFEST" | jq -r ".changelog += [\"$entry\"]") + done <<< "$logs" + + fi + + echo "$MANIFEST" + +} + + +# Load util lib +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source "$DIR/lib/util.sh" + +# Test for arguments +if [ -z "$1" ]; then + show_usage + exit 1 +fi + +SRC_DIR=$(readlink -f "$1") + +main diff --git a/lib/build.sh b/lib/build.sh index 8c08aba..9899bd6 100755 --- a/lib/build.sh +++ b/lib/build.sh @@ -62,7 +62,7 @@ function create_debian_control_file { echo "Version: ${package_version:-0.0.0}" >> "${control_file}" package_section=$(get_project_opt .section) - echo "Section: ${package_section:-extra}" >> "${control_file}" + echo "Section: ${package_section:-unknown}" >> "${control_file}" package_priority=$(get_project_opt .priority) echo "Priority: ${package_priority:-optional}" >> "${control_file}" @@ -72,7 +72,7 @@ function create_debian_control_file { dependencies=$( get_project_opt ".dependencies | .[\"${DISTRIB}\"] | @sh" | sed "s/' '/, /g" | sed "s/'//g" ) - debug "Package dependencies: $dependencies" + debug "Package dependencies: ${dependencies:-None}" echo "Depends: ${dependencies}" >> "${control_file}" @@ -114,6 +114,29 @@ function create_debian_hooks { } +function create_debian_changelog { + + debian_dir="${1}" + changelog="${debian_dir}/changelog" + + logs="$(get_project_opt '.changelog | map(.+"\n") | add')" + package_name=$(get_project_opt .name) + package_version=$(get_project_opt .version) + maintainer=$(get_project_opt .maintainer) + + echo "${package_name} (${package_version:-0.0.0}), ${DISTRIB}; urgency=low" > "${changelog}" + echo >> "${changelog}" + + while read -r entry; do + echo " * ${entry}" >> "${changelog}" + done <<< "$(echo -e "${logs}" | sed 's/^"//')" + + echo >> "${changelog}" + + echo "-- ${maintainer} $(date -R)" >> "${changelog}" + +} + function create_debian_metadata { build_dir="${1}" @@ -124,6 +147,7 @@ function create_debian_metadata { create_debian_control_file "${debian_dir}" create_debian_hooks "${debian_dir}" + create_debian_changelog "${debian_dir}" } @@ -170,8 +194,8 @@ function main { manifest_path=${SRC_DIR}/tamarin.json - if [ ! -f "${manifest_path}" ]; then - fatal "There is no 'tamarin.json' file found in the project directory !" + if [ ! -f "${manifest_path}" ] && [ ! -d "${SRC_DIR}/debian" ] && [ ! -d "${SRC_DIR}/DEBIAN" ]; then + fatal "There is no 'tamarin.json' nor debian packaging files in the project directory !" fi build_project diff --git a/lib/util.sh b/lib/util.sh index 6948492..8310de4 100644 --- a/lib/util.sh +++ b/lib/util.sh @@ -9,10 +9,10 @@ function debug { } function error { - echo "[${HOSTNAME}] [ERROR] $@" + echo "[${HOSTNAME}] [ERROR] $@" >&2 } function fatal { - echo "[${HOSTNAME}] [FATAL] $@" + echo "[${HOSTNAME}] [FATAL] $@" >&2 exit 1 }