Ajout script de completion du manifeste via metadonnées Git
This commit is contained in:
parent
95fc0a7002
commit
08fda00993
|
@ -0,0 +1,78 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
function show_usage {
|
||||||
|
echo
|
||||||
|
echo "Usage: $0 <src>"
|
||||||
|
echo
|
||||||
|
echo "Paramètres: "
|
||||||
|
echo
|
||||||
|
echo " - <src> 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
|
32
lib/build.sh
32
lib/build.sh
|
@ -62,7 +62,7 @@ function create_debian_control_file {
|
||||||
echo "Version: ${package_version:-0.0.0}" >> "${control_file}"
|
echo "Version: ${package_version:-0.0.0}" >> "${control_file}"
|
||||||
|
|
||||||
package_section=$(get_project_opt .section)
|
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)
|
package_priority=$(get_project_opt .priority)
|
||||||
echo "Priority: ${package_priority:-optional}" >> "${control_file}"
|
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" )
|
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}"
|
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 {
|
function create_debian_metadata {
|
||||||
|
|
||||||
build_dir="${1}"
|
build_dir="${1}"
|
||||||
|
@ -124,6 +147,7 @@ function create_debian_metadata {
|
||||||
|
|
||||||
create_debian_control_file "${debian_dir}"
|
create_debian_control_file "${debian_dir}"
|
||||||
create_debian_hooks "${debian_dir}"
|
create_debian_hooks "${debian_dir}"
|
||||||
|
create_debian_changelog "${debian_dir}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,8 +194,8 @@ function main {
|
||||||
|
|
||||||
manifest_path=${SRC_DIR}/tamarin.json
|
manifest_path=${SRC_DIR}/tamarin.json
|
||||||
|
|
||||||
if [ ! -f "${manifest_path}" ]; then
|
if [ ! -f "${manifest_path}" ] && [ ! -d "${SRC_DIR}/debian" ] && [ ! -d "${SRC_DIR}/DEBIAN" ]; then
|
||||||
fatal "There is no 'tamarin.json' file found in the project directory !"
|
fatal "There is no 'tamarin.json' nor debian packaging files in the project directory !"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
build_project
|
build_project
|
||||||
|
|
|
@ -9,10 +9,10 @@ function debug {
|
||||||
}
|
}
|
||||||
|
|
||||||
function error {
|
function error {
|
||||||
echo "[${HOSTNAME}] [ERROR] $@"
|
echo "[${HOSTNAME}] [ERROR] $@" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
function fatal {
|
function fatal {
|
||||||
echo "[${HOSTNAME}] [FATAL] $@"
|
echo "[${HOSTNAME}] [FATAL] $@" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue