Skip to content

Commit c30a564

Browse files
committed
[HUDI-7438] Fix Azure CI report check with new issue comments
1 parent 47d9631 commit c30a564

File tree

4 files changed

+329
-35
lines changed

4 files changed

+329
-35
lines changed

.github/workflows/azure_ci.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
async function checkAzureCiStatus({ github, context, prNumber, latestCommitHash }) {
21+
console.log(`- Checking Azure CI status of PR: ${prNumber} ${latestCommitHash}`);
22+
const botUsername = 'hudi-bot';
23+
24+
const comments = await github.rest.issues.listComments({
25+
owner: context.repo.owner,
26+
repo: context.repo.repo,
27+
issue_number: prNumber,
28+
});
29+
30+
// Find the latest comment from hudi-bot containing the Azure CI report
31+
const botComments = comments.data.filter(comment => comment.user.login === botUsername);
32+
const lastComment = botComments.pop();
33+
34+
let status = 'pending';
35+
let message = 'In progress';
36+
let azureRunLink = '';
37+
38+
if (lastComment) {
39+
const reportPrefix = `${latestCommitHash} Azure: `
40+
const successReportString = `${reportPrefix}[SUCCESS]`
41+
const failureReportString = `${reportPrefix}[FAILURE]`
42+
43+
if (lastComment.body.includes(reportPrefix)) {
44+
if (lastComment.body.includes(successReportString)) {
45+
message = 'Successful on the latest commit';
46+
status = 'success';
47+
} else if (lastComment.body.includes(failureReportString)) {
48+
message = 'Failed on the latest commit';
49+
status = 'failure';
50+
}
51+
}
52+
53+
const linkRegex = /\[[a-zA-Z]+\]\((https?:\/\/[^\s]+)\)/;
54+
const parts = lastComment.body.split(reportPrefix);
55+
const secondPart = parts.length > 1 ? parts[1] : '';
56+
const match = secondPart.match(linkRegex);
57+
58+
if (match) {
59+
azureRunLink = match[1];
60+
}
61+
}
62+
63+
console.log(`Status: ${status}`);
64+
console.log(`Azure Run Link: ${azureRunLink}`);
65+
console.log(`${message}`);
66+
67+
console.log(`- Create commit status of PR based on Azure CI status: ${prNumber} ${latestCommitHash}`);
68+
// Create or update the commit status for Azure CI
69+
await github.rest.repos.createCommitStatus({
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
sha: latestCommitHash,
73+
state: status,
74+
target_url: azureRunLink,
75+
description: message,
76+
context: 'Azure CI'
77+
});
78+
79+
return { status, message, azureRunLink };
80+
}
81+
82+
module.exports = checkAzureCiStatus;

.github/workflows/azure_ci_check.yml

Lines changed: 68 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,22 @@
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
statuses: write
2629
pull-requests: read
2730
issues: read
2831

