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/09/19 21:30:23 UTC

[pulsar] branch master updated: [fix][CI] Fix issues with approval solution for GitHub Actions (#17723)

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.git


The following commit(s) were added to refs/heads/master by this push:
     new 9f9922af0a0 [fix][CI] Fix issues with approval solution for GitHub Actions (#17723)
9f9922af0a0 is described below

commit 9f9922af0a08736efabf52dde3de4d12f2ead5e9
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Tue Sep 20 00:30:11 2022 +0300

    [fix][CI] Fix issues with approval solution for GitHub Actions (#17723)
    
    - The approval solution doesn't work as expected by approving the PR
      or by adding the ready-to-test label and adding a comment
      "/pulsarbot rerun-failure-checks".
    
    - Fix the ready-to-test label check:
      - Refresh PR labels when re-running workflow
        - when re-running, the event JSON remains the same. The API
          must be used to fetch the up-to-date JSON for the PR.
    
    - Fix the PR approval check:
      - set GITHUB_TOKEN for script so that retrieving the approval status could work
---
 .github/workflows/ci-cpp-build.yaml    |  3 +++
 .github/workflows/ci-go-functions.yaml |  3 +++
 .github/workflows/pulsar-ci-flaky.yaml |  3 +++
 .github/workflows/pulsar-ci.yaml       |  3 +++
 build/pulsar_ci_tool.sh                | 17 +++++++++++++++--
 5 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/ci-cpp-build.yaml b/.github/workflows/ci-cpp-build.yaml
index d7d6032e600..7a450efe972 100644
--- a/.github/workflows/ci-cpp-build.yaml
+++ b/.github/workflows/ci-cpp-build.yaml
@@ -56,6 +56,9 @@ jobs:
 
       - name: Check if the PR has been approved for testing
         if: ${{ steps.check_changes.outputs.docs_only != 'true' && github.repository == 'apache/pulsar' && github.event_name == 'pull_request' }}
+        env:
+          GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }}
+          GITHUB_TOKEN: ${{ github.token }}
         run: |
           build/pulsar_ci_tool.sh check_ready_to_test
 
diff --git a/.github/workflows/ci-go-functions.yaml b/.github/workflows/ci-go-functions.yaml
index 4b8b4e12947..266bfd57723 100644
--- a/.github/workflows/ci-go-functions.yaml
+++ b/.github/workflows/ci-go-functions.yaml
@@ -60,6 +60,9 @@ jobs:
 
       - name: Check if the PR has been approved for testing
         if: ${{ steps.check_changes.outputs.docs_only != 'true' && github.repository == 'apache/pulsar' && github.event_name == 'pull_request' }}
+        env:
+          GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }}
+          GITHUB_TOKEN: ${{ github.token }}
         run: |
           build/pulsar_ci_tool.sh check_ready_to_test
 
diff --git a/.github/workflows/pulsar-ci-flaky.yaml b/.github/workflows/pulsar-ci-flaky.yaml
index e9150bf391d..03e3adff33a 100644
--- a/.github/workflows/pulsar-ci-flaky.yaml
+++ b/.github/workflows/pulsar-ci-flaky.yaml
@@ -62,6 +62,9 @@ jobs:
 
       - name: Check if the PR has been approved for testing
         if: ${{ steps.check_changes.outputs.docs_only != 'true' && github.repository == 'apache/pulsar' && github.event_name == 'pull_request' }}
+        env:
+          GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }}
+          GITHUB_TOKEN: ${{ github.token }}
         run: |
           build/pulsar_ci_tool.sh check_ready_to_test
 
diff --git a/.github/workflows/pulsar-ci.yaml b/.github/workflows/pulsar-ci.yaml
index 74f93003f8b..56018eab2fd 100644
--- a/.github/workflows/pulsar-ci.yaml
+++ b/.github/workflows/pulsar-ci.yaml
@@ -62,6 +62,9 @@ jobs:
 
       - name: Check if the PR has been approved for testing
         if: ${{ steps.check_changes.outputs.docs_only != 'true' && github.repository == 'apache/pulsar' && github.event_name == 'pull_request' }}
+        env:
+          GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }}
+          GITHUB_TOKEN: ${{ github.token }}
         run: |
           build/pulsar_ci_tool.sh check_ready_to_test
 
diff --git a/build/pulsar_ci_tool.sh b/build/pulsar_ci_tool.sh
index 512163bfbf3..37daeffeae3 100755
--- a/build/pulsar_ci_tool.sh
+++ b/build/pulsar_ci_tool.sh
@@ -159,9 +159,22 @@ function ci_check_ready_to_test() {
     >&2 echo "GITHUB_EVENT_PATH isn't set"
     return 1
   fi
+
+  PR_JSON=$(jq '.pull_request' "${GITHUB_EVENT_PATH}")
+
+  # when re-running, the event doesn't get updated, fetch the PR JSON
+  if [[ $GITHUB_RUN_ATTEMPT -gt 1 ]]; then
+    PR_JSON_URL=$(jq -r '.pull_request.url' "${GITHUB_EVENT_PATH}")
+    echo "Refreshing $PR_JSON_URL..."
+    PR_JSON=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" "${PR_JSON_URL}")
+  fi
+
   # check ready-to-test label
-  if jq -e '.pull_request.labels[] | .name | select(. == "ready-to-test")' "$GITHUB_EVENT_PATH" &> /dev/null; then
+  if printf "%s" "${PR_JSON}" | jq -e '.labels[] | .name | select(. == "ready-to-test")' &> /dev/null; then
+    echo "Found ready-to-test label."
     return 0
+  else
+    echo "There is no ready-to-test label on the PR."
   fi
 
   # check if the PR has been approved
@@ -179,7 +192,7 @@ function ci_check_ready_to_test() {
   FORK_REPO_URL=$(jq -r '.pull_request.head.repo.html_url' "$GITHUB_EVENT_PATH")
   PR_BRANCH_LABEL=$(jq -r '.pull_request.head.label' "$GITHUB_EVENT_PATH")
   PR_URL=$(jq -r '.pull_request.html_url' "$GITHUB_EVENT_PATH")
-  FORK_PR_TITLE_URL_ENCODED=$(jq -r '"[run-tests] " + .pull_request.title | @uri' "$GITHUB_EVENT_PATH")
+  FORK_PR_TITLE_URL_ENCODED=$(printf "%s" "${PR_JSON}" | jq -r '"[run-tests] " + .title | @uri')
   FORK_PR_BODY_URL_ENCODED=$(jq -n -r "\"This PR is for running tests for upstream PR ${PR_URL}.\n\n<!-- Before creating this PR, please ensure that the fork $FORK_REPO_URL is up to date with https://github.com/apache/pulsar -->\" | @uri")
   >&2 tee -a "$GITHUB_STEP_SUMMARY" <<EOF