-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate_version.sh
executable file
·41 lines (32 loc) · 1.3 KB
/
update_version.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
#!/bin/bash
current_date=$(date %Y%m%d)
# Check if the script is being run in a GitHub workflow
if [ "$GITHUB_ACTIONS" = true ]; then
# Get the latest tag
latest_tag=$(git describe --tags --abbrev=0)
# Extract the version number from the latest tag
version_number=${latest_tag}
else
# Set the first release date
first_release_date="20241001"
# Get the current date
current_date=$(date %Y%m%d)
# Calculate the version number
version_number=$((current_date - first_release_date))
if [ $version_number -lt 1 ]; then
version_number=1
fi
fi
# Convert the version number to hexadecimal
hex_version=$(printf "X" $version_number)
# Print the new version number, HEX version, date
echo "New version number: $version_number"
echo "HEX: 0x$hex_version"
echo "build date: $current_date"
# Set the output date variable
echo "version=$version_number" >> $GITHUB_ENV
# Set the output date variable
echo "build_date=$current_date" >> $GITHUB_ENV
# Update the device version in const.h using awk
awk -v hex_version="$hex_version" '/OTA_FW_VERSION/ {sub(/0x[0-9A-F]*/, "0x" hex_version)} 1' main/const.h > temp && mv temp main/const.h
awk -v fw_date="$current_date" '/FW_BUILD_DATE/ {sub(/"[^"]*"/, "\"" fw_date "\"")} 1' main/const.h > temp && mv temp main/const.h