You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2022/04/22 15:43:26 UTC

[pulsar-test-infra] branch master updated: [pulsarbot] Use gawk (gnu awk) so that CSV can be properly handled (#35)

This is an automated email from the ASF dual-hosted git repository.

lhotari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-test-infra.git


The following commit(s) were added to refs/heads/master by this push:
     new d00e88b  [pulsarbot] Use gawk (gnu awk) so that CSV can be properly handled (#35)
d00e88b is described below

commit d00e88ba40d83ad0c0abb5884e99453514bf61d8
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Fri Apr 22 18:43:21 2022 +0300

    [pulsarbot] Use gawk (gnu awk) so that CSV can be properly handled (#35)
    
    - previously a comma in the name caused a parsing issue
---
 pulsarbot/Dockerfile    |  4 ++--
 pulsarbot/entrypoint.sh | 18 ++++++++++++++++--
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/pulsarbot/Dockerfile b/pulsarbot/Dockerfile
index 3e59202..abe0473 100644
--- a/pulsarbot/Dockerfile
+++ b/pulsarbot/Dockerfile
@@ -9,7 +9,7 @@ LABEL "com.github.actions.description"="Pulsar Bot"
 LABEL "com.github.actions.icon"="git-commit"
 LABEL "com.github.actions.color"="gray-dark"
 
-RUN apk add --update git jq bash curl coreutils && rm -rf /var/cache/apk/*
+RUN apk add --update git jq bash curl coreutils gawk && rm -rf /var/cache/apk/*
 
 COPY entrypoint.sh /entrypoint.sh
-ENTRYPOINT ["/entrypoint.sh"]
\ No newline at end of file
+ENTRYPOINT ["/entrypoint.sh"]
diff --git a/pulsarbot/entrypoint.sh b/pulsarbot/entrypoint.sh
index 978d058..5186fc4 100755
--- a/pulsarbot/entrypoint.sh
+++ b/pulsarbot/entrypoint.sh
@@ -67,7 +67,16 @@ function get_runs() {
 
 # take the last attempt for each workflow to prevent restarting old runs
 function filter_oldruns() {
-    awk -F, '{ if (NR > 1 && LAST != null && LAST != $1) {print LASTLINE; print $0; LAST=null; LASTLINE=null} else { LAST = $1;LASTLINE = $0} } END { if (LASTLINE != null) { print LASTLINE } }'
+    awk '
+    BEGIN { FPAT="([^,]+)|(\"[^\"]+\")" }
+    { 
+        if (NR > 1 && LAST != null && LAST != $1) {
+            print LASTLINE; print $0; LAST=null; LASTLINE=null
+        } else {
+            LAST = $1;LASTLINE = $0
+        }
+    } 
+    END { if (LASTLINE != null) { print LASTLINE } }'
 }
 
 function get_all_runs() {
@@ -91,7 +100,12 @@ function get_all_runs() {
 # return url and name for failed or cancelled jobs that are the most recent ones for each workflow
 function find_failed_or_cancelled() {
     get_all_runs | filter_oldruns \
-      | awk -F, '{ gsub(/"/, ""); if ($3 == "failure" || $3 == "cancelled") { print $4 "\t" $5 "\t" $6 } }'
+      | awk '
+      BEGIN { FPAT="([^,]+)|(\"[^\"]+\")" } 
+      { 
+        gsub(/"/, "", $3); gsub(/"/, "", $4); gsub(/"/, "", $5); gsub(/"/, "", $6); 
+        if ($3 == "failure" || $3 == "cancelled") { print $4 "\t" $5 "\t" $6 }
+      }'
 }
 
 # allocate file descriptor for the failed or cancelled url and name listing