diff --git a/platformio.ini b/platformio.ini index 1a49cee..9048d2f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -96,7 +96,8 @@ custom_component_remove = espressif/esp_hosted espressif/esp-zboss-lib espressif/esp-zigbee-lib chmorgan/esp-libhelix-mp3 -extra_scripts = post:tools/esp32.py +extra_scripts = pre:tools/add_build_commit.py + post:tools/esp32.py post:tools/build.py build_type = ${env.build_type} build_flags = ${env.build_flags} diff --git a/src/PortalTask.h b/src/PortalTask.h index edabc12..5b4505f 100644 --- a/src/PortalTask.h +++ b/src/PortalTask.h @@ -552,6 +552,7 @@ protected: auto docBuild = doc[FPSTR(S_BUILD)].to(); docBuild[FPSTR(S_VERSION)] = BUILD_VERSION; + docBuild[FPSTR(S_COMMIT)] = BUILD_COMMIT; docBuild[FPSTR(S_DATE)] = __DATE__ " " __TIME__; docBuild[FPSTR(S_ENV)] = BUILD_ENV; docBuild[FPSTR(S_CORE)] = ESP.getCoreVersion(); @@ -592,6 +593,7 @@ protected: auto docBuild = doc[FPSTR(S_BUILD)].to(); docBuild[FPSTR(S_VERSION)] = BUILD_VERSION; + docBuild[FPSTR(S_COMMIT)] = BUILD_COMMIT; docBuild[FPSTR(S_DATE)] = __DATE__ " " __TIME__; docBuild[FPSTR(S_ENV)] = BUILD_ENV; docBuild[FPSTR(S_CORE)] = ESP.getCoreVersion(); diff --git a/src/defines.h b/src/defines.h index 3b71bfb..411b770 100644 --- a/src/defines.h +++ b/src/defines.h @@ -30,6 +30,10 @@ #define BUILD_VERSION "0.0.0" #endif +#ifndef BUILD_COMMIT + #define BUILD_COMMIT "undefined" +#endif + #ifndef BUILD_ENV #define BUILD_ENV "undefined" #endif diff --git a/src/strings.h b/src/strings.h index 6b3f362..92c33bb 100644 --- a/src/strings.h +++ b/src/strings.h @@ -56,6 +56,7 @@ const char S_CHANNEL[] PROGMEM = "channel"; const char S_CH2_ALWAYS_ENABLED[] PROGMEM = "ch2AlwaysEnabled"; const char S_CHIP[] PROGMEM = "chip"; const char S_CODE[] PROGMEM = "code"; +const char S_COMMIT[] PROGMEM = "commit"; const char S_CONNECTED[] PROGMEM = "connected"; const char S_CONTINUES[] PROGMEM = "continues"; const char S_COOLING[] PROGMEM = "cooling"; diff --git a/src_data/locales/cn.json b/src_data/locales/cn.json index 2e74d48..01f4d08 100644 --- a/src_data/locales/cn.json +++ b/src_data/locales/cn.json @@ -44,6 +44,7 @@ "build": { "title": "Build", "version": "固件版本", + "commit": "Commit", "date": "日期", "core": "内核版本", "sdk": "SDK" diff --git a/src_data/locales/en.json b/src_data/locales/en.json index 9739e7d..d0d1fc1 100644 --- a/src_data/locales/en.json +++ b/src_data/locales/en.json @@ -44,6 +44,7 @@ "build": { "title": "Build", "version": "Version", + "commit": "Commit", "date": "Date", "core": "Core", "sdk": "SDK" diff --git a/src_data/locales/it.json b/src_data/locales/it.json index 7e2c9e5..91b3ff2 100644 --- a/src_data/locales/it.json +++ b/src_data/locales/it.json @@ -44,6 +44,7 @@ "build": { "title": "Build", "version": "Versione", + "commit": "Commit", "date": "Data", "core": "Core", "sdk": "SDK" diff --git a/src_data/locales/nl.json b/src_data/locales/nl.json index 8d978be..3d03f42 100644 --- a/src_data/locales/nl.json +++ b/src_data/locales/nl.json @@ -40,6 +40,7 @@ "build": { "title": "Build", "version": "Versie", + "commit": "Commit", "date": "Datum", "core": "Core", "sdk": "SDK" diff --git a/src_data/locales/ru.json b/src_data/locales/ru.json index 3f3a036..408446b 100644 --- a/src_data/locales/ru.json +++ b/src_data/locales/ru.json @@ -44,6 +44,7 @@ "build": { "title": "Билд", "version": "Версия", + "commit": "Коммит", "date": "Дата", "core": "Ядро", "sdk": "SDK" diff --git a/src_data/pages/index.html b/src_data/pages/index.html index c309190..a44fbd8 100644 --- a/src_data/pages/index.html +++ b/src_data/pages/index.html @@ -104,6 +104,7 @@ index.system.build.title Env:
+ index.system.build.commit:
index.system.build.date:
index.system.build.core:
index.system.build.sdk: @@ -206,6 +207,7 @@ setBusy('#main-busy', '#main-table', false); setValue('#build-version', result.build.version); + setValue('#build-commit', result.build.commit); setValue('#build-date', result.build.date); setValue('#build-env', result.build.env); setValue('#build-core', result.build.core); diff --git a/tools/add_build_commit.py b/tools/add_build_commit.py new file mode 100644 index 0000000..8142b23 --- /dev/null +++ b/tools/add_build_commit.py @@ -0,0 +1,16 @@ +import subprocess +Import("env") + +try: + commit_hash = "undefined" + result = subprocess.check_output( + ["git", "rev-parse", "--short", "HEAD"] + ) + commit_hash = result.decode("utf-8").strip() + env.Append( + CPPDEFINES=[ + ("BUILD_COMMIT", '\\"{}\\"'.format(commit_hash)) + ] + ) +except Exception as error: + print("Failed to get commit hash: {}".format(error)) \ No newline at end of file