Skip to content

Commit 392c062

Browse files
committed
[HUDI-7438] Fix Azure CI report check with new issue comments
1 parent 6f74c7f commit 392c062

File tree

2 files changed

+107
-19
lines changed

2 files changed

+107
-19
lines changed

.github/workflows/azure_ci_check.yml

Lines changed: 68 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@
1818
name: Azure CI
1919

2020
on:
21+
pull_request:
22+
types: [ opened, edited, reopened, synchronize ]
2123
issue_comment:
2224
types: [ created, edited, deleted ]
2325

2426
permissions:
27+
checks: write
2528
pull-requests: read
2629
issues: read
2730

2831
jobs:
2932
check-azure-ci-report:
30-
if: "!contains(github.event.pull_request.body, 'HOTFIX: SKIP AZURE CI')"
33+
if: true #|
34+
#github.event.issue.pull_request != null &&
35+
#!contains(github.event.pull_request.body, 'HOTFIX: SKIP AZURE CI')
3136
runs-on: ubuntu-latest
3237
steps:
3338
- name: Get last commit hash
@@ -36,13 +41,20 @@ jobs:
3641
with:
3742
github-token: ${{secrets.GITHUB_TOKEN}}
3843
script: |
39-
const pr = context.payload.pull_request;
40-
const lastCommitHash = pr.head.sha;
41-
console.log(`Last commit hash: ${lastCommitHash}`);
44+
const issueNumber = 10740; // github.event.issue.number;
45+
const { data: pullRequest } = await github.rest.pulls.get({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
pull_number: issueNumber
49+
});
50+
51+
const commitHash = pullRequest.head.sha;
52+
console.log(`Latest commit hash: ${commitHash}`);
4253
// Set the output variable to be used in subsequent step
43-
core.setOutput("last_commit_hash", lastCommitHash);
54+
core.setOutput("last_commit_hash", commitHash);
4455
4556
- name: Check Azure CI report in PR comment
57+
id: check_report_in_pr_comment
4658
uses: actions/github-script@v7
4759
with:
4860
github-token: ${{secrets.GITHUB_TOKEN}}
@@ -61,32 +73,69 @@ jobs:
6173
const botComments = comments.data.filter(comment => comment.user.login === botUsername);
6274
const lastComment = botComments.pop();
6375
76+
let message = '';
77+
let result = false;
78+
6479
if (lastComment) {
6580
const reportPrefix = '${lastCommitHash} Azure: '
6681
const successReportString = '${reportPrefix}[SUCCESS]'
6782
const failureReportString = '${reportPrefix}[FAILURE]'
6883
if (lastComment.body.includes(reportPrefix)) {
6984
if (lastComment.body.includes(successReportString)) {
70-
console.log(`Azure CI succeeded on the latest commit of the PR.`);
71-
return true;
85+
message = 'Azure CI succeeded on the latest commit of the PR.';
86+
result = true;
7287
} else if (lastComment.body.includes(failureReportString)) {
73-
console.log(`Azure CI failed on the latest commit of the PR.`);
74-
core.setFailed("Azure CI failed on the latest commit of the PR.");
75-
return false;
88+
message = 'Azure CI failed on the latest commit of the PR';
89+
result = false;
7690
} else {
77-
console.log(`Azure CI is in progress on the latest commit of the PR.`);
78-
core.setFailed("Azure CI is in progress on the latest commit of the PR.");
79-
return false;
91+
message = 'Azure CI is in progress on the latest commit of the PR.';
92+
result = false;
8093
}
8194
} else {
82-
console.log(`No Azure CI report on the latest commit of the PR.`);
83-
core.setFailed("No Azure CI report on the latest commit of the PR.");
84-
return false;
95+
message = 'No Azure CI report on the latest commit of the PR.';
96+
result = false;
8597
}
8698
} else {
87-
console.log(`Azure CI report does not seem to be ready yet.`);
88-
core.setFailed("Azure CI report does not seem to be ready yet.");
89-
return false;
99+
message = 'Azure CI report does not seem to be ready yet.';
100+
result = false;
90101
}
102+
console.log(`${message}`);
103+
core.setOutput("check_result_message", message);
104+
core.setOutput("is_check_successful", result);
91105
env:
92106
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
107+
108+
- name: Attach Azure CI report check to the PR
109+
uses: actions/github-script@v5
110+
with:
111+
github-token: ${{ secrets.GITHUB_TOKEN }}
112+
script: |
113+
let conclusionString = 'failure';
114+
if (${{ steps.check_report_in_pr_comment.outputs.is_check_successful }}) {
115+
conclusionString = 'success';
116+
}
117+
console.log(`Check status: ${conclusionString}`);
118+
await github.rest.checks.create({
119+
owner: context.repo.owner,
120+
repo: context.repo.repo,
121+
name: 'Azure CI Report Check',
122+
head_sha: '${{ steps.last_commit.outputs.last_commit_hash }}',
123+
status: 'completed',
124+
conclusion: '${conclusionString}',
125+
completed_at: new Date(),
126+
output: {
127+
title: 'Azure CI Report Check',
128+
summary: '${{ steps.check_report_in_pr_comment.outputs.check_result_message }}',
129+
}
130+
});
131+
132+
- name: Remove Azure CI Blocker check
133+
run: |
134+
curl -X GET \
135+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
136+
-H "Accept: application/vnd.github.v3+json" \
137+
https://api.github.com/repos/${{ github.repository }}/commits/${{ steps.last_commit.outputs.last_commit_hash }}/check-runs | jq '.check_runs[] | select(.name | contains("create-azure-ci-report-check")) | .id' | xargs -I {} curl -X PATCH \
138+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
139+
-H "Accept: application/vnd.github.v3+json" \
140+
-d '{"status": "neutral"}' \
141+
https://api.github.com/repos/${{ github.repository }}/check-runs/{}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: Azure CI Blocker
19+
20+
on:
21+
pull_request:
22+
types: [ opened, edited, reopened, synchronize ]
23+
24+
permissions:
25+
pull-requests: read
26+
issues: read
27+
28+
jobs:
29+
create-azure-ci-report-check:
30+
if: "!contains(github.event.pull_request.body, 'HOTFIX: SKIP AZURE CI')"
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Create a placeholder check for Azure CI report
34+
uses: actions/github-script@v7
35+
with:
36+
github-token: ${{secrets.GITHUB_TOKEN}}
37+
script: |
38+
core.setFailed("Please wait for the Azure CI report on the latest commit of the PR.");
39+
return false;

0 commit comments

Comments
 (0)