Skip to content

Commit 9815f07

Browse files
committed
2022.08.07:
* fixed: bash/github/init-*-workflow.sh: minor fixup * new: bash/github: added `init-diff-workflow.sh` to support `diff` command workflow * new: bash/github/init-yq-workflow.sh: `yq_restore_edited_uniform_diff` function to restore yaml comments and blank lines * changed: bash/cache/accum-content.sh: use `yq_restore_edited_uniform_diff` function by default * changed: _externals/tacklelib/bash/tacklelib: merge with the latest changes * refactor: bash/github/init-yq-workflow.sh: code refactor
1 parent 30a09ee commit 9815f07

File tree

10 files changed

+1183
-56
lines changed

10 files changed

+1183
-56
lines changed

_externals/tacklelib/bash/tacklelib/baselib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fi >&2
2626

2727
function tkl_enable_nocase_match()
2828
{
29-
RETURN_VALUE=$(shopt -p nocasematch) && # Read state before change
29+
RETURN_VALUE="$(shopt -p nocasematch)" && # Read state before change
3030
if [[ "$RETURN_VALUE" != 'shopt -s nocasematch' ]]; then
3131
shopt -s nocasematch
3232
return 0
@@ -39,7 +39,7 @@ function tkl_enable_nocase_match()
3939

4040
function tkl_disable_nocase_match()
4141
{
42-
RETURN_VALUE=$(shopt -p nocasematch) && # Read state before change
42+
RETURN_VALUE="$(shopt -p nocasematch)" && # Read state before change
4343
if [[ "$RETURN_VALUE" != 'shopt -u nocasematch' ]]; then
4444
shopt -u nocasematch
4545
return 0

_externals/tacklelib/bash/tacklelib/bash_tacklelib

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function tkl_echo_args_as_expr()
163163
local expr="$1"
164164
shift
165165

166-
eval "unset out_var; echo $expr"
166+
eval "echo $expr"
167167
}
168168

169169
function tkl_export()
@@ -934,7 +934,7 @@ function tkl_convert_backend_path_to_native()
934934
;;
935935

936936
cygwin*)
937-
ConvertedPath=$(/bin/cygpath.exe -w "$RETURN_VALUE")
937+
ConvertedPath="$(/bin/cygpath.exe -w "$RETURN_VALUE")"
938938
# remove last slash
939939
RETURN_VALUE="${ConvertedPath%[/\\]}"
940940
;;
@@ -1460,7 +1460,7 @@ function tkl_exctract_path_ignoring_user_mount_points()
14601460

14611461
builtin trap "tkl_local_return_${#FUNCNAME[@]}; builtin trap - RETURN" RETURN || return 253
14621462

1463-
oldShopt=$(shopt -p nocasematch) # Read state before change
1463+
oldShopt="$(shopt -p nocasematch)" # Read state before change
14641464
if [[ "$oldShopt" != 'shopt -s nocasematch' ]]; then
14651465
shopt -s nocasematch
14661466
else
@@ -1511,7 +1511,7 @@ function tkl_exctract_path_ignoring_user_mount_points()
15111511
RETURN_VALUE="${PathPrefix%/}/"
15121512
tkl_escape_string "$RETURN_VALUE" '' 2
15131513
# msys automatically converts argument to the native path if it begins from '/' character
1514-
ConvertedPath=$("$ComSpecInternal" '^/C' \(echo.$RETURN_VALUE\))
1514+
ConvertedPath="$("$ComSpecInternal" '^/C' \(echo.$RETURN_VALUE\))"
15151515
break
15161516
done
15171517
;;

_externals/tacklelib/bash/tacklelib/funclib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function tkl_get_func_decl()
2525
[[ -z "$FuncName" ]] && return 1
2626

2727
local FuncDecl
28-
FuncDecl=$(declare -f "$FuncName") || return 2
28+
FuncDecl="$(declare -f "$FuncName")" || return 2
2929
[[ -z "$FuncDecl" ]] && return 3
3030

