-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate_version.sh
More file actions
27 lines (20 loc) · 890 Bytes
/
update_version.sh
File metadata and controls
27 lines (20 loc) · 890 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
#!/bin/bash
set -e
VERSION_FILE="resources/version.conf"
BUILD_INFO_FILE="resources/build_info.conf"
GIT_BUILD_MSG="Built from Git source at $(date)"
NON_GIT_BUILD_MSG="(*built from non-Git environment $(date), version may not be correct)"
if command -v git &> /dev/null && git rev-parse --is-inside-work-tree &> /dev/null; then
echo "Git environment detected. Overwriting version files."
# Full version with Git metadata
FULL_VERSION=$(git describe --tags | sed -E 's/-g([0-9a-f]{3,}).*/-g\1/')
# Clean semantic version
CLEAN_VERSION=$(echo "$FULL_VERSION" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
# Write both
echo "$CLEAN_VERSION" > "$VERSION_FILE"
echo "$GIT_BUILD_MSG ($FULL_VERSION)" > "$BUILD_INFO_FILE"
else
echo "Non-Git environment detected. Overwriting with fallback versions."
echo "$NON_GIT_BUILD_MSG" > "$BUILD_INFO_FILE"
fi
exit 0