2932
jobs:
3033
check-azure-ci-report:
31-
if: "!contains(github.event.pull_request.body, 'HOTFIX: SKIP AZURE CI')"
34+
if: true #|
35+
#github.event.issue.pull_request != null &&
36+
#!contains(github.event.pull_request.body, 'HOTFIX: SKIP AZURE CI')
3237
runs-on: ubuntu-latest
3338
steps:
3439
- name: Get last commit hash
@@ -37,13 +42,20 @@ jobs:
3742
with:
3843
github-token: ${{secrets.GITHUB_TOKEN}}
3944
script: |
40-
const pr = context.payload.pull_request;
41-
const lastCommitHash = pr.head.sha;
42-
console.log(`Last commit hash: ${lastCommitHash}`);
45+
const issueNumber = 10740; // github.event.issue.number;
46+
const { data: pullRequest } = await github.rest.pulls.get({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
pull_number: issueNumber
50+
});
51+
52+
const commitHash = pullRequest.head.sha;
53+
console.log(`Latest commit hash: ${commitHash}`);
4354
// Set the output variable to be used in subsequent step
44-
core.setOutput("last_commit_hash", lastCommitHash);
55+
core.setOutput("last_commit_hash", commitHash);
4556
4657
- name: Check Azure CI report in PR comment
58+
id: check_report_in_pr_comment
4759
uses: actions/github-script@v7
4860
with:
4961
github-token: ${{secrets.GITHUB_TOKEN}}
@@ -62,32 +74,69 @@ jobs:
6274
const botComments = comments.data.filter(comment => comment.user.login === botUsername);
6375
const lastComment = botComments.pop();
6476
77+
let message = '';
78+
let result = false;
79+
6580
if (lastComment) {
6681
const reportPrefix = '${lastCommitHash} Azure: '
6782
const successReportString = '${reportPrefix}[SUCCESS]'
6883
const failureReportString = '${reportPrefix}[FAILURE]'
6984
if (lastComment.body.includes(reportPrefix)) {
7085
if (lastComment.body.includes(successReportString)) {
71-
console.log(`Azure CI succeeded on the latest commit of the PR.`);
72-
return true;
86+
message = 'Azure CI succeeded on the latest commit of the PR.';
87+
result = true;
7388
} else if (lastComment.body.includes(failureReportString)) {
74-
console.log(`Azure CI failed on the latest commit of the PR.`);
75-
core.setFailed("Azure CI failed on the latest commit of the PR.");
76-
return false;
89+
message = 'Azure CI failed on the latest commit of the PR';
90+
result = false;
7791
} else {
78-
console.log(`Azure CI is in progress on the latest commit of the PR.`);
79-
core.setFailed("Azure CI is in progress on the latest commit of the PR.");
80-
return false;
92+
message = 'Azure CI is in progress on the latest commit of the PR.';
93+
result = false;
8194
}
8295
} else {
83-
console.log(`No Azure CI report on the latest commit of the PR.`);
84-
core.setFailed("No Azure CI report on the latest commit of the PR.");
85-
return false;
96+
message = 'No Azure CI report on the latest commit of the PR.';
97+
result = false;
8698
}
8799
} else {
88-
console.log(`Azure CI report does not seem to be ready yet.`);
89-
core.setFailed("Azure CI report does not seem to be ready yet.");
90-
return false;
100+
message = 'Azure CI report does not seem to be ready yet.';
101+
result = false;
91102
}
103+
console.log(`${message}`);
104+
core.setOutput("check_result_message", message);
105+
core.setOutput("is_check_successful", result);
92106
env:
93107
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
108+
109+
- name: Attach Azure CI report check to the PR
110+
uses: actions/github-script@v5
111+
with:
112+
github-token: ${{ secrets.GITHUB_TOKEN }}
113+
script: |
114+
let conclusionString = 'failure';
115+
if (${{ steps.check_report_in_pr_comment.outputs.is_check_successful }}) {
116+
conclusionString = 'success';
117+
}
118+
console.log(`Check status: ${conclusionString}`);
119+
await github.rest.checks.create({
120+
owner: context.repo.owner,
121+
repo: context.repo.repo,
122+
name: 'Azure CI Report Check',
123+
head_sha: '${{ steps.last_commit.outputs.last_commit_hash }}',
124+
status: 'completed',
125+
conclusion: '${conclusionString}',
126+
completed_at: new Date(),
127+
output: {
128+
title: 'Azure CI Report Check',
129+
summary: '${{ steps.check_report_in_pr_comment.outputs.check_result_message }}',
130+
}
131+
});
132+
133+
- name: Remove Azure CI Blocker check
134+
run: |
135+
curl -X GET \
136+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
137+
-H "Accept: application/vnd.github.v3+json" \
138+
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 \
139+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
140+
-H "Accept: application/vnd.github.v3+json" \
141+
-d '{"status": "neutral"}' \
142+
https://api.github.com/repos/${{ github.repository }}/check-runs/{}

.github/workflows/labeler.yml

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,54 @@
11
name: Label PR
22

3-
on: [ pull_request ]
3+
on:
4+
pull_request:
5+
types: [ opened, edited, reopened, synchronize ]
6+
7+
permissions:
8+
issues: write
9+
pull-requests: write
410

511
jobs:
612
labeler:
713
runs-on: ubuntu-latest
8-
name: Label the PR size
914
steps:
10-
- uses: codelytv/pr-size-labeler@v1
15+
- name: Label PR size
16+
uses: actions/github-script@v7
1117
with:
12-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13-
xs_label: 'size-xs'
14-
xs_max_size: '10'
15-
s_label: 'size-s'
16-
s_max_size: '100'
17-
m_label: 'size-m'
18-
m_max_size: '500'
19-
l_label: 'size-l'
20-
l_max_size: '1000'
21-
xl_label: 'size-xl'
22-
fail_if_xl: 'false'
23-
github_api_url: 'api.github.com'
24-
files_to_ignore: ''
18+
github-token: ${{secrets.GITHUB_TOKEN}}
19+
script: |
20+
const prNumber = context.payload.pull_request.number;
21+
const { data: prData } = await github.rest.pulls.get({
22+
owner: context.repo.owner,
23+
repo: context.repo.repo,
24+
pull_number: prNumber,
25+
});
26+
27+
const additions = prData.additions;
28+
const deletions = prData.deletions;
29+
const totalChanges = additions + deletions;
30+
31+
let label = "";
32+
33+
if (totalChanges < 10) {
34+
label = "size:XS";
35+
} else if (totalChanges < 100) {
36+
label = "size:S";
37+
} else if (totalChanges < 300) {
38+
label = "size:M";
39+
} else if (totalChanges < 1000) {
40+
label = "size:L";
41+
} else {
42+
label = "size:XL";
43+
}
44+
45+
// Apply the label
46+
await github.rest.issues.addLabels({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
issue_number: prNumber,
50+
labels: [label],
51+
});
52+
53+
console.log(`Total lines of changes: ${totalChanges}`);
54+
console.log(`Label: ${label}`);

0 commit comments

Comments
 (0)