@@ -142,6 +142,7 @@ if test "${OPENSOURCE_ONLY:?}" != 'false'; then
142142 printf ' ZIP_SHORT_COMMIT_ID=%s\n' " ${ZIP_SHORT_COMMIT_ID?} "
143143 printf ' ZIP_BUILD_TYPE=%s\n' " ${BUILD_TYPE?} "
144144 printf ' ZIP_BUILD_TYPE_SUPPORTED=%s\n' ' false'
145+ printf ' ZIP_BRANCH_NAME=\n'
145146 printf ' ZIP_IS_ALPHA=%s\n' " ${MODULE_IS_ALPHA?} "
146147 printf ' ZIP_SHA256=\n'
147148 printf ' ZIP_MD5=\n'
@@ -176,6 +177,13 @@ if test -z "${TEMP_DIR}"; then ui_error 'Failed to create our temp dir'; fi
176177rm -rf " ${TEMP_DIR:? } " /* || ui_error ' Failed to empty our temp dir'
177178
178179# Set filename
180+ sanitize_filename_part ()
181+ {
182+ # The "-" character must be replaced because it is used to separate the various parts of the filename
183+ printf ' %s' " ${1:? } " | tr -- ' -\\/:*?"<>|\r\n\0' ' _' || ui_error ' Failed to sanitize filename part'
184+ }
185+
186+ BRANCH_NAME=' '
179187FILENAME_COMMIT_ID=" g${ZIP_SHORT_COMMIT_ID?} "
180188test " ${FILENAME_COMMIT_ID:? } " ! = ' g' || FILENAME_COMMIT_ID=' NOGIT'
181189FILENAME_START=" ${MODULE_ID:? } -${MODULE_VER:? } -"
@@ -184,18 +192,18 @@ FILENAME_END="-${BUILD_TYPE:?}-by-${MODULE_AUTHOR:?}"
184192
185193if test " ${CI:- false} " ! = ' false' ; then
186194 if test -n " ${CI_COMMIT_BRANCH-} " && test " ${CI_COMMIT_BRANCH:? } " ! = " ${CI_DEFAULT_BRANCH:- unknown} " ; then
187- FILENAME_MIDDLE=" ${CI_COMMIT_BRANCH:? } -${FILENAME_MIDDLE:? } " # GitLab
188- fi
189- if test " ${GITHUB_REF_TYPE-} " = ' branch' && test -n " ${GITHUB_REF_NAME-} " && test " ${GITHUB_REF_NAME:? } " ! = " ${GITHUB_REPOSITORY_DEFAULT_BRANCH:- main} " ; then
190- FILENAME_MIDDLE=" ${GITHUB_REF_NAME:? } -${FILENAME_MIDDLE:? } " # GitHub
195+ BRANCH_NAME=" $( sanitize_filename_part " ${CI_COMMIT_BRANCH:? } " || :) " # GitLab
196+ elif test " ${GITHUB_REF_TYPE-} " = ' branch' && test -n " ${GITHUB_REF_NAME-} " && test " ${GITHUB_REF_NAME:? } " ! = " ${GITHUB_REPOSITORY_DEFAULT_BRANCH:- main} " ; then
197+ BRANCH_NAME=" $( sanitize_filename_part " ${GITHUB_REF_NAME:? } " || :) " # GitHub
191198 fi
199+ test -z " ${BRANCH_NAME?} " || FILENAME_MIDDLE=" ${BRANCH_NAME:? } -${FILENAME_MIDDLE:? } "
192200 if test " ${CI_PROJECT_NAMESPACE:- ${GITHUB_REPOSITORY_OWNER:- unknown} } " ! = ' micro' ' 5k' ; then
193201 FILENAME_MIDDLE=" fork-${FILENAME_MIDDLE:? } " # GitLab / GitHub
194202 fi
195203else
196- branch_name =" $( git 2> /dev/null branch --show-current) " || branch_name =" $( git 2> /dev/null rev-parse --abbrev-ref HEAD) " || branch_name =' '
197- if test -n " ${branch_name ?} " && test " ${branch_name :? } " ! = ' main' && test " ${branch_name :? } " ! = ' master ' && test " ${branch_name :? }" ! = ' HEAD' ; then
198- FILENAME_MIDDLE=" ${branch_name :? } -${FILENAME_MIDDLE:? } "
204+ BRANCH_NAME =" $( git 2> /dev/null branch --show-current) " || BRANCH_NAME =" $( git 2> /dev/null rev-parse --abbrev-ref HEAD) " || BRANCH_NAME =' '
205+ if test -n " ${BRANCH_NAME ?} " && test " ${BRANCH_NAME :? } " ! = ' main' && test " ${BRANCH_NAME :? } " ! = ' HEAD' ; then
206+ FILENAME_MIDDLE=" $( sanitize_filename_part " ${BRANCH_NAME :? }" || : ) -${FILENAME_MIDDLE:? } "
199207 fi
200208fi
201209
@@ -369,6 +377,7 @@ if test "${GITHUB_JOB:-false}" != 'false'; then
369377 printf ' ZIP_SHORT_COMMIT_ID=%s\n' " ${ZIP_SHORT_COMMIT_ID?} "
370378 printf ' ZIP_BUILD_TYPE=%s\n' " ${BUILD_TYPE?} "
371379 printf ' ZIP_BUILD_TYPE_SUPPORTED=%s\n' ' true'
380+ printf ' ZIP_BRANCH_NAME=%s\n' " ${BRANCH_NAME?} "
372381 printf ' ZIP_IS_ALPHA=%s\n' " ${MODULE_IS_ALPHA?} "
373382 printf ' ZIP_SHA256=%s\n' " ${ZIP_SHA256?} "
374383 printf ' ZIP_MD5=%s\n' " ${ZIP_MD5?} "
0 commit comments