Skip to content

Commit db8aa50

Browse files
committed
build-release: write version string like Urcheon
Keep the possibility to append username (something Urcheon does not) but make it optional and not enabled by default.
1 parent 9b927b7 commit db8aa50

File tree

1 file changed

+56
-13
lines changed

1 file changed

+56
-13
lines changed

build-release

+56-13
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ printHelp () {
7474
${tab}${tab}build multiple targets at once in parallel
7575
${tab}${tab}beware: return code will be inaccurate
7676
77+
${tab}-u
78+
${tab}${tab}write username in version string (requires -v)
79+
7780
${tab}-v
7881
${tab}${tab}write package version strings
7982
@@ -242,11 +245,52 @@ package () {
242245
)
243246
}
244247

248+
printVersion () {
249+
local tag_string='0'
250+
local date_string=''
251+
local ref_string=''
252+
local dirt_string=''
253+
254+
local git_last_commit_short="$(git rev-parse --short HEAD)"
255+
256+
if [ -n "${git_last_commit_short}" ]
257+
then
258+
local git_describe_string="$(git describe --tags --match 'v[0-9].*' 2>/dev/null | cut -c2-)"
259+
local git_closest_tag="$(git describe --tags --abbrev=0 --match 'v[0-9].*' 2>/dev/null | cut -c2-)"
260+
local git_last_commit_date="$(date --date="@$(git log -1 '--pretty=format:%ct')" --utc '+%Y%m%d-%H%M%S')"
261+
262+
if [ -n "${git_closest_tag}" ]
263+
then
264+
tag_string="${git_closest_tag}"
265+
266+
if [ "${git_closest_tag}" != "${git_describe_string}" ]
267+
then
268+
date_string="-${git_last_commit_date}"
269+
ref_string="-${git_last_commit_short}"
270+
fi
271+
else
272+
date_string="-${git_last_commit_date}"
273+
ref_string="-${git_last_commit_short}"
274+
fi
275+
else
276+
date_string="-$(date --utc '+%Y%m%d-%H%M%S')"
277+
ref_string='-0'
278+
fi
279+
280+
if ! git diff --quiet 2>/dev/null
281+
then
282+
dirt_string='-dirty'
283+
fi
284+
285+
echo "${tag_string}${date_string}${ref_string}${dirt_string}"
286+
}
287+
245288
build () {
246289
local job_count="${1}"
247290
local write_version_string="${2}"
248-
local root_dir="${3}"
249-
local target="${4}"
291+
local write_username_string="${3}"
292+
local root_dir="${4}"
293+
local target="${5}"
250294

251295
local symbol_archive_basename='symbols'
252296
local vmpak_archive_basename=''
@@ -342,17 +386,11 @@ build () {
342386

343387
if "${write_version_string}"
344388
then
345-
git_last_commit="$(git rev-list HEAD | head -n 1)"
346-
git_last_commit_short="$(git rev-list HEAD | head -n 1 | cut -c1-7)"
347-
git_ref="$(git describe --tags --match 'v*' | cut -c2-)"
348-
git_last_tag="$(git describe --tags --match 'v*' | cut -f1 -d'-' | cut -c2-)"
349-
git_last_date="$(date --date="@$(git log -1 '--pretty=format:%ct')" -u '+%Y%m%d-%H%M%S')"
389+
build_version="$(printVersion)"
350390

351-
if [ "${git_ref}" = "${git_last_tag}" ]
391+
if "${write_username_string}"
352392
then
353-
build_version="${git_ref}"
354-
else
355-
build_version="${git_last_tag}+${git_last_date}+${git_last_commit_short}+$(getUserName)"
393+
build_version+="-$(whoami | tr '[:upper:]' '[:lower:]')"
356394
fi
357395

358396
vmpak_version_string="_${build_version}"
@@ -741,6 +779,7 @@ root_dir="$(git rev-parse --show-toplevel)"
741779
job_count=''
742780
parallel_target='false'
743781
write_version_string='false'
782+
write_username_string='false'
744783
target_list=''
745784

746785
while [ -n "${1:-}" ]
@@ -765,6 +804,10 @@ do
765804
parallel_target='true'
766805
shift
767806
;;
807+
'-u')
808+
write_username_string='true'
809+
shift
810+
;;
768811
'-v')
769812
write_version_string='true'
770813
shift
@@ -785,9 +828,9 @@ for target in ${target_list}
785828
do
786829
if "${parallel_target}"
787830
then
788-
build "${job_count}" "${write_version_string}" "${root_dir}" "${target}" &
831+
build "${job_count}" "${write_version_string}" "${write_username_string}" "${root_dir}" "${target}" &
789832
else
790-
build "${job_count}" "${write_version_string}" "${root_dir}" "${target}"
833+
build "${job_count}" "${write_version_string}" "${write_username_string}" "${root_dir}" "${target}"
791834
fi
792835
done
793836
wait

0 commit comments

Comments
 (0)