-
-
Notifications
You must be signed in to change notification settings - Fork 134
fix(linux): include missing artifacts in source tarball 🗜️ #15566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1b4e254
5fbe9bc
f981469
9322a8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,78 +91,135 @@ function generate_tar_ignore_list() { | |
| local list_var="$4" | ||
| local prefix="$5" | ||
| local includes_array="${includes_var}[@]" | ||
| # shellcheck disable=SC2034 | ||
| local includes=("${!includes_array}") | ||
| local excludes_array="${excludes_var}[@]" | ||
| local excludes=("${!excludes_array}") | ||
| local dir all_dirs found_match inc | ||
|
|
||
| mapfile -t all_dirs < <(find "${directory}" -mindepth 1 -maxdepth 1 -type d | sort) | ||
| for dir in "${all_dirs[@]}"; do | ||
| found_match=false | ||
| for inc in "${includes[@]}"; do | ||
| if [[ "./${inc}" =~ ^${dir} ]]; then | ||
| found_match=true | ||
| if [[ "./${inc}" != "${dir}" ]]; then | ||
| # check subdirectories | ||
| generate_tar_ignore_list "${dir}" "${includes_var}" "${excludes_var}" "${list_var}" "${prefix}" | ||
| fi | ||
| # check if files/subdir in $dir are in excludes list | ||
| _generate_excludes_for_dir "${dir}" "${includes_var}" "${excludes_var}" "${list_var}" | ||
| break | ||
| fi | ||
| done | ||
| if ! ${found_match}; then | ||
| _add_to_list "${list_var}" "${dir}" | ||
|
|
||
| # Loop through excludes and put all without path in single_excludes | ||
| local single_excludes=() | ||
| for item in "${excludes[@]}"; do | ||
| if [[ ${item} != */* ]]; then | ||
| single_excludes+=("${item}") | ||
| fi | ||
| done | ||
|
|
||
| local ignore_list=() | ||
| _process_directory "${directory}" false | ||
|
|
||
| for item in "${ignore_list[@]}"; do | ||
| eval "${list_var}+=(\"--tar-ignore=${item}\")" | ||
| done | ||
| } | ||
|
|
||
| function _generate_excludes_for_dir() { | ||
| function _process_directory() { | ||
| local directory="$1" | ||
| local includes_var="$2" | ||
| local excludes_var="$3" | ||
| local list_var="$4" | ||
| local includes_array="${includes_var}[@]" | ||
| local includes=("${!includes_array}") | ||
| local excludes_array="${excludes_var}[@]" | ||
| local excludes=("${!excludes_array}") | ||
| local file all_files excluded included is_match | ||
|
|
||
| mapfile -t all_files < <(find "${directory}" -mindepth 1 -maxdepth 1 | sort) | ||
| is_match=false | ||
| for file in "${all_files[@]}"; do | ||
| for included in "${includes[@]}"; do | ||
| if [[ "${file}" == ./${included} ]]; then | ||
| is_match=true | ||
| break | ||
| local isParentIncluded="$2" | ||
| local all_items item | ||
|
|
||
| mapfile -t all_items < <(find "${directory}" -mindepth 1 -maxdepth 1 | sort) | ||
| for item in "${all_items[@]}"; do | ||
| debug "Checking item: ${item}" | ||
| if _is_exact_match "includes" "${item}"; then | ||
| debug " Including (full match): ${item}" | ||
| if [[ -d "${item}" ]]; then | ||
| _process_directory "${item}" true | ||
| fi | ||
| done | ||
| if ${is_match} ; then | ||
| if [[ "${file}" != ./${included} ]] && [[ -f "${file}" ]]; then | ||
| _add_to_list "${list_var}" "${file}" | ||
| elif _starts_with "includes" "${item}"; then | ||
| debug " Including (partial match): ${item}" | ||
| if [[ -d "${item}" ]]; then | ||
| _process_directory "${item}" "${isParentIncluded}" | ||
| fi | ||
| elif _is_exact_match "excludes" "${item}"; then | ||
| debug " Excluding (full match): ${item}" | ||
| _add_to_list "${item}" | ||
| elif _ends_with "single_excludes" "${item}" || _is_wildcard_match "single_excludes" "${item}"; then | ||
| debug " Excluding (single exclude): ${item}" | ||
| _add_to_list "${item}" | ||
| elif [[ "${isParentIncluded}" == "false" ]]; then | ||
| debug " Excluding (not included): ${item}" | ||
| _add_to_list "${item}" | ||
| else | ||
| for excluded in "${excludes[@]}"; do | ||
| if [[ "${file}" == ./${excluded} ]]; then | ||
| _add_to_list "${list_var}" "${file}" | ||
| break | ||
| elif [[ "./${excluded}" =~ ^${file} ]]; then | ||
| # check subdirectories | ||
| _generate_excludes_for_dir "${file}" "${includes_var}" "${excludes_var}" "${list_var}" | ||
| break | ||
| fi | ||
| done | ||
| debug " Including (parent included): ${item}" | ||
| if [[ -d "${item}" ]]; then | ||
| _process_directory "${item}" "${isParentIncluded}" | ||
| fi | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| function _add_to_list() { | ||
| local list_var="$1" | ||
| local filename="$2" | ||
|
|
||
| # Note: the files end up in subdirectories under `keyman` (or rather | ||
| # the directory name of $KEYMAN_ROOT), so we can | ||
| # include that when matching files and directories to ignore. | ||
| # shellcheck disable=SC2154 | ||
| eval "${list_var}+=(\"--tar-ignore=${prefix}/${filename#./}\")" | ||
| local item="$1" | ||
| ignore_list+=("${prefix}/${item#./}") | ||
| } | ||
|
|
||
| # Returns true if one of the values in the $1 array equals ${file} ($2) | ||
| # Example: will return true for array=(path1/path2) file=./path1/path2 | ||
| function _is_exact_match() { | ||
| local array_var="$1" | ||
| local file="$2" | ||
| local array_name="${array_var}[@]" | ||
| local haystack=("${!array_name}") | ||
| local item | ||
| for item in "${haystack[@]}"; do | ||
| if [[ "./${item#./}" == "${file}" ]]; then | ||
| return 0 | ||
| fi | ||
| done | ||
| return 1 | ||
| } | ||
|
|
||
| # Returns true if one of the values in the $1 array starts with ${file} ($2) | ||
| # Example: will return true for array=(path1/path2) file=./path1 | ||
| function _starts_with() { | ||
| local array_var="$1" | ||
| local file="$2" | ||
| local array_name="${array_var}[@]" | ||
| local array_values=("${!array_name}") | ||
| local array_item | ||
| for array_item in "${array_values[@]}"; do | ||
| if [[ "./${array_item#./}" == ${file}* ]]; then | ||
| return 0 | ||
| fi | ||
| done | ||
| return 1 | ||
| } | ||
|
|
||
| # Returns true if ${file} ($2) ends with one of the values in the $1 array | ||
| # Example: will return true for array=(path2) file=./path1/path2 | ||
| function _ends_with() { | ||
| local array_var="$1" | ||
| local file="$2" | ||
| local array_name="${array_var}[@]" | ||
| local array_values=("${!array_name}") | ||
| local array_item | ||
| for array_item in "${array_values[@]}"; do | ||
| if [[ "${file}" == */${array_item#./} ]]; then | ||
| return 0 | ||
| fi | ||
| done | ||
| return 1 | ||
| } | ||
|
|
||
| # Returns true if ${file} ($2) matches one of the values of the $1 array. | ||
| # These values may contain wildcards. | ||
| # Example: will return true for array=(*.sh) file=./path1/build.sh | ||
| function _is_wildcard_match() { | ||
|
Comment on lines
158
to
207
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to see unit tests for these eminently testable functions 😁
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes, good point. Done. |
||
| local array_var="$1" | ||
| local file="$2" | ||
| local array_name="${array_var}[@]" | ||
| local array_values=("${!array_name}") | ||
| local array_item | ||
| for array_item in "${array_values[@]}"; do | ||
| array_item=${array_item/./\\.} | ||
| if [[ "${file}" =~ /${array_item/\*/.\*}$ ]]; then | ||
| return 0 | ||
| fi | ||
| done | ||
| return 1 | ||
| } | ||
|
|
||
| function debug() { | ||
| # echo "$@" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have access to check builder local and debug options?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so since it's not a full builder script. |
||
| return 0 | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.