MonScoDocEssai/tools/get_scodoc_version.sh

64 lines
1.6 KiB
Bash
Raw Normal View History

2020-12-21 18:15:01 +01:00
#!/bin/bash
# Get version information
2021-07-25 11:19:01 +02:00
# Use VERSION.py, VERSION, last commit, diff, and last upstream commit date
2020-12-21 18:15:01 +01:00
2021-07-25 11:19:01 +02:00
# Le répertoire de ce script:
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
2020-12-21 18:15:01 +01:00
2021-07-25 11:19:01 +02:00
source "$SCRIPT_DIR/config.sh"
source "$SCRIPT_DIR/utils.sh"
2020-12-21 18:15:01 +01:00
# Source code version:
2021-07-25 11:19:01 +02:00
x=$(grep SCOVERSION "$SCODOC_DIR/app/scodoc/VERSION.py") || terminate "can't access VERSION.py" 1
2020-12-21 18:15:01 +01:00
x=${x#*\"}
src_version=${x%\"*}
2021-07-25 11:19:01 +02:00
release_version=$(cat "$SCODOC_DIR/VERSION")
2020-12-21 18:15:01 +01:00
2021-07-25 11:19:01 +02:00
git status >& /dev/null
if [ $? = 0 ]
2020-12-21 18:15:01 +01:00
then
2021-07-25 11:19:01 +02:00
# development install: use git
# last commit
git_last_commit_hash=$(git log -1 --format=%h)
git_last_commit_date=$(git log -1 --format=%ci)
git_up_commit_hash=$(git log -1 --format=%h origin/ScoDoc8)
git_up_commit_date=$(git log -1 --format=%ci origin/ScoDoc8)
# Check if git has local changes
nchanges=$(git status --porcelain | grep -c -v '^??')
if [ "$nchanges" -gt 0 ]
then
has_local_changes="yes"
else
has_local_changes="no"
fi
git_info=" ($git_up_commit_hash) $git_up_commit_date"
if [ "$has_local_changes" = "yes" ]
then
git_info="$git_info (modified)"
fi
2020-12-21 18:15:01 +01:00
else
2021-07-25 11:19:01 +02:00
git_info=""
2020-12-21 18:15:01 +01:00
fi
# Synthetic one-line version:
2021-07-25 11:19:01 +02:00
sco_version="$release_version ($src_version)$git_info"
2020-12-21 18:15:01 +01:00
#
if [ "$1" = "-s" ]
then
echo "$sco_version"
else
echo src_version: "$src_version"
echo git_last_commit_hash: "$git_last_commit_hash"
echo git_last_commit_date: "$git_last_commit_date"
echo git_up_commit_hash: "$git_up_commit_hash"
echo git_up_commit_date: "$git_up_commit_date"
echo has_local_diffs: "$has_local_changes"
echo sco_version: "$sco_version"
fi