Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle Check Optimization #109

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/sample-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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
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({
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: |
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=${{ 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
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
Loading