diff --git a/.github/workflows/sample-check.yml b/.github/workflows/sample-check.yml new file mode 100644 index 0000000000..dd53fa1040 --- /dev/null +++ b/.github/workflows/sample-check.yml @@ -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 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 *")