8
8
pull_request_target :
9
9
types : [opened, synchronize, reopened]
10
10
11
+ permissions :
12
+ contents : read # to fetch code (actions/checkout)
13
+
11
14
jobs :
12
15
gradle-check :
16
+ if : github.repository == 'opensearch-project/OpenSearch'
17
+ permissions :
18
+ contents : read # to fetch code (actions/checkout)
19
+ pull-requests : write # to create or update comment (peter-evans/create-or-update-comment)
20
+ issues : write # To create an issue if check fails on push.
21
+
13
22
runs-on : ubuntu-latest
14
23
timeout-minutes : 130
15
24
steps :
16
25
- name : Checkout OpenSearch repo
17
- uses : actions/checkout@v2
26
+ uses : actions/checkout@v4
18
27
with :
19
28
ref : ${{ github.event.pull_request.head.sha }}
20
29
21
30
- name : Setup environment variables (PR)
22
31
if : github.event_name == 'pull_request_target'
23
32
run : |
24
- echo "pr_from_sha=$(jq --raw-output .pull_request.head.sha $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
25
- echo "pr_from_clone_url=$(jq --raw-output .pull_request.head.repo.clone_url $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
26
- echo "pr_to_clone_url=$(jq --raw-output .pull_request.base.repo.clone_url $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
27
- echo "pr_title=$(jq --raw-output .pull_request.title $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
28
- echo "pr_number=$(jq --raw-output .pull_request.number $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
33
+ echo "event_name=pull_request_target" >> $GITHUB_ENV
34
+ echo "branch_name=$(jq --raw-output .pull_request.base.ref $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
35
+ echo "pr_from_sha=$(jq --raw-output .pull_request.head.sha $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
36
+ echo "pr_from_clone_url=$(jq --raw-output .pull_request.head.repo.clone_url $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
37
+ echo "pr_to_clone_url=$(jq --raw-output .pull_request.base.repo.clone_url $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
38
+ echo "pr_title=$(jq --raw-output .pull_request.title $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
39
+ echo "pr_number=$(jq --raw-output .pull_request.number $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
40
+ echo "pr_owner=$(jq --raw-output .pull_request.user.login $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
41
+ echo "pr_or_commit_description=$(jq --ascii-output .pull_request.body $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
42
+ echo "post_merge_action=false" >> $GITHUB_ENV
43
+
44
+ # to get the PR data that can be used for post merge actions
45
+ - uses : actions/github-script@v7
46
+ if : github.event_name == 'push'
47
+ id : get_pr_data
48
+ with :
49
+ github-token : ${{secrets.GITHUB_TOKEN}}
50
+ script : |
51
+ return (
52
+ await github.rest.repos.listPullRequestsAssociatedWithCommit({
53
+ commit_sha: context.sha,
54
+ owner: context.repo.owner,
55
+ repo: context.repo.repo,
56
+ })
57
+ ).data[0];
29
58
30
59
- name : Setup environment variables (Push)
31
60
if : github.event_name == 'push'
32
61
run : |
33
- repo_url="https://github.com/opensearch-project/OpenSearch"
34
- ref_id=$(git rev-parse HEAD)
35
- branch_name=$(git rev-parse --abbrev-ref HEAD)
36
- echo "pr_from_sha=$ref_id" >> $GITHUB_ENV
37
- echo "pr_from_clone_url=$repo_url" >> $GITHUB_ENV
38
- echo "pr_to_clone_url=$repo_url" >> $GITHUB_ENV
39
- echo "pr_title=Push trigger $branch_name $ref_id $repo_url" >> $GITHUB_ENV
40
- echo "pr_number=Null" >> $GITHUB_ENV
62
+ repo_url="https://github.com/opensearch-project/OpenSearch"
63
+ ref_id=$(git rev-parse HEAD)
64
+ branch_name=$(git rev-parse --abbrev-ref HEAD)
65
+ echo "branch_name=$branch_name" >> $GITHUB_ENV
66
+ echo "event_name=push" >> $GITHUB_ENV
67
+ echo "pr_from_sha=$ref_id" >> $GITHUB_ENV
68
+ echo "pr_from_clone_url=$repo_url" >> $GITHUB_ENV
69
+ echo "pr_to_clone_url=$repo_url" >> $GITHUB_ENV
70
+ echo "pr_title=Push trigger $branch_name $ref_id $repo_url" >> $GITHUB_ENV
71
+ echo "pr_owner=$(jq --raw-output '.commits[0].author.username' $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
72
+ echo 'pr_number=${{ fromJson(steps.get_pr_data.outputs.result).number }}' >> $GITHUB_ENV
73
+ echo "pr_or_commit_description=$(jq --ascii-output .head_commit.message $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
74
+ echo "post_merge_action=true" >> $GITHUB_ENV
41
75
42
76
- name : Checkout opensearch-build repo
43
- uses : actions/checkout@v2
77
+ uses : actions/checkout@v4
44
78
with :
45
79
repository : opensearch-project/opensearch-build
46
80
ref : main
@@ -62,28 +96,58 @@ jobs:
62
96
63
97
- name : Upload Coverage Report
64
98
if : success()
65
- uses : codecov/codecov-action@v2
99
+ uses : codecov/codecov-action@v4
66
100
with :
67
101
files : ./codeCoverage.xml
68
102
69
103
- name : Create Comment Success
70
- if : ${{ github.event_name == 'pull_request_target' && success() }}
71
- uses : peter-evans/create-or-update-comment@v2
104
+ if : ${{ github.event_name == 'pull_request_target' && success() && env.result == 'SUCCESS' }}
105
+ uses : peter-evans/create-or-update-comment@v4
72
106
with :
73
107
issue-number : ${{ env.pr_number }}
74
108
body : |
75
- ### Gradle Check (Jenkins) Run Completed with:
76
- * **RESULT:** ${{ env.result }} :white_check_mark:
77
- * **URL:** ${{ env.workflow_url }}
78
- * **CommitID:** ${{ env.pr_from_sha }}
109
+ :white_check_mark: Gradle check result for ${{ env.pr_from_sha }}: [${{ env.result }}](${{ env.workflow_url }})
110
+
111
+ - name : Extract Test Failure
112
+ if : ${{ github.event_name == 'pull_request_target' && env.result != 'SUCCESS' }}
113
+ run : |
114
+ TEST_FAILURES=`curl -s "${{ env.workflow_url }}/testReport/api/json?tree=suites\[cases\[status,className,name\]\]" | jq -r '.. | objects | select(.status=="FAILED",.status=="REGRESSION") | (.className + "." + .name)' | uniq -c | sort -n -r | head -n 10`
115
+ if [[ "$TEST_FAILURES" != "" ]]
116
+ then
117
+ echo "test_failures<<EOF" >> $GITHUB_ENV
118
+ echo "" >> $GITHUB_ENV
119
+ echo "* **TEST FAILURES:**" >> $GITHUB_ENV
120
+ echo '```' >> $GITHUB_ENV
121
+ echo "$TEST_FAILURES" >> $GITHUB_ENV
122
+ echo '```' >> $GITHUB_ENV
123
+ echo "EOF" >> $GITHUB_ENV
124
+ fi
125
+
126
+ - name : Create Comment Flaky
127
+ if : ${{ github.event_name == 'pull_request_target' && success() && env.result != 'SUCCESS' }}
128
+ uses : peter-evans/create-or-update-comment@v4
129
+ with :
130
+ issue-number : ${{ env.pr_number }}
131
+ body : |
132
+ :grey_exclamation: Gradle check result for ${{ env.pr_from_sha }}: [${{ env.result }}](${{ env.workflow_url }}) ${{ env.test_failures }}
133
+
134
+ Please review all [flaky tests](https://github.com/opensearch-project/OpenSearch/blob/1.x/DEVELOPER_GUIDE.md#flaky-tests) that succeeded after retry and create an issue if one does not already exist to track the flaky failure.
79
135
80
136
- name : Create Comment Failure
81
137
if : ${{ github.event_name == 'pull_request_target' && failure() }}
82
- uses : peter-evans/create-or-update-comment@v2
138
+ uses : peter-evans/create-or-update-comment@v4
83
139
with :
84
140
issue-number : ${{ env.pr_number }}
85
141
body : |
86
- ### Gradle Check (Jenkins) Run Completed with:
87
- * **RESULT:** ${{ env.result }} :x:
88
- * **URL:** ${{ env.workflow_url }}
89
- * **CommitID:** ${{ env.pr_from_sha }}
142
+ :x: Gradle check result for ${{ env.pr_from_sha }}: [${{ env.result }}](${{ env.workflow_url }})
143
+
144
+ Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure [a flaky test](https://github.com/opensearch-project/OpenSearch/blob/1.x/DEVELOPER_GUIDE.md#flaky-tests) unrelated to your change?
145
+
146
+ - name : Create Issue On Push Failure
147
+ if : ${{ github.event_name == 'push' && failure() }}
148
+ uses : dblock/create-a-github-issue@v3
149
+ env :
150
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
151
+ with :
152
+ assignees : ${{ github.event.head_commit.author.username }}, ${{ github.triggering_actor }}
153
+ filename : .github/ISSUE_TEMPLATE/failed_check.md
0 commit comments