-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathupdate-swinfo.sh
executable file
·115 lines (94 loc) · 3 KB
/
update-swinfo.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
SWINFO_FILE=source/dentist/swinfo.d
function main()
{
echo -n 'Updating `dentist.swinfo` ... '
get_updated_swinfo "$SWINFO_FILE" > "$SWINFO_FILE~"
if ! cmp -s "$SWINFO_FILE" "$SWINFO_FILE~";
then
mv "$SWINFO_FILE~" "$SWINFO_FILE"
echo 'done'
else
echo 'skipped'
fi
}
function is_git_clean()
{
git status --porcelain | \
awk '
BEGIN {
ignore["source/dentist/swinfo.d"] = 1;
ignore["source/dentist/swinfo.d~"] = 1;
ignore["update-swinfo.sh"] = 1;
list_dirty_files = ("LIST_DIRTY_FILES" in ENVIRON && ENVIRON["LIST_DIRTY_FILES"] != 0);
}
(FILENAME == ".dockerignore" && substr($0, 1, 1) == "!") {
current = substr($0, 2);
gsub(/\*/, "[^/]*", current);
gsub(/\?/, "[^/]?", current);
gsub(/\./, "\\.", current);
current = "^" current "(/|$)";
if (include_re)
include_re = include_re "|" current;
else
include_re = current;
}
(FILENAME == "-") {
if ($2 in ignore || !($2 ~ include_re)) {
# ignore
} else {
# there is a change to a file that is not ignored
if (list_dirty_files)
dirty_files[++n] = $0;
else
exit ++n;
}
}
END {
if (list_dirty_files) {
print "include_re" "=" include_re > "/dev/stderr";
for (i = 1; i <= n; ++i)
print dirty_files[i] > "/dev/stderr";
}
exit n
}
' .dockerignore -
}
function get_updated_swinfo()
{
INFO_JSON="$(dub describe | jq -c '.packages[0]')"
EXECUTABLE_NAME="$(jq '.targetName' <<<"$INFO_JSON")"
GIT_VERSION="$(git describe)"
GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
GIT_COMMIT="$(git rev-parse HEAD)"
DESCRIPTION="$(jq '.description' <<<"$INFO_JSON")"
COPYRIGHT="$(jq '.copyright' <<<"$INFO_JSON")"
if [[ -z "${GIT_BRANCH##release/*}" ]]
then
GIT_VERSION="$(git config --get gitflow.prefix.versiontag)${GIT_BRANCH#release/}"
fi
if ! is_git_clean
then
GIT_VERSION="$GIT_VERSION-dirty"
GIT_COMMIT="$GIT_COMMIT+dirty"
fi
sed -E \
-e 's/(executableName\s*=\s*)[^;]+;/\1'"$EXECUTABLE_NAME"';/' \
-e 's/(gitVersion\s*=\s*)[^;]+;/\1"'"$GIT_VERSION"'";/' \
-e 's/(gitCommit\s*=\s*)[^;]+;/\1"'"$GIT_COMMIT"'";/' \
-e 's/(description\s*=\s*)[^;]+;/\1'"$DESCRIPTION"'.wrap;/' \
-e 's/(copyright\s*=\s*)[^;]+;/\1'"$COPYRIGHT"'.wrap;/' \
"$1"
}
function clean_up()
{
rm -f "$SWINFO_FILE~"
}
function on_error()
{
echo failed
}
trap clean_up EXIT
trap on_error ERR
set -e # exit when any command fails
main