You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/04/05 15:01:10 UTC

[camel] branch main updated: (chores) ci: rework the result comment script to avoid potentially unsafe practices

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

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 1e64de78999 (chores) ci: rework the result comment script to avoid potentially unsafe practices
1e64de78999 is described below

commit 1e64de78999396bc0b8603470df12440f126c1bb
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Apr 5 17:00:53 2022 +0200

    (chores) ci: rework the result comment script to avoid potentially unsafe practices
---
 .github/actions/quick-test/quick-test.sh | 15 +++++++-------
 .github/workflows/component-pr.yaml      | 35 ++++++++++++++++++++++++--------
 2 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/.github/actions/quick-test/quick-test.sh b/.github/actions/quick-test/quick-test.sh
index 6cb757177b6..795b9491ee6 100755
--- a/.github/actions/quick-test/quick-test.sh
+++ b/.github/actions/quick-test/quick-test.sh
@@ -92,12 +92,15 @@ function main() {
   local components=$(git diff "${startCommit}^..${endCommit}" --name-only --pretty=format:"" | grep -e '^components' | grep -v -e '^$' | cut -d / -f 1-2 | uniq | sort)
   local total=$(echo "${components}" | grep -v -e '^$' | wc -l)
 
+  echo "${total}" > "${logDir}/total"
   if [[ ${total} -eq 0 ]]; then
-    echo "result=:no_entry_sign: There are (likely) no components to be tested in this PR" > "${logDir}/results.txt"
+    echo "0" > "${logDir}/tested"
+    echo "0" > "${logDir}/failures"
     exit 0
   else
     if [[ ${total} -gt 10 ]]; then
-      echo "result=:no_entry_sign: There are too many components to be tested in this PR, components were removed or the code needs a rebase: (${total} likely to be tested)"  > "${logDir}/results.txt"
+      echo "0" > "${logDir}/tested"
+      echo "0" > "${logDir}/failures"
       exit 0
     fi
   fi
@@ -111,13 +114,9 @@ function main() {
     componentTest "${component}" "${total}" "${current}"
   done
 
+  echo "${total}" > "${logDir}/tested"
+  echo "${failures}" > "${logDir}/failures"
   # This is the comment that is displayed on the PR
-  if [[ ${failures} -eq 0 ]]; then
-    echo "result=:heavy_check_mark: Finished component verification: ${failures} component(s) test failed out of **${total} component(s) tested**" > "${logDir}/results.txt"
-  else
-    echo "result=:x: Finished component verification: **${failures} component(s) test failed** out of ${total} component(s) tested" > "${logDir}/results.txt"
-  fi
-
   exit "${failures}"
 }
 
diff --git a/.github/workflows/component-pr.yaml b/.github/workflows/component-pr.yaml
index 13ff465ea79..054bd27482b 100644
--- a/.github/workflows/component-pr.yaml
+++ b/.github/workflows/component-pr.yaml
@@ -76,11 +76,6 @@ jobs:
       - run: unzip test-logs.zip
         if: |
           github.event_name == 'workflow_run'
-      - name: Get the test result
-        if: |
-          github.event_name == 'workflow_run'
-        run: |
-          cat results.txt >> $GITHUB_ENV
       - uses: actions/github-script@v6
         if: |
           github.event_name == 'workflow_run'
@@ -89,9 +84,31 @@ jobs:
           script: |
             let fs = require('fs');
             let issue_number = Number(fs.readFileSync('./pr_number'));
+            let total = Number(fs.readFileSync('./total'));
+            let tested = Number(fs.readFileSync('./tested'));
+            let failures = Number(fs.readFileSync('./failures'));
+
+            var message = ""
+
+            if (tested === 0) {
+              if (total === 0) {
+                message = ":no_entry_sign: There are (likely) no components to be tested in this PR"
+              } else {
+                if (total > 10) {
+                  message = `There are too many components to be tested in this PR, components were removed or the code needs a rebase: (${total} likely to be tested)`
+                }
+              }
+            } else {
+              if (failures === 0) {
+                message = `:heavy_check_mark: Finished component verification: ${failures} component(s) test failed out of **${tested} component(s) tested**`
+              } else {
+                message = `:x: Finished component verification: **${failures} component(s) test failed** out of ${tested} component(s) tested`
+              }
+            }
+
             await github.rest.issues.createComment({
-              owner: context.repo.owner,
-              repo: context.repo.repo,
-              issue_number: issue_number,
-              body: "${{ env.result }}"
+                  owner: context.repo.owner,
+                  repo: context.repo.repo,
+                  issue_number: issue_number,
+                  body: message
             });