Skip to content

Commit

Permalink
Gradle Check Optimization
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi committed May 20, 2024
1 parent 6da488d commit 2592854
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/sample-check.yml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 17 additions & 6 deletions jenkins/gradle/gradle-check.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 *")
Expand Down

0 comments on commit 2592854

Please sign in to comment.