From f99e4ed45bb3f37b92f962b4f6a9fd343a049f8d Mon Sep 17 00:00:00 2001 From: Sadek Baroudi Date: Sun, 30 Oct 2022 22:30:47 -0700 Subject: [PATCH] added firmware file renaming to fp_build.sh for output zip file in github actions --- bin/fp_build.sh | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/bin/fp_build.sh b/bin/fp_build.sh index 7c1440dfb4..2026878d42 100755 --- a/bin/fp_build.sh +++ b/bin/fp_build.sh @@ -166,6 +166,60 @@ make_build_string_recursive() { fi } +rename_file_from_build_string() { + tokens=( $1 ) + + # Calculate the qmk build filename prefix to move it + token_file_prefix="${tokens[1]//\//_}" + token_file_prefix="${token_file_prefix//:/_}" + + # Start the new filename, which will be appended to below + target_filename="${token_file_prefix}" + + # check if token_i>1 + # check if first paramter is CONVERT_TO, then grab other side of = (stemcell for example) + # otherwise grab first parameter (RGBLIGHT_ENABLE for example) + # rename file accordingly + token_i=0 + for token in "${tokens[@]}" + do + if [[ $token_i -gt 1 ]]; then + config_param="${token%%=*}" + config_value="${token#*=}" + if [[ "${config_param}" == "CONVERT_TO" ]]; then + token_file_prefix+="_${config_value}" + target_filename+="_${config_value}" + else + # ,, converts to lowercase + target_filename+="_${config_param,,}" + fi + fi + token_i+=1 + done + + echo "${0}: filename token is ${token_file_prefix}" + echo "${0}: target filename is ${target_filename}" + + hex_source_file=".build/${token_file_prefix}.hex" + uf2_source_file=".build/${token_file_prefix}.uf2" + hex_target_file=".build/${target_filename}.hex" + uf2_target_file=".build/${target_filename}.uf2" + + if test -f "${hex_source_file}"; then + echo "${0}: Renaming file '${hex_source_file}' to '${hex_target_file}'" + mv "${hex_source_file}" "${hex_target_file}" + else + echo "${0}: Could not find hex source file ${hex_source_file} to rename." + fi + + if test -f "${uf2_source_file}"; then + echo "${0}: Renaming file '${uf2_source_file}' to '${uf2_target_file}'" + mv "${uf2_source_file}" "${uf2_target_file}" + else + echo "${0}: Could not find uf2 source file ${uf2_source_file} to rename." + fi +} + # process_build_string $build_string $run_build process_build_string() { build_string="$1" @@ -177,6 +231,8 @@ process_build_string() { echo "fp_build.sh: Running QMK Build...." echo "" eval "${build_string}" + + rename_file_from_build_string "${build_string}" fi }