forked from ZanSara/write-version-to-file
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·45 lines (33 loc) · 834 Bytes
/
entrypoint.sh
File metadata and controls
executable file
·45 lines (33 loc) · 834 Bytes
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
#!/bin/sh
set -eo pipefail
error() {
echo -e "\x1b[1;31m$1\e[0m $2"
}
log() {
echo -e "\x1b[1;32m$1\e[0m $2"
}
filename=$1
log "File Name:" "$filename"
if [ -z "$2" ]; then
placeholder="\${VERSION}"
else
placeholder=$2
fi
log "Placeholder:" "$placeholder"
if test -f "$filename"; then
content=$(cat "$filename")
else
error "Version file not found! Looked for:" "$filename"
exit 1;
fi
log "File Content:" "\n$content"
if [ -z "$3" ]; then
git fetch --tags --force
latestVersionTag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
else
latestVersionTag=$3
fi
log "Replacing placeholder with:" "$latestVersionTag"
updatedContent=$(< "$filename" sed "s/$placeholder/$latestVersionTag/g")
echo "$updatedContent" > "$filename"
log "Updated File Content:" "\n$updatedContent"