3131
RETURN_VALUE="$FuncDecl"
@@ -83,7 +83,7 @@ function tkl_make_func_copy_ex()
8383
if [[ "${Flags//f/}" == "$Flags" ]]; then
8484
# new function should not exist
8585
local NewFuncDecl
86-
NewFuncDecl=$(declare -f "$NewFuncName") && return 1
86+
NewFuncDecl="$(declare -f "$NewFuncName")" && return 1
8787
[[ -n "$NewFuncDecl" ]] && return 2
8888
fi
8989

_externals/tacklelib/bash/tacklelib/hashlib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function tkl_hash_func_body_as_token()
205205
local FuncDecl
206206
local FuncDeclSize
207207

208-
FuncDecl=$(declare -f "$FuncName")
208+
FuncDecl="$(declare -f "$FuncName")"
209209
[[ -z "$FuncDecl" ]] && return 2
210210

211211
# remove function signature
@@ -233,7 +233,7 @@ function tkl_hash_func_as_token()
233233
local FuncDecl
234234
local FuncDeclSize
235235

236-
FuncDecl=$(declare -f "$FuncName")
236+
FuncDecl="$(declare -f "$FuncName")"
237237
[[ -z "$FuncDecl" ]] && return 2
238238

239239
tkl_crc32 "$FuncDecl" tkl_crc32_gnu || return 3

bash/cache/accum-content.sh

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
# This is a composite script to use from a composite GitHub action.
55
#
66

7+
# NOTE:
8+
#
9+
# Yaml specific user variables (to set):
10+
#
11+
# * DISABLE_YAML_EDIT_FORMAT_RESTORE_BY_DIFF_MERGE_WORKAROUND
12+
#
13+
714
[[ -z "$GH_WORKFLOW_ROOT" ]] && {
815
echo "$0: error: \`GH_WORKFLOW_ROOT\` variable must be defined." >&2
916
exit 255
@@ -198,7 +205,7 @@ for i in $("${YQ_CMDLINE_READ[@]}" '."content-config".entries[0].dirs|keys|.[]'
198205
fi
199206
200207
if [[ "$config_index_dir" != "$index_dir" ]]; then
201-
gh_print_warning_ln "$0: warning: invalid index file directory entry: dirs[$i]:"$'\n'" config_index_dir=\`$config_index_dir\`"$'\n'" index_dir=\`$index_dir\`"
208+
gh_print_warning_ln "$0: warning: invalid index file directory entry: dirs[$i]:"$'\n'" config_dir=\`$config_dir\`"$'\n'" index_dir=\`$index_dir\`"$'\n'" content_index_dir=\`$content_index_dir\`"$'\n'" config_index_dir=\`$config_index_dir\`"
202209
203210
(( stats_failed_inc++ ))
204211
@@ -295,10 +302,22 @@ for i in $("${YQ_CMDLINE_READ[@]}" '."content-config".entries[0].dirs|keys|.[]'
295302
if [[ -n "$index_file_next_md5_hash" && "$index_file_next_md5_hash" != "$index_file_prev_md5_hash" ]]; then
296303
index_file_next_timestamp="$(date --utc +%FT%TZ)"
297304
298-
yq_edit 'content-index' "$content_index_file" "$TEMP_DIR/content-index-[$i][$j]-edited.yml" \
299-
".\"content-index\".entries[0].dirs[$i].files[$j].\"md5-hash\"=\"$index_file_next_md5_hash\"" && \
300-
yq_diff "$content_index_file" "$TEMP_DIR/content-index-[$i][$j]-edited.yml" "$TEMP_DIR/content-index-[$i][$j]-edited.diff" && \
301-
yq_patch "$content_index_file" "$TEMP_DIR/content-index-[$i][$j]-edited.diff" "$TEMP_DIR/content-index-[$i][$j].yml" "$content_index_file"
305+
{
306+
# update index file fields
307+
if (( DISABLE_YAML_EDIT_FORMAT_RESTORE_BY_DIFF_MERGE_WORKAROUND )); then
308+
yq_edit 'content-index' 'edit' "$content_index_file" "$TEMP_DIR/content-index-[$i][$j]-edited.yml" \
309+
".\"content-index\".entries[0].dirs[$i].files[$j].\"md5-hash\"=\"$index_file_next_md5_hash\"" && \
310+
mv -Tf "$TEMP_DIR/content-index-[$i][$j]-edited.yml" "$content_index_file"
311+
else
312+
yq_edit 'content-index' 'edit' "$content_index_file" "$TEMP_DIR/content-index-[$i][$j]-edited.yml" \
313+
".\"content-index\".entries[0].dirs[$i].files[$j].\"md5-hash\"=\"$index_file_next_md5_hash\"" && \
314+
yq_diff "$TEMP_DIR/content-index-[$i][$j]-edited.yml" "$content_index_file" "$TEMP_DIR/content-index-[$i][$j]-edited.diff" && \
315+
yq_restore_edited_uniform_diff "$TEMP_DIR/content-index-[$i][$j]-edited.diff" "$TEMP_DIR/content-index-[$i][$j]-edited-restored.diff" && \
316+
yq_patch "$TEMP_DIR/content-index-[$i][$j]-edited.yml" "$TEMP_DIR/content-index-[$i][$j]-edited-restored.diff" "$TEMP_DIR/content-index-[$i][$j].yml" "$content_index_file"
317+
fi
318+
} || {
319+
(( stats_failed_inc++ ))
320+
}
302321
303322
echo '---'
304323
fi
@@ -395,13 +414,26 @@ for i in $("${YQ_CMDLINE_READ[@]}" '."content-config".entries[0].dirs|keys|.[]'
395414
(( stats_skipped_inc++ ))
396415
fi
397416
398-
# update index file fields
399-
yq_edit 'content-index' "$content_index_file" "$TEMP_DIR/content-index-[$i][$j]-edited.yml" \
400-
".\"content-index\".entries[0].dirs[$i].files[$j].\"queried-url\"=\"$config_query_url\"" \
401-
".\"content-index\".entries[0].dirs[$i].files[$j].\"md5-hash\"=\"$index_file_next_md5_hash\"" \
402-
".\"content-index\".entries[0].dirs[$i].files[$j].timestamp=\"$index_file_next_timestamp\"" && \
403-
yq_diff "$content_index_file" "$TEMP_DIR/content-index-[$i][$j]-edited.yml" "$TEMP_DIR/content-index-[$i][$j]-edited.diff" && \
404-
yq_patch "$content_index_file" "$TEMP_DIR/content-index-[$i][$j]-edited.diff" "$TEMP_DIR/content-index-[$i][$j].yml" "$content_index_file"
417+
{
418+
# update index file fields
419+
if (( DISABLE_YAML_EDIT_FORMAT_RESTORE_BY_DIFF_MERGE_WORKAROUND )); then
420+
yq_edit 'content-index' 'edit' "$content_index_file" "$TEMP_DIR/content-index-[$i][$j]-edited.yml" \
421+
".\"content-index\".entries[0].dirs[$i].files[$j].\"queried-url\"=\"$config_query_url\"" \
422+
".\"content-index\".entries[0].dirs[$i].files[$j].\"md5-hash\"=\"$index_file_next_md5_hash\"" \
423+
".\"content-index\".entries[0].dirs[$i].files[$j].timestamp=\"$index_file_next_timestamp\"" && \
424+
mv -Tf "$TEMP_DIR/content-index-[$i][$j]-edited.yml" "$content_index_file"
425+
else
426+
yq_edit 'content-index' 'edit' "$content_index_file" "$TEMP_DIR/content-index-[$i][$j]-edited.yml" \
427+
".\"content-index\".entries[0].dirs[$i].files[$j].\"queried-url\"=\"$config_query_url\"" \
428+
".\"content-index\".entries[0].dirs[$i].files[$j].\"md5-hash\"=\"$index_file_next_md5_hash\"" \
429+
".\"content-index\".entries[0].dirs[$i].files[$j].timestamp=\"$index_file_next_timestamp\"" && \
430+
yq_diff "$TEMP_DIR/content-index-[$i][$j]-edited.yml" "$content_index_file" "$TEMP_DIR/content-index-[$i][$j]-edited.diff" && \
431+
yq_restore_edited_uniform_diff "$TEMP_DIR/content-index-[$i][$j]-edited.diff" "$TEMP_DIR/content-index-[$i][$j]-edited-restored.diff" && \
432+
yq_patch "$TEMP_DIR/content-index-[$i][$j]-edited.yml" "$TEMP_DIR/content-index-[$i][$j]-edited-restored.diff" "$TEMP_DIR/content-index-[$i][$j].yml" "$content_index_file"
433+
fi
434+
} || {
435+
(( stats_failed_inc++ ))
436+
}
405437
406438
echo '---'
407439
done
@@ -410,11 +442,22 @@ done
410442
content_index_file_next_md5_hash=( $(md5sum -b "$content_index_file") )
411443
412444
if (( stats_changed_inc )) || [[ "$content_index_file_next_md5_hash" != "$content_index_file_prev_md5_hash" ]]; then
413-
# update index file change timestamp
414-
yq_edit 'content-index' "$content_index_file" "$TEMP_DIR/content-index-[timestamp].yml" \
415-
".\"content-index\".timestamp=\"$index_file_next_timestamp\"" && \
416-
yq_diff "$content_index_file" "$TEMP_DIR/content-index-[timestamp].yml" "$TEMP_DIR/content-index-[timestamp].diff" && \
417-
yq_patch "$content_index_file" "$TEMP_DIR/content-index-[timestamp].diff" "$TEMP_DIR/content-index-[timestamp].yml" "$content_index_file"
445+
{
446+
# update index file change timestamp
447+
if (( DISABLE_YAML_EDIT_FORMAT_RESTORE_BY_DIFF_MERGE_WORKAROUND )); then
448+
yq_edit 'content-index' 'edit' "$content_index_file" "$TEMP_DIR/content-index-[timestamp]-edited.yml" \
449+
".\"content-index\".timestamp=\"$index_file_next_timestamp\"" && \
450+
mv -Tf "$TEMP_DIR/content-index-[timestamp]-edited.yml" "$content_index_file"
451+
else
452+
yq_edit 'content-index' 'edit' "$content_index_file" "$TEMP_DIR/content-index-[timestamp]-edited.yml" \
453+
".\"content-index\".timestamp=\"$index_file_next_timestamp\"" && \
454+
yq_diff "$TEMP_DIR/content-index-[timestamp]-edited.yml" "$content_index_file" "$TEMP_DIR/content-index-[timestamp]-edited.diff" && \
455+
yq_restore_edited_uniform_diff "$TEMP_DIR/content-index-[timestamp]-edited.diff" "$TEMP_DIR/content-index-[timestamp]-edited-restored.diff" && \
456+
yq_patch "$TEMP_DIR/content-index-[timestamp]-edited.yml" "$TEMP_DIR/content-index-[timestamp]-edited-restored.diff" "$TEMP_DIR/content-index-[timestamp].yml" "$content_index_file"
457+
fi
458+
} || {
459+
(( stats_failed_inc++ ))
460+
}
418461
419462
echo '---'
420463
fi

bash/github/accum-rate-limits.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
source "$GH_WORKFLOW_ROOT/_externals/tacklelib/bash/tacklelib/bash_tacklelib" || exit $?
1313

14+
tkl_include_or_abort "$GH_WORKFLOW_ROOT/_externals/tacklelib/bash/tacklelib/traplib.sh"
15+
1416
tkl_include_or_abort "$GH_WORKFLOW_ROOT/bash/github/init-basic-workflow.sh"
1517
tkl_include_or_abort "$GH_WORKFLOW_ROOT/bash/github/init-stats-workflow.sh"
1618
tkl_include_or_abort "$GH_WORKFLOW_ROOT/bash/github/init-jq-workflow.sh"

bash/github/accum-stats.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
source "$GH_WORKFLOW_ROOT/_externals/tacklelib/bash/tacklelib/bash_tacklelib" || exit $?
1313

14+
tkl_include_or_abort "$GH_WORKFLOW_ROOT/_externals/tacklelib/bash/tacklelib/traplib.sh"
15+
1416
tkl_include_or_abort "$GH_WORKFLOW_ROOT/bash/github/init-basic-workflow.sh"
1517
tkl_include_or_abort "$GH_WORKFLOW_ROOT/bash/github/init-stats-workflow.sh"
1618
tkl_include_or_abort "$GH_WORKFLOW_ROOT/bash/github/init-jq-workflow.sh"

0 commit comments

Comments
 (0)