summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorReFil <31960031+ReFil@users.noreply.github.com>2023-11-16 07:49:39 +0000
committerGitHub <noreply@github.com>2023-11-16 07:49:39 +0000
commitcdcec22e609688812bf0f5ac303cc9c6970efb23 (patch)
treefa4b666fbc83311089a8ebdb0a7aa0c2b405d2fe /bin
parent44a42af666dbeee899520b956200137222c8378c (diff)
Version compiled FW with automatic macro (#267)
* Version compiled FW with hash Auto generates a macro to type out version info, local and github compilation now includes commit hash and timestamp in final uf2 files * Fix local builds makefile doesn't like the script returning the macro, directed to null for local builds as version.dtsi file accessible
Diffstat (limited to 'bin')
-rwxr-xr-xbin/build.sh5
-rwxr-xr-xbin/get_version.sh57
2 files changed, 60 insertions, 2 deletions
diff --git a/bin/build.sh b/bin/build.sh
index ade4767..cd68988 100755
--- a/bin/build.sh
+++ b/bin/build.sh
@@ -3,7 +3,8 @@
set -eu
PWD=$(pwd)
-TIMESTAMP="${TIMESTAMP:-$(date -u +"%Y%m%d%H%M%S")}"
+TIMESTAMP="${TIMESTAMP:-$(date -u +"%Y%m%d%H%M")}"
+COMMIT="${COMMIT:-$(echo xxxxxx)}"
# West Build (left)
west build -s zmk/app -d build/left -b adv360_left -- -DZMK_CONFIG="${PWD}/config"
@@ -14,4 +15,4 @@ west build -s zmk/app -d build/right -b adv360_right -- -DZMK_CONFIG="${PWD}/con
# Adv360 Right Kconfig file
grep -vE '(^#|^$)' build/right/zephyr/.config
# Rename zmk.uf2
-cp build/left/zephyr/zmk.uf2 "./firmware/${TIMESTAMP}-left.uf2" && cp build/right/zephyr/zmk.uf2 "./firmware/${TIMESTAMP}-right.uf2"
+cp build/left/zephyr/zmk.uf2 "./firmware/${TIMESTAMP}-${COMMIT}-left.uf2" && cp build/right/zephyr/zmk.uf2 "./firmware/${TIMESTAMP}-${COMMIT}-right.uf2"
diff --git a/bin/get_version.sh b/bin/get_version.sh
new file mode 100755
index 0000000..a1b1d6e
--- /dev/null
+++ b/bin/get_version.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+# Get the date, first 4 chars of branch name and short commit hash
+date=$(date -u +"%Y%m%d")
+branch=${1:-$(git rev-parse --abbrev-ref HEAD | cut -c1-4)}
+commit=${2:-$(git rev-parse --short HEAD)}
+
+# Function to transform characters to ZMK key behaviours
+transform_char() {
+ local char=$1
+ if [[ $char =~ [A-Za-z] ]]; then
+ echo "<&kp ${char^^}>, "
+ elif [[ $char =~ [0-9] ]]; then
+ echo "<&kp N${char}>, "
+ elif [ "$char" = "." ]; then
+ echo "<&kp DOT>, "
+ fi
+}
+
+# Iterate over the date and format characters
+formatted_date=""
+for ((i = 0; i < ${#date}; i++)); do
+ formatted_date+=$(transform_char "${date:$i:1}")
+done
+
+# Insert separator between date and branch
+formatted_date+="<&kp MINUS>, "
+
+# Iterate over the branch and format characters
+formatted_branch=""
+for ((i = 0; i < ${#branch}; i++)); do
+ formatted_branch+=$(transform_char "${branch:$i:1}")
+done
+
+# Insert separator between branch and commit hash
+formatted_branch+="<&kp MINUS>, "
+
+# Iterate over the commit hash and format characters
+formatted_commit=""
+for ((i = 0; i < ${#commit}; i++)); do
+ formatted_commit+=$(transform_char "${commit:$i:1}")
+done
+
+# Combine the formatted string, add trailing carriage return
+formatted_result="$formatted_date$formatted_branch$formatted_commit"
+formatted_result+="<&kp RET>"
+
+echo $formatted_result
+# Create new macro to define version, overwrite previous one
+
+echo '#define VERSION_MACRO' > "config/version.dtsi"
+echo 'macro_ver: macro_ver {' >> "config/version.dtsi"
+echo 'compatible = "zmk,behavior-macro";' >> "config/version.dtsi"
+echo 'label = "macro_ver";' >> "config/version.dtsi"
+echo '#binding-cells = <0>;' >> "config/version.dtsi"
+echo "bindings = $formatted_result;" >> "config/version.dtsi"
+echo '};' >> "config/version.dtsi"