Implement ci target for Makefile to reproduce github CI actions & artifacts (#1769)
* Implement CI target in Makefile to emulate github CI actions & artifacts * Improve filter for metadata * metadata.py: update usage output for wrong number of input arguments / code review * metadata.py: remove excessive checks for the second input argument / code review * metadata.py: remove hard-coded model for multi-lang builds in ModelName argument processing / code review * metadata.py: remove hard-coded models for multi-lang builds in file name pattern processing / code review * metadata.py: update usage output to remove ambiguity about json extension for output file * metadata.py: unify new lines style formatting * metadata.py: sort the list of processing files in alphanumeric order before looping through them to get the same lang order on every generation in every json output file
This commit is contained in:
@@ -10,27 +10,33 @@ import sys
|
||||
# Creates an index metadata json file of the hexfiles folder
|
||||
# This is used by automation like the Pinecil updater
|
||||
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print("Requires the output json name as an arg")
|
||||
if len(sys.argv) < 2 or len(sys.argv) > 3:
|
||||
print("Usage: metadata.py OUTPUT_FILE [model]")
|
||||
print(" OUTPUT_FILE - the name of output file in json format with meta info about binary files")
|
||||
print(" model [optional] - name of the model (as for `make model=NAME`) to scan files for explicitly (all files in source/Hexfile by default otherwise)")
|
||||
exit(1)
|
||||
|
||||
# If model is provided explicitly to scan related files only for json output, then process the argument
|
||||
ModelName = None
|
||||
if len(sys.argv) == 3:
|
||||
ModelName = sys.argv[2]
|
||||
if ModelName.endswith("_multi-lang"):
|
||||
# rename on-the-fly for direct compatibility with make targets like PINECILMODEL_multi-lang
|
||||
ModelName = ModelName.rstrip("-lang")
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
|
||||
HexFileFolder = os.path.join(HERE, "Hexfile")
|
||||
OutputJSONPath = os.path.join(HexFileFolder, sys.argv[1])
|
||||
TranslationsFilesPath = os.path.join(HERE.parent, "Translations")
|
||||
|
||||
|
||||
def load_json(filename: str):
|
||||
with open(filename) as f:
|
||||
return json.loads(f.read())
|
||||
|
||||
|
||||
def read_git_tag():
|
||||
return f"{subprocess.check_output(['git', 'rev-parse', '--short=7', 'HEAD']).strip().decode('ascii').upper()}"
|
||||
|
||||
|
||||
def read_version():
|
||||
with open(HERE / "version.h") as version_file:
|
||||
for line in version_file:
|
||||
@@ -40,10 +46,9 @@ def read_version():
|
||||
return matches[0]
|
||||
raise Exception("Could not parse version")
|
||||
|
||||
|
||||
# Fetch our file listings
|
||||
translation_files = [os.path.join(TranslationsFilesPath, f) for f in os.listdir(TranslationsFilesPath) if os.path.isfile(os.path.join(TranslationsFilesPath, f)) and f.endswith(".json")]
|
||||
output_files = [os.path.join(HexFileFolder, f) for f in os.listdir(HexFileFolder) if os.path.isfile(os.path.join(HexFileFolder, f))]
|
||||
output_files = [os.path.join(HexFileFolder, f) for f in sorted(os.listdir(HexFileFolder)) if os.path.isfile(os.path.join(HexFileFolder, f))]
|
||||
|
||||
parsed_languages = {}
|
||||
for path in translation_files:
|
||||
@@ -61,6 +66,13 @@ for file_path in output_files:
|
||||
if file_path.endswith(".hex") or file_path.endswith(".dfu"):
|
||||
# Find out what language this file is
|
||||
name: str = os.path.basename(file_path)
|
||||
if ModelName is not None:
|
||||
# If ModelName is provided as the second argument (compatible with make model=NAME fully) but current file name doesn't match the model name, then skip it
|
||||
if not name.startswith(ModelName + "_"):
|
||||
continue
|
||||
# If build of interest is not multi-lang one but scanning one is not MODEL_LANG-ID here, then skip it to avoid mess in json between MODEL_LANG-ID & MODEL_multi'
|
||||
if not ModelName.endswith("_multi") and not re.match(r"^" + ModelName + "_" + "([A-Z]+).*$", name):
|
||||
continue
|
||||
matches = re.findall(r"^([a-zA-Z0-9]+)_(.+)\.(.+)$", name)
|
||||
if matches:
|
||||
matches = matches[0]
|
||||
|
||||
Reference in New Issue
Block a user