From 83b3a98bd4307e61daa18c23105405f27aa8245c Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Fri, 7 Jun 2024 21:31:28 +0900 Subject: [PATCH 1/6] ci: catch renovate schema error --- .github/workflows/validate-renovate.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate-renovate.yml b/.github/workflows/validate-renovate.yml index 1ab091bd..b793ea44 100644 --- a/.github/workflows/validate-renovate.yml +++ b/.github/workflows/validate-renovate.yml @@ -28,12 +28,19 @@ jobs: echo "npx: $(npx --version)" echo "installing: $package..." export H="$(mktemp)" + se="$(mktemp)" echo '{' >> "$H" - # let's do main part, but avoid pipefail - (npx --yes --package "$package" -- renovate-config-validator --strict || true)\ + # let's do main part, but avoid pipefail for soft-error about migration + (npx --yes --package "$package" -- renovate-config-validator --strict 2>"$se" || true)\ | ruby -e 'File.open(ENV[?H], ?a) {|r| while gets; puts $_; $> = r if $_.strip == "WARN: Config migration necessary" ;end; }' echo '}' >> "$H" + cat "$se" >&2 + if [ "$(stat -c %s "$se")" -gt 0 ] && (echo "$se" | grep "ERROR"); then + gh pr comment -F "Error(s) has been occurred: $(cat "$se")" "${URL}" + exit 1 + fi + # exit early if migration is not required if [ "$(stat -c %s "$H")" -le 4 ]; then echo 'Migration is unnecessary, exiting (early)' From 2d0ddb60e0935a5ea7e388d929e926968cd0b611 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Fri, 7 Jun 2024 21:33:55 +0900 Subject: [PATCH 2/6] ci: redirect temporary file content to `grep` --- .github/workflows/validate-renovate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate-renovate.yml b/.github/workflows/validate-renovate.yml index b793ea44..983b0d1a 100644 --- a/.github/workflows/validate-renovate.yml +++ b/.github/workflows/validate-renovate.yml @@ -36,7 +36,7 @@ jobs: echo '}' >> "$H" cat "$se" >&2 - if [ "$(stat -c %s "$se")" -gt 0 ] && (echo "$se" | grep "ERROR"); then + if [ "$(stat -c %s "$se")" -gt 0 ] && (grep "ERROR" < "$se"); then gh pr comment -F "Error(s) has been occurred: $(cat "$se")" "${URL}" exit 1 fi From 6b1937695128d14d83c5e4a1bd047448a53c87ab Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Fri, 7 Jun 2024 22:08:12 +0900 Subject: [PATCH 3/6] ci: redirect temporary file content to `grep`, take 2 --- .github/workflows/validate-renovate.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/validate-renovate.yml b/.github/workflows/validate-renovate.yml index 983b0d1a..c58145a9 100644 --- a/.github/workflows/validate-renovate.yml +++ b/.github/workflows/validate-renovate.yml @@ -30,17 +30,20 @@ jobs: export H="$(mktemp)" se="$(mktemp)" echo '{' >> "$H" - # let's do main part, but avoid pipefail for soft-error about migration - (npx --yes --package "$package" -- renovate-config-validator --strict 2>"$se" || true)\ - | ruby -e 'File.open(ENV[?H], ?a) {|r| while gets; puts $_; $> = r if $_.strip == "WARN: Config migration necessary" ;end; }' - echo '}' >> "$H" - - cat "$se" >&2 - if [ "$(stat -c %s "$se")" -gt 0 ] && (grep "ERROR" < "$se"); then - gh pr comment -F "Error(s) has been occurred: $(cat "$se")" "${URL}" + js_output_temp="$(mktemp)" + npx --yes --package "$package" -- renovate-config-validator --strict >"$js_output_temp" || true + if grep -e "^ERROR: Found errors in configuration" "$js_output_temp"; then + # hard error + # TODO: collect this as JSON, and display it in more structured way + lf=$'\n' + gh pr comment -F "Error(s) has been occurred: ${lf}${js_output}" "${URL}" exit 1 fi + # let's do main part, but avoid pipefail for soft-error about migration + ruby -e 'File.open(ENV[?H], ?a) {|r| while gets; puts $_; $> = r if $_.strip == "WARN: Config migration necessary" ;end; }' <"$js_output_temp" + echo '}' >> "$H" + # exit early if migration is not required if [ "$(stat -c %s "$H")" -le 4 ]; then echo 'Migration is unnecessary, exiting (early)' From b4c43d28c50a5eb34efe751726bd36dd8dbabfdb Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Fri, 7 Jun 2024 22:11:22 +0900 Subject: [PATCH 4/6] ci: prepare buffer file correctly --- .github/workflows/validate-renovate.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/validate-renovate.yml b/.github/workflows/validate-renovate.yml index c58145a9..11083a53 100644 --- a/.github/workflows/validate-renovate.yml +++ b/.github/workflows/validate-renovate.yml @@ -36,7 +36,9 @@ jobs: # hard error # TODO: collect this as JSON, and display it in more structured way lf=$'\n' - gh pr comment -F "Error(s) has been occurred: ${lf}${js_output}" "${URL}" + comment_buffer="$(mktemp)" + echo "Error(s) has been occurred: ${lf}$(cat "$js_output_temp")" >"$comment_buffer" + gh pr comment -F "$comment_buffer" "${URL}" exit 1 fi From 62b797a7c9663f937f96dd50b6c7d2a6b3ea1b99 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Fri, 7 Jun 2024 22:13:50 +0900 Subject: [PATCH 5/6] =?UTF-8?q?ci:=20=E3=81=A1=E3=82=87=E3=81=A3=E3=81=A8?= =?UTF-8?q?=E3=81=BE=E3=81=A8=E3=82=82=E3=81=B6=E3=82=8B=20(=E3=81=93?= =?UTF-8?q?=E3=81=86=E3=81=97=E3=81=AA=E3=81=84=E3=81=A8=E8=A1=8C=E9=A0=AD?= =?UTF-8?q?=E3=81=AE=E3=82=B9=E3=83=9A=E3=83=BC=E3=82=B9=E3=81=8C=E5=89=8A?= =?UTF-8?q?=E3=82=8C=E3=82=8B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/validate-renovate.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/validate-renovate.yml b/.github/workflows/validate-renovate.yml index 11083a53..b0a99be4 100644 --- a/.github/workflows/validate-renovate.yml +++ b/.github/workflows/validate-renovate.yml @@ -37,7 +37,9 @@ jobs: # TODO: collect this as JSON, and display it in more structured way lf=$'\n' comment_buffer="$(mktemp)" + echo '```' >"$comment_buffer" echo "Error(s) has been occurred: ${lf}$(cat "$js_output_temp")" >"$comment_buffer" + echo '```' >"$comment_buffer" gh pr comment -F "$comment_buffer" "${URL}" exit 1 fi From a26ddd5bf6475cb9646bde40c9e09c4435f6f039 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Fri, 7 Jun 2024 22:18:00 +0900 Subject: [PATCH 6/6] ci: less complexity --- .github/workflows/validate-renovate.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/validate-renovate.yml b/.github/workflows/validate-renovate.yml index b0a99be4..be276455 100644 --- a/.github/workflows/validate-renovate.yml +++ b/.github/workflows/validate-renovate.yml @@ -36,11 +36,11 @@ jobs: # hard error # TODO: collect this as JSON, and display it in more structured way lf=$'\n' - comment_buffer="$(mktemp)" - echo '```' >"$comment_buffer" - echo "Error(s) has been occurred: ${lf}$(cat "$js_output_temp")" >"$comment_buffer" - echo '```' >"$comment_buffer" - gh pr comment -F "$comment_buffer" "${URL}" + { + echo '```' + echo "Error(s) has been occurred: ${lf}$(cat "$js_output_temp")" + echo '```' + } | gh pr comment -F - "${URL}" exit 1 fi