|
6 | 6 |
|
7 | 7 | # NOTE: |
8 | 8 | # |
| 9 | +# Script specific system variables (to set): |
| 10 | +# |
| 11 | +# * NO_SKIP_UNEXPIRED_ENTRIES |
| 12 | +# * NO_DOWNLOAD_ENTRIES |
| 13 | +# * NO_DOWNLOAD_ENTRIES_AND_CREATE_EMPTY_INSTEAD |
| 14 | +# |
9 | 15 | # Yaml specific user variables (to set): |
10 | 16 | # |
11 | 17 | # * DISABLE_YAML_EDIT_FORMAT_RESTORE_BY_DIFF_MERGE_WORKAROUND |
12 | 18 | # |
| 19 | +# The rest of variables is related to other scripts. |
| 20 | +# |
13 | 21 |
|
14 | 22 | [[ -z "$GH_WORKFLOW_ROOT" ]] && { |
15 | 23 | echo "$0: error: \`GH_WORKFLOW_ROOT\` variable must be defined." >&2 |
@@ -393,41 +401,47 @@ for i in $("${YQ_CMDLINE_READ[@]}" '."content-config".entries[0].dirs|keys|.[]' |
393 | 401 | echo " file: \`$index_dir/$index_file\`" |
394 | 402 | echo " URL: $config_query_url" |
395 | 403 |
|
396 | | - # CAUTION: |
397 | | - # The `sed` has to be used to ignore blank lines by replacing `CR` by `LF`. |
398 | | - # This is required for uniform parse the curl output in both verbose or non verbose mode. |
399 | | - # |
400 | | - if eval curl $curl_flags -o '"$TEMP_DIR/content/$index_dir/$index_file"' '"$config_query_url"' 2>&1 | tee "$TEMP_DIR/curl_stderr/$index_dir/$index_file" | sed -E 's/\r([^\n])/\n\1/g' | grep -P '^(?: [% ] |(?: | \d|\d\d)\d |[<>] )'; then |
401 | | - (( stats_downloaded_inc++ )) |
| 404 | + if (( ! NO_DOWNLOAD_ENTRIES && ! NO_DOWNLOAD_ENTRIES_AND_CREATE_EMPTY_INSTEAD )); then |
| 405 | + # CAUTION: |
| 406 | + # The `sed` has to be used to ignore blank lines by replacing `CR` by `LF`. |
| 407 | + # This is required for uniform parse the curl output in both verbose or non verbose mode. |
| 408 | + # |
| 409 | + eval curl $curl_flags -o '"$TEMP_DIR/content/$index_dir/$index_file"' '"$config_query_url"' 2>&1 | tee "$TEMP_DIR/curl_stderr/$index_dir/$index_file" | sed -E 's/\r([^\n])/\n\1/g' | grep -P '^(?: [% ] |(?: | \d|\d\d)\d |[<>] )' |
| 410 | + last_error=$? |
402 | 411 |
|
403 | 412 | echo '---' |
404 | | - else |
405 | | - echo '---' |
406 | 413 |
|
| 414 | + # always print stderr unconditionally to a return code |
407 | 415 | if [[ -s "$TEMP_DIR/curl_stderr/$index_dir/$index_file" ]]; then |
408 | 416 | echo "$(<"$TEMP_DIR/curl_stderr/$index_dir/$index_file")" |
409 | 417 | echo '---' |
410 | 418 | fi |
411 | 419 |
|
412 | | - (( stats_failed_inc++ )) |
| 420 | + if (( ! last_error )); then |
| 421 | + (( stats_downloaded_inc++ )) |
| 422 | + else |
| 423 | + (( stats_failed_inc++ )) |
413 | 424 |
|
414 | | - gh_enable_print_buffering |
| 425 | + gh_enable_print_buffering |
415 | 426 |
|
416 | | - gh_print_error_and_write_to_changelog_text_ln \ |
417 | | - "$0: error: failed to download: \`$index_dir/$index_file\`" \ |
418 | | - "* error: $index_dir/$index_file: failed to download" |
419 | | - continue |
| 427 | + gh_print_error_and_write_to_changelog_text_ln \ |
| 428 | + "$0: error: failed to download: \`$index_dir/$index_file\`" \ |
| 429 | + "* error: $index_dir/$index_file: failed to download" |
| 430 | + continue |
| 431 | + fi |
| 432 | + else |
| 433 | + # just copy from the cache if exist or create empty |
| 434 | + if (( ! NO_DOWNLOAD_ENTRIES_AND_CREATE_EMPTY_INSTEAD )) && [[ -f "$index_dir/$index_file" ]]; then |
| 435 | + cp -T "$index_dir/$index_file" "$TEMP_DIR/content/$index_dir/$index_file" |
| 436 | + else |
| 437 | + echo -n '' > "$TEMP_DIR/content/$index_dir/$index_file" |
| 438 | + fi |
420 | 439 | fi |
421 | 440 |
|
422 | 441 | index_file_next_size="$(stat -c%s "$TEMP_DIR/content/$index_dir/$index_file")" |
423 | 442 |
|
424 | 443 | # check on empty |
425 | 444 | if (( ! index_file_next_size )); then |
426 | | - if [[ -s "$TEMP_DIR/curl_stderr/$index_dir/$index_file" ]]; then |
427 | | - echo "$(<"$TEMP_DIR/curl_stderr/$index_dir/$index_file")" |
428 | | - echo '---' |
429 | | - fi |
430 | | -
|
431 | 445 | (( stats_failed_inc++ )) |
432 | 446 |
|
433 | 447 | gh_enable_print_buffering |
|
0 commit comments