From 25928547cbe1da50af58bc2d1edbec4b8282d511 Mon Sep 17 00:00:00 2001 From: Prudhvi Godithi Date: Mon, 20 May 2024 11:27:09 -0700 Subject: [PATCH 1/4] Gradle Check Optimization Signed-off-by: Prudhvi Godithi --- .github/workflows/sample-check.yml | 58 +++++++++++++++++++++++++ jenkins/gradle/gradle-check.jenkinsfile | 23 +++++++--- 2 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/sample-check.yml diff --git a/.github/workflows/sample-check.yml b/.github/workflows/sample-check.yml new file mode 100644 index 0000000000..430a68dde3 --- /dev/null +++ b/.github/workflows/sample-check.yml @@ -0,0 +1,58 @@ +name: Gradle Check (Jenkins) +on: + push: + branches-ignore: + - 'backport/**' + - 'create-pull-request/**' + - 'dependabot/**' + pull_request_target: + types: [opened, synchronize, reopened] + +permissions: + contents: read # to fetch code (actions/checkout) + +jobs: + gradle-check: + if: github.repository == 'prudhvigodithi/opensearch-build' + permissions: + contents: read # to fetch code (actions/checkout) + pull-requests: write # to create or update comment (peter-evans/create-or-update-comment) + issues: write # To create an issue if check fails on push. + + runs-on: ubuntu-latest + timeout-minutes: 130 + steps: + - name: Checkout OpenSearch repo + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Setup environment variables (PR) + if: github.event_name == 'pull_request_target' + run: | + echo "event_name=pull_request_target" >> $GITHUB_ENV + echo "branch_name=$(jq --raw-output .pull_request.base.ref $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + echo "pr_from_sha=$(jq --raw-output .pull_request.head.sha $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + echo "pr_from_clone_url=$(jq --raw-output .pull_request.head.repo.clone_url $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + echo "pr_to_clone_url=$(jq --raw-output .pull_request.base.repo.clone_url $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + echo "pr_title=$(jq --raw-output .pull_request.title $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + echo "pr_number=$(jq --raw-output .pull_request.number $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + echo "pr_owner=$(jq --raw-output .pull_request.user.login $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + echo "pr_or_commit_description=$(jq --ascii-output .pull_request.body $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + cat $GITHUB_ENV + - name: Setup environment variables (Push) + if: github.event_name == 'push' + run: | + repo_url="https://github.com/opensearch-project/OpenSearch" + ref_id=$(git rev-parse HEAD) + branch_name=$(git rev-parse --abbrev-ref HEAD) + echo "branch_name=$branch_name" >> $GITHUB_ENV + echo "event_name=push" >> $GITHUB_ENV + echo "pr_from_sha=$ref_id" >> $GITHUB_ENV + echo "pr_from_clone_url=$repo_url" >> $GITHUB_ENV + echo "pr_to_clone_url=$repo_url" >> $GITHUB_ENV + echo "pr_title=Push trigger $branch_name $ref_id $repo_url" >> $GITHUB_ENV + echo "pr_owner=$(jq --raw-output '.commits[0].author.username' $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + echo "pr_number=$(jq --raw-output .pull_request.number $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + echo "pr_or_commit_description=$(jq --ascii-output .head_commit.message $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + cat $GITHUB_ENV diff --git a/jenkins/gradle/gradle-check.jenkinsfile b/jenkins/gradle/gradle-check.jenkinsfile index 7a242ec6a1..e9ac03cb80 100644 --- a/jenkins/gradle/gradle-check.jenkinsfile +++ b/jenkins/gradle/gradle-check.jenkinsfile @@ -60,7 +60,8 @@ pipeline { [key: 'pr_from_clone_url', value: '$.pr_from_clone_url'], [key: 'pr_to_clone_url', value: '$.pr_to_clone_url'], [key: 'pr_title', value: '$.pr_title'], - [key: 'pr_number', value: '$.pr_number'] + [key: 'pr_number', value: '$.pr_number'], + [key: 'pr_owner', value: '$.pr_owner'] ], tokenCredentialId: 'jenkins-gradle-check-generic-webhook-token', causeString: 'Triggered by PR on OpenSearch core repository', @@ -150,26 +151,36 @@ pipeline { def invokedBy def pullRequest def pullRequestTitle + def pullRequestSha + def pullRequestOwner switch (true) { case env.BUILD_CAUSE.contains('Started by user'): invokedBy = 'User' - pullRequest = "${GIT_REFERENCE}" - pullRequestTitle = "Null" + pullRequest = "null" + pullRequestTitle = "null" + pullRequestSha = "${GIT_REFERENCE}" + pullRequestOwner = "null" break case env.BUILD_CAUSE.contains('Started by timer'): invokedBy = 'Timer' - pullRequest = "${GIT_REFERENCE}" - pullRequestTitle = "Null" + pullRequest = "null" + pullRequestTitle = "null" + pullRequestSha = "${GIT_REFERENCE}" + pullRequestOwner = "null" break case "${pr_number}" == "Null": invokedBy = 'Post Merge Action' - pullRequest = "${GIT_REFERENCE}" + pullRequest = "null" pullRequestTitle = "${pr_title}" + pullRequestSha = "${pr_from_sha}" + pullRequestOwner = "${pr_owner}" break default: invokedBy = 'Pull Request' pullRequest = "${pr_number}" pullRequestTitle = "${pr_title}" + pullRequestSha = "${pr_from_sha}" + pullRequestOwner = "${pr_owner}" } publishGradleCheckTestResults(prNumber: "${pullRequest}" , prDescription: "${pullRequestTitle}", invokeType: "${invokedBy}") sh("rm -rf *") From 8e6fd2a6d41460e29ff42817aaae3ce4912f84bd Mon Sep 17 00:00:00 2001 From: Prudhvi Godithi Date: Mon, 20 May 2024 11:30:05 -0700 Subject: [PATCH 2/4] Gradle Check Optimization Signed-off-by: Prudhvi Godithi --- .github/workflows/sample-check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/sample-check.yml b/.github/workflows/sample-check.yml index 430a68dde3..f8e5d82641 100644 --- a/.github/workflows/sample-check.yml +++ b/.github/workflows/sample-check.yml @@ -39,6 +39,7 @@ jobs: echo "pr_number=$(jq --raw-output .pull_request.number $GITHUB_EVENT_PATH)" >> $GITHUB_ENV echo "pr_owner=$(jq --raw-output .pull_request.user.login $GITHUB_EVENT_PATH)" >> $GITHUB_ENV echo "pr_or_commit_description=$(jq --ascii-output .pull_request.body $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + cat $GITHUB_ENV - name: Setup environment variables (Push) if: github.event_name == 'push' From 373a917e114e7b392e38933dabc456d778d6a71a Mon Sep 17 00:00:00 2001 From: Prudhvi Godithi Date: Mon, 20 May 2024 11:30:05 -0700 Subject: [PATCH 3/4] Gradle Check Optimization Signed-off-by: Prudhvi Godithi --- .github/workflows/sample-check.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sample-check.yml b/.github/workflows/sample-check.yml index 430a68dde3..bd1b535880 100644 --- a/.github/workflows/sample-check.yml +++ b/.github/workflows/sample-check.yml @@ -39,7 +39,20 @@ jobs: echo "pr_number=$(jq --raw-output .pull_request.number $GITHUB_EVENT_PATH)" >> $GITHUB_ENV echo "pr_owner=$(jq --raw-output .pull_request.user.login $GITHUB_EVENT_PATH)" >> $GITHUB_ENV echo "pr_or_commit_description=$(jq --ascii-output .pull_request.body $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + cat $GITHUB_ENV + - uses: actions/github-script@v7 + if: github.event_name == 'push' + id: get_pr_data + with: + script: | + return ( + await github.rest.repos.listPullRequestsAssociatedWithCommit({ + commit_sha: context.sha, + owner: context.repo.owner, + repo: context.repo.repo, + }) + ).data[0]; - name: Setup environment variables (Push) if: github.event_name == 'push' run: | @@ -53,6 +66,6 @@ jobs: echo "pr_to_clone_url=$repo_url" >> $GITHUB_ENV echo "pr_title=Push trigger $branch_name $ref_id $repo_url" >> $GITHUB_ENV echo "pr_owner=$(jq --raw-output '.commits[0].author.username' $GITHUB_EVENT_PATH)" >> $GITHUB_ENV - echo "pr_number=$(jq --raw-output .pull_request.number $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + echo 'pr_number=${{ fromJson(steps.get_pr_data.outputs.result).number }}' >> $GITHUB_ENV echo "pr_or_commit_description=$(jq --ascii-output .head_commit.message $GITHUB_EVENT_PATH)" >> $GITHUB_ENV cat $GITHUB_ENV From 5fde5b947381769f290fcda188da5fa01f1b4fe8 Mon Sep 17 00:00:00 2001 From: Prudhvi Godithi Date: Mon, 20 May 2024 11:59:59 -0700 Subject: [PATCH 4/4] Gradle Check Optimization Signed-off-by: Prudhvi Godithi --- .github/workflows/sample-check.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sample-check.yml b/.github/workflows/sample-check.yml index bd1b535880..dd53fa1040 100644 --- a/.github/workflows/sample-check.yml +++ b/.github/workflows/sample-check.yml @@ -39,12 +39,14 @@ jobs: echo "pr_number=$(jq --raw-output .pull_request.number $GITHUB_EVENT_PATH)" >> $GITHUB_ENV echo "pr_owner=$(jq --raw-output .pull_request.user.login $GITHUB_EVENT_PATH)" >> $GITHUB_ENV echo "pr_or_commit_description=$(jq --ascii-output .pull_request.body $GITHUB_EVENT_PATH)" >> $GITHUB_ENV - + echo 'post_merge_action=false' >> $GITHUB_ENV + cat $GITHUB_ENV - uses: actions/github-script@v7 if: github.event_name == 'push' id: get_pr_data with: + github-token: ${{secrets.GITHUB_TOKEN}} script: | return ( await github.rest.repos.listPullRequestsAssociatedWithCommit({ @@ -68,4 +70,5 @@ jobs: echo "pr_owner=$(jq --raw-output '.commits[0].author.username' $GITHUB_EVENT_PATH)" >> $GITHUB_ENV echo 'pr_number=${{ fromJson(steps.get_pr_data.outputs.result).number }}' >> $GITHUB_ENV echo "pr_or_commit_description=$(jq --ascii-output .head_commit.message $GITHUB_EVENT_PATH)" >> $GITHUB_ENV + echo 'post_merge_action=true' >> $GITHUB_ENV cat $GITHUB_ENV