From b2f6215f02191e93e71bcd21163fe8fefc187cfc Mon Sep 17 00:00:00 2001 From: TD-er Date: Tue, 30 Aug 2022 01:35:35 +0200 Subject: [PATCH] [Build_CDN] Generate CDN prefix URL based on Git tag --- src/src/CustomBuild/CompiletimeDefines.cpp | 10 ++++++++++ src/src/CustomBuild/CompiletimeDefines.h | 1 + src/src/Static/WebStaticData.cpp | 3 ++- src/src/WebServer/ESPEasy_WebServer.cpp | 8 ++++---- tools/pio/generate-compiletime-defines.py | 17 +++++++++++++++++ 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/src/CustomBuild/CompiletimeDefines.cpp b/src/src/CustomBuild/CompiletimeDefines.cpp index 4554e6ccf..6899ff986 100644 --- a/src/src/CustomBuild/CompiletimeDefines.cpp +++ b/src/src/CustomBuild/CompiletimeDefines.cpp @@ -85,4 +85,14 @@ const __FlashStringHelper * get_board_name() { #else return F(""); #endif +} + +const __FlashStringHelper * get_CDN_url_prefix() { + #ifdef CUSTOM_BUILD_CDN_URL + return F(CUSTOM_BUILD_CDN_URL); + #elif defined(SET_BUILD_CDN_URL) + return F(SET_BUILD_CDN_URL); + #else + return F("https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy/static/"); + #endif } \ No newline at end of file diff --git a/src/src/CustomBuild/CompiletimeDefines.h b/src/src/CustomBuild/CompiletimeDefines.h index 392a83d25..d5e031a8a 100644 --- a/src/src/CustomBuild/CompiletimeDefines.h +++ b/src/src/CustomBuild/CompiletimeDefines.h @@ -14,6 +14,7 @@ const __FlashStringHelper * get_build_origin(); const __FlashStringHelper * get_build_platform(); const __FlashStringHelper * get_git_head(); const __FlashStringHelper * get_board_name(); +const __FlashStringHelper * get_CDN_url_prefix(); #endif // CUSTOMBUILD_COMPILETIMEDEFINES_H diff --git a/src/src/Static/WebStaticData.cpp b/src/src/Static/WebStaticData.cpp index b0f5bde19..134014641 100644 --- a/src/src/Static/WebStaticData.cpp +++ b/src/src/Static/WebStaticData.cpp @@ -1,5 +1,6 @@ #include "../Static/WebStaticData.h" +#include "../CustomBuild/CompiletimeDefines.h" #include "../Globals/Cache.h" #include "../Helpers/ESPEasy_Storage.h" #include "../WebServer/HTML_wrappers.h" @@ -8,7 +9,7 @@ String generate_external_URL(const String& fname) { String url; url.reserve(80 + fname.length()); - url = F("https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega-20211224/static/"); + url = get_CDN_url_prefix(); url += fname; return url; } diff --git a/src/src/WebServer/ESPEasy_WebServer.cpp b/src/src/WebServer/ESPEasy_WebServer.cpp index 442f5a42c..011ecc67a 100644 --- a/src/src/WebServer/ESPEasy_WebServer.cpp +++ b/src/src/WebServer/ESPEasy_WebServer.cpp @@ -428,10 +428,10 @@ void getWebPageTemplateDefaultHead(WebTemplateParser& parser, bool addMeta, bool if (parser.isTail()) return; parser.process(F("" "" - "" - "" - "" - "" + "" + "" + "" + "" "" "" "{{name}}")); diff --git a/tools/pio/generate-compiletime-defines.py b/tools/pio/generate-compiletime-defines.py index 2af365798..7199ec6b2 100644 --- a/tools/pio/generate-compiletime-defines.py +++ b/tools/pio/generate-compiletime-defines.py @@ -24,6 +24,21 @@ def get_board_name(): return env.BoardConfig().get("name").replace('"', "") +def get_cdn_url_prefix(): + try: + from pygit2 import Repository + import re + try: + regex = re.compile('^/tags/mega-{0}'.format(date.today().strftime("%Y%m%d"))) + repo = Repository('.') + tag_today = [r for r in repo.references if regex.match(restr)][0] + return "https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@{0}/static/".format(tag_today) + except: + return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy/static/' + except ImportError: + return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy/static/' + + def get_git_description(): try: from pygit2 import Repository @@ -67,6 +82,7 @@ def gen_compiletime_defines(node): + [("SET_BOARD_NAME", '\\"%s\\"' % get_board_name())] + [("SET_BUILD_PLATFORM", '\\"%s\\"' % platform.platform())] + [("SET_BUILD_GIT_HEAD", '\\"%s\\"' % get_git_description())] + + [("SET_BUILD_CDN_URL", '\\"%s\\"' % get_cdn_url_prefix())] + [("SET_BUILD_VERSION", compute_version_date())], CCFLAGS=env["CCFLAGS"] ) @@ -80,6 +96,7 @@ print("\u001b[33m PROGNAME: \u001b[0m {}".format(env['PROGNAME'])) print("\u001b[33m BOARD_NAME: \u001b[0m {}".format(get_board_name())) print("\u001b[33m BUILD_PLATFORM: \u001b[0m {}".format(platform.platform())) print("\u001b[33m GIT_HEAD: \u001b[0m {}".format(get_git_description())) +print("\u001b[33m CDN_URL: \u001b[0m {}".format(get_cdn_url_prefix())) print("\u001b[33m BUILD_VERSION: \u001b[0m {}".format(compute_version_date())) print("\u001b[32m ------------------------------- \u001b[0m")