-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_version.sh
More file actions
48 lines (40 loc) · 1.34 KB
/
generate_version.sh
File metadata and controls
48 lines (40 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /bin/sh
# Extract latest version and release date from ChangeLog.md and write to output file.
cl=$1
if [ -z "$cl" ]; then
echo Error: Need the Change Log file as parameter one >&2
exit 1
fi
vf=$2
if [ -z "$vf" ]; then
echo Error: Need the output file name as parameter two >&2
exit 1
fi
# Looking for '### major.minor.patch -- date'
# $1 $2 $3 $4
recent=`egrep -m 1 -e '^### [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+ --' $cl`
if [ $? -ne 0 -o -z "$recent" ]; then
echo "Error: Change Log $cl does not contain a semantic version line of '### major.minor.patch'" >&2
exit 1
fi
set -- $recent
version=$2
date=$4
# Deduce project URL from go.mod
project=`grep ^module go.mod| head -1 | cut -f2 -d' '`
if [ $? -ne 0 -o -z "$project" ]; then
echo Error: No module name found on go.mod >&2
exit 1
fi
# Generate verion file in the approve gofmt format
(
printf '// Code generated by "generate_version.sh"; DO NOT EDIT.\n'
printf '// Generated on: %s\n\n' `date +%F`
printf 'package main\n\nconst (\n'
printf '\tName = "fad"\n'
printf '\tProject = "go install %s"\n' "${project}@latest"
printf '\tReleaseDate = "%s"\n' "${date}"
printf '\tVersion = "%s"\n' "${version}"
printf ')\n\n'
printf '// Code generated by "generate_version.sh"; DO NOT EDIT.\n'
) >${vf}