Skip to content

Commit d7d08bf

Browse files
committed
2022.08.10:
* fixed: bash/github/print-*.sh: notices, warnings, errors functions fixup * fixed: bash/github/accum-rate-limits.sh: json format change fixup * changed: bash/github/accum-rate-limits.sh: changed rate limits json format change message from an error to a warning
1 parent 1cc3010 commit d7d08bf

File tree

8 files changed

+168
-24
lines changed

8 files changed

+168
-24
lines changed

bash/github/accum-rate-limits.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ IFS=$'\n' read -r -d '' \
5050
stats_prev_exec_code_scanning_upload_limit stats_prev_exec_code_scanning_upload_used \
5151
stats_prev_exec_actions_runner_registration_limit stats_prev_exec_actions_runner_registration_used \
5252
stats_prev_exec_scim_limit stats_prev_exec_scim_used \
53+
stats_prev_exec_dependency_snapshots_limit stats_prev_exec_dependency_snapshots_used \
5354
stats_prev_exec_rate_limit stats_prev_exec_rate_used \
5455
<<< $(jq ".resources.core.limit,.resources.core.used,\
5556
.resources.search.limit,.resources.search.used,\
@@ -59,6 +60,7 @@ IFS=$'\n' read -r -d '' \
5960
.resources.code_scanning_upload.limit,.resources.code_scanning_upload.used,\
6061
.resources.actions_runner_registration.limit,.resources.actions_runner_registration.used,\
6162
.resources.scim.limit,.resources.scim.used,\
63+
.resources.dependency_snapshots.limit,.resources.dependency_snapshots.used,\
6264
.rate.limit,.rate.used\
6365
" $stats_accum_json)
6466

@@ -75,6 +77,7 @@ jq_fix_null \
7577
stats_prev_exec_code_scanning_upload_limit:0 stats_prev_exec_code_scanning_upload_used:0 \
7678
stats_prev_exec_actions_runner_registration_limit:0 stats_prev_exec_actions_runner_registration_used:0 \
7779
stats_prev_exec_scim_limit:0 stats_prev_exec_scim_used:0 \
80+
stats_prev_exec_dependency_snapshots_limit:0 stats_prev_exec_dependency_snapshots_used:0 \
7881
stats_prev_exec_rate_limit:0 stats_prev_exec_rate_used:0
7982

8083
gh_print_notice_ln "prev: graphql / rate: limit used: $stats_prev_exec_graphql_limit $stats_prev_exec_graphql_used / $stats_prev_exec_rate_limit $stats_prev_exec_rate_used"
@@ -92,6 +95,7 @@ IFS=$'\n' read -r -d '' \
9295
code_scanning_upload_limit code_scanning_upload_used \
9396
actions_runner_registration_limit actions_runner_registration_used \
9497
scim_limit scim_used \
98+
dependency_snapshots_limit dependency_snapshots_used \
9599
rate_limit rate_used \
96100
resources_length \
97101
<<< $(jq ".resources.core.limit,.resources.core.used,\
@@ -102,6 +106,7 @@ IFS=$'\n' read -r -d '' \
102106
.resources.code_scanning_upload.limit,.resources.code_scanning_upload.used,\
103107
.resources.actions_runner_registration.limit,.resources.actions_runner_registration.used,\
104108
.resources.scim.limit,.resources.scim.used,\
109+
.resources.dependency_snapshots.limit,.resources.dependency_snapshots.used,\
105110
.rate.limit,.rate.used,
106111
.resources|length\
107112
" $stats_json)
@@ -119,6 +124,7 @@ jq_fix_null \
119124
code_scanning_upload_limit:0 code_scanning_upload_used:0 \
120125
actions_runner_registration_limit:0 actions_runner_registration_used:0 \
121126
scim_limit:0 scim_used:0 \
127+
dependency_snapshots_limit:0 dependency_snapshots_used:0 \
122128
rate_limit:0 rate_used:0
123129

124130
gh_print_notice_ln "next: graphql / rate: limit used: $graphql_limit $graphql_used / $rate_limit $rate_used"
@@ -141,6 +147,7 @@ if (( core_limit != stats_prev_exec_core_limit || core_used != stats_prev_exec_c
141147
code_scanning_upload_limit != stats_prev_exec_code_scanning_upload_limit || code_scanning_upload_used != stats_prev_exec_code_scanning_upload_used || \
142148
actions_runner_registration_limit != stats_prev_exec_actions_runner_registration_limit || actions_runner_registration_used != stats_prev_exec_actions_runner_registration_used || \
143149
scim_limit != stats_prev_exec_scim_limit || scim_used != stats_prev_exec_scim_used || \
150+
dependency_snapshots_limit != stats_prev_exec_dependency_snapshots_limit || dependency_snapshots_used != stats_prev_exec_dependency_snapshots_used || \
144151
rate_limit != stats_prev_exec_rate_limit || rate_used != stats_prev_exec_rate_used )); then
145152
has_changes=1
146153

@@ -175,13 +182,13 @@ stats_prev_exec_rate_used_dec=0
175182
gh_print_notice_and_write_to_changelog_text_bullet_ln \
176183
"prev exec diff: graphql / rate: limit used: +$stats_prev_exec_graphql_limit_inc +$stats_prev_exec_graphql_used_inc -$stats_prev_exec_graphql_limit_dec -$stats_prev_exec_graphql_used_dec / +$stats_prev_exec_rate_limit_inc +$stats_prev_exec_rate_used_inc -$stats_prev_exec_rate_limit_dec -$stats_prev_exec_rate_used_dec"
177184

178-
if (( resources_length != 8 || \
185+
if (( resources_length != 9 || \
179186
! core_limit || ! search_limit || ! graphql_limit || ! integration_manifest_limit || \
180-
! source_import_limit || ! code_scanning_upload_limit || ! actions_runner_registration_limit || ! scim_limit || \
187+
! source_import_limit || ! code_scanning_upload_limit || ! actions_runner_registration_limit || ! scim_limit || ! dependency_snapshots_limit || \
181188
! rate_limit )); then
182189
gh_enable_print_buffering
183190

184-
gh_print_error_and_write_to_changelog_text_bullet_ln "$0: error: json data is invalid or empty or format is changed." "json data is invalid or empty or format is changed"
191+
gh_print_warning_and_write_to_changelog_text_bullet_ln "$0: warning: json data is invalid or empty or format is changed." "json data is invalid or empty or format is changed"
185192

186193
# try to request json generic response fields to print them as a notice
187194
IFS=$'\n' read -r -d '' json_message json_url json_documentation_url <<< $(jq ".message,.url,.documentation_url" $stats_json)

bash/github/print-error.sh

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,37 @@ function gh_print_error_ln()
6868
fi
6969
}
7070

71+
function gh_print_errors_nobuf_nolag()
72+
{
73+
local IFS=$'\n'
74+
local arg
75+
76+
# with check on integer value
77+
[[ -n "$PRINT_ERROR_LAG_FSEC" && -z "${PRINT_ERROR_LAG_FSEC//[0-9]/}" ]] && sleep $PRINT_ERROR_LAG_FSEC
78+
79+
# fix GitHub log issue when a trailing line return charcter in the message does convert into blank line
80+
81+
if [[ -n "$GITHUB_ACTIONS" ]]; then
82+
for arg in "$@"; do
83+
gh_trim_trailing_line_return_chars "$arg"
84+
echo -n "::error ::$RETURN_VALUE" # without line return
85+
done >&2
86+
else
87+
for arg in "$@"; do
88+
gh_trim_trailing_line_return_chars "$arg"
89+
echo "::error ::$RETURN_VALUE" # with line return
90+
done >&2
91+
fi
92+
}
93+
94+
function gh_print_errors_nobuf_noprefix()
95+
{
96+
# with check on integer value
97+
[[ -n "$PRINT_ERROR_LAG_FSEC" && -z "${PRINT_ERROR_LAG_FSEC//[0-9]/}" ]] && sleep $PRINT_ERROR_LAG_FSEC
98+
99+
gh_print_args "$@" >&2
100+
}
101+
71102
function gh_print_errors()
72103
{
73104
local IFS=$'\n'
@@ -88,13 +119,9 @@ function gh_print_errors()
88119
[[ -n "$PRINT_ERROR_LAG_FSEC" && -z "${PRINT_ERROR_LAG_FSEC//[0-9]/}" ]] && sleep $PRINT_ERROR_LAG_FSEC
89120

90121
if [[ -n "$GITHUB_ACTIONS" ]]; then
91-
for arg in "$@"; do
92-
echo "::error ::$arg" >&2
93-
done
122+
gh_print_errors_nobuf_nolag "$@"
94123
else
95-
for arg in "$@"; do
96-
echo "$arg" >&2
97-
done
124+
gh_print_args "$@" >&2
98125
fi
99126
fi
100127
}

bash/github/print-notice.sh

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,34 @@ function gh_print_notice_ln()
6868
fi
6969
}
7070

71+
function gh_print_notices_nobuf_nolag()
72+
{
73+
local IFS=$'\n'
74+
local arg
75+
76+
# fix GitHub log issue when a trailing line return charcter in the message does convert into blank line
77+
78+
if [[ -n "$GITHUB_ACTIONS" ]]; then
79+
for arg in "$@"; do
80+
gh_trim_trailing_line_return_chars "$arg"
81+
echo -n "::notice ::$RETURN_VALUE" # without line return
82+
done
83+
else
84+
for arg in "$@"; do
85+
gh_trim_trailing_line_return_chars "$arg"
86+
echo "::notice ::$RETURN_VALUE" # with line return
87+
done
88+
fi
89+
}
90+
91+
function gh_print_notices_nobuf_noprefix()
92+
{
93+
# with check on integer value
94+
[[ -n "$PRINT_NOTICE_LAG_FSEC" && -z "${PRINT_NOTICE_LAG_FSEC//[0-9]/}" ]] && sleep $PRINT_NOTICE_LAG_FSEC
95+
96+
gh_print_args "$@"
97+
}
98+
7199
function gh_print_notices()
72100
{
73101
local IFS=$'\n'
@@ -88,13 +116,9 @@ function gh_print_notices()
88116
[[ -n "$PRINT_NOTICE_LAG_FSEC" && -z "${PRINT_NOTICE_LAG_FSEC//[0-9]/}" ]] && sleep $PRINT_NOTICE_LAG_FSEC
89117

90118
if [[ -n "$GITHUB_ACTIONS" ]]; then
91-
for arg in "$@"; do
92-
echo "::notice ::$arg"
93-
done
119+
gh_print_notices_nobuf_nolag "$@"
94120
else
95-
for arg in "$@"; do
96-
echo "$arg"
97-
done
121+
gh_print_args "$@"
98122
fi
99123
fi
100124
}

bash/github/print-warning.sh

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,34 @@ function gh_print_warning_ln()
6868
fi
6969
}
7070

71+
function gh_print_warnings_nobuf_nolag()
72+
{
73+
local IFS=$'\n'
74+
local arg
75+
76+
# fix GitHub log issue when a trailing line return charcter in the message does convert into blank line
77+
78+
if [[ -n "$GITHUB_ACTIONS" ]]; then
79+
for arg in "$@"; do
80+
gh_trim_trailing_line_return_chars "$arg"
81+
echo -n "::warning ::$RETURN_VALUE" # without line return
82+
done >&2
83+
else
84+
for arg in "$@"; do
85+
gh_trim_trailing_line_return_chars "$arg"
86+
echo "::warning ::$RETURN_VALUE" # with line return
87+
done >&2
88+
fi
89+
}
90+
91+
function gh_print_warnings_nobuf_noprefix()
92+
{
93+
# with check on integer value
94+
[[ -n "$PRINT_WARNING_LAG_FSEC" && -z "${PRINT_WARNING_LAG_FSEC//[0-9]/}" ]] && sleep $PRINT_WARNING_LAG_FSEC
95+
96+
gh_print_args "$@" >&2
97+
}
98+
7199
function gh_print_warnings()
72100
{
73101
local IFS=$'\n'
@@ -88,13 +116,9 @@ function gh_print_warnings()
88116
[[ -n "$PRINT_WARNING_LAG_FSEC" && -z "${PRINT_WARNING_LAG_FSEC//[0-9]/}" ]] && sleep $PRINT_WARNING_LAG_FSEC
89117

90118
if [[ -n "$GITHUB_ACTIONS" ]]; then
91-
for arg in "$@"; do
92-
echo "::warning ::$arg" >&2
93-
done
119+
gh_print_warnings_nobuf_nolag "$@"
94120
else
95-
for arg in "$@"; do
96-
echo "$arg" >&2
97-
done
121+
gh_print_args "$@" >&2
98122
fi
99123
fi
100124
}

bash/github/print.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SOURCE_GHWF_PRINT_SH=1 # including guard
1111

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

14+
tkl_include_or_abort "$GH_WORKFLOW_ROOT/bash/github/utils.sh"
1415
tkl_include_or_abort "$GH_WORKFLOW_ROOT/bash/github/print-notice.sh"
1516
tkl_include_or_abort "$GH_WORKFLOW_ROOT/bash/github/print-warning.sh"
1617
tkl_include_or_abort "$GH_WORKFLOW_ROOT/bash/github/print-error.sh"
@@ -35,21 +36,21 @@ function gh_flush_print_buffers()
3536
if [[ -n "${PRINT_NOTICE_BUF_STR+x}" ]]; then
3637
print_str="${PRINT_NOTICE_BUF_STR}"
3738
unset PRINT_NOTICE_BUF_STR
38-
gh_print_notices "$print_str"
39+
gh_print_notices_nobuf_noprefix "$print_str"
3940
fi
4041

4142
# warnings
4243
if [[ -n "${PRINT_WARNING_BUF_STR+x}" ]]; then
4344
print_str="${PRINT_WARNING_BUF_STR}"
4445
unset PRINT_WARNING_BUF_STR
45-
gh_print_warnings "$print_str"
46+
gh_print_warnings_nobuf_noprefix "$print_str"
4647
fi
4748

4849
# errors
4950
if [[ -n "${PRINT_ERROR_BUF_STR+x}" ]]; then
5051
print_str="${PRINT_ERROR_BUF_STR}"
5152
unset PRINT_ERROR_BUF_STR
52-
gh_print_errors "$print_str"
53+
gh_print_errors_nobuf_noprefix "$print_str"
5354
fi
5455
}
5556

@@ -61,3 +62,23 @@ function gh_write_to_changelog_text_ln()
6162

6263
CHANGELOG_BUF_STR="${CHANGELOG_BUF_STR}${changelog_msg}"$'\r\n'
6364
}
65+
66+
function gh_print_args()
67+
{
68+
local IFS=$'\n'
69+
local arg
70+
71+
# fix GitHub log issue when a trailing line return charcter in the message does convert into blank line
72+
73+
if [[ -n "$GITHUB_ACTIONS" ]]; then
74+
for arg in "$@"; do
75+
gh_trim_trailing_line_return_chars "$arg"
76+
echo -n "$RETURN_VALUE" >&2 # without line return
77+
done
78+
else
79+
for arg in "$@"; do
80+
gh_trim_trailing_line_return_chars "$arg"
81+
echo "$RETURN_VALUE" >&2 # with line return
82+
done
83+
fi
84+
}

bash/github/utils.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# NOTE:
4+
# This is a composite script to use from a composite GitHub action.
5+
#
6+
7+
# Script both for execution and inclusion.
8+
[[ -z "$BASH" || (-n "$SOURCE_GHWF_UTILS_SH" && SOURCE_GHWF_UTILS_SH -ne 0) ]] && return
9+
10+
SOURCE_GHWF_UTILS_SH=1 # including guard
11+
12+
[[ -z "$GH_WORKFLOW_ROOT" ]] && {
13+
echo "$0: error: \`GH_WORKFLOW_ROOT\` variable must be defined." >&2
14+
exit 255
15+
}
16+
17+
source "$GH_WORKFLOW_ROOT/_externals/tacklelib/bash/tacklelib/bash_tacklelib" || exit $?
18+
19+
20+
function gh_trim_trailing_line_return_chars()
21+
{
22+
local str="$1"
23+
24+
while [[ "${str%[$'\r\n']}" != "$str" ]]; do
25+
str="${str%[$'\r\n']}"
26+
done
27+
28+
RETURN_VALUE="$str"
29+
}
30+
31+
tkl_set_return

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2022.08.10:
2+
* fixed: bash/github/print-*.sh: notices, warnings, errors functions fixup
3+
* fixed: bash/github/accum-rate-limits.sh: json format change fixup
4+
* changed: bash/github/accum-rate-limits.sh: changed rate limits json format change message from an error to a warning
5+
16
2022.08.09:
27
* new: bash/github/init-yq-workflow.sh: added `ENABLE_YAML_DIFF_PRINT_BEFORE_PATCH`, `ENABLE_YAML_PRINT_AFTER_PATCH` variables to print diff/yaml file before patch instead of after edit (has priority over `ENABLE_YAML_DIFF_PRINT_AFTER_EDIT`, `ENABLE_YAML_PRINT_AFTER_EDIT` variables)
38

userlog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
33
> :warning: to find all changes use [changelog.txt](https://github.com/andry81-devops/gh-workflow/blob/master/changelog.txt) file in a directory
44
5+
## 2022.08.10:
6+
* fixed: bash/github/print-*.sh: notices, warnings, errors functions fixup
7+
* fixed: bash/github/accum-rate-limits.sh: json format change fixup
8+
* changed: bash/github/accum-rate-limits.sh: changed rate limits json format change message from an error to a warning
9+
510
## 2022.08.09:
611
* new: bash/github/init-yq-workflow.sh: added `ENABLE_YAML_DIFF_PRINT_BEFORE_PATCH`, `ENABLE_YAML_PRINT_AFTER_PATCH` variables to print diff/yaml file before patch instead of after edit (has priority over `ENABLE_YAML_DIFF_PRINT_AFTER_EDIT`, `ENABLE_YAML_PRINT_AFTER_EDIT` variables)
712

0 commit comments

Comments
 (0)