-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HUDI-7438] Fix Azure CI report check with new issue comments
- Loading branch information
Showing
4 changed files
with
246 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
async function checkAzureCiAndCreateCommitStatus({ github, context, prNumber, latestCommitHash }) { | ||
console.log(`- Checking Azure CI status of PR: ${prNumber} ${latestCommitHash}`); | ||
const botUsername = 'hudi-bot'; | ||
|
||
const comments = await github.rest.issues.listComments({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: prNumber, | ||
}); | ||
|
||
// Find the latest comment from hudi-bot containing the Azure CI report | ||
const botComments = comments.data.filter(comment => comment.user.login === botUsername); | ||
const lastComment = botComments.pop(); | ||
|
||
let status = 'pending'; | ||
let message = 'In progress'; | ||
let azureRunLink = ''; | ||
|
||
if (lastComment) { | ||
const reportPrefix = `${latestCommitHash} Azure: ` | ||
const successReportString = `${reportPrefix}[SUCCESS]` | ||
const failureReportString = `${reportPrefix}[FAILURE]` | ||
|
||
if (lastComment.body.includes(reportPrefix)) { | ||
if (lastComment.body.includes(successReportString)) { | ||
message = 'Successful on the latest commit'; | ||
status = 'success'; | ||
} else if (lastComment.body.includes(failureReportString)) { | ||
message = 'Failed on the latest commit'; | ||
status = 'failure'; | ||
} | ||
} | ||
|
||
const linkRegex = /\[[a-zA-Z]+\]\((https?:\/\/[^\s]+)\)/; | ||
const parts = lastComment.body.split(reportPrefix); | ||
const secondPart = parts.length > 1 ? parts[1] : ''; | ||
const match = secondPart.match(linkRegex); | ||
|
||
if (match) { | ||
azureRunLink = match[1]; | ||
} | ||
} | ||
|
||
console.log(`Status: ${status}`); | ||
console.log(`Azure Run Link: ${azureRunLink}`); | ||
console.log(`${message}`); | ||
|
||
console.log(`- Create commit status of PR based on Azure CI status: ${prNumber} ${latestCommitHash}`); | ||
// Create or update the commit status for Azure CI | ||
await github.rest.repos.createCommitStatus({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
sha: latestCommitHash, | ||
state: status, | ||
target_url: azureRunLink, | ||
description: message, | ||
context: 'Azure CI' | ||
}); | ||
|
||
return { status, message, azureRunLink }; | ||
} | ||
|
||
module.exports = checkAzureCiAndCreateCommitStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,54 @@ | ||
name: Label PR | ||
|
||
on: [ pull_request ] | ||
on: | ||
pull_request: | ||
types: [ opened, edited, reopened, synchronize ] | ||
|
||
permissions: | ||
issues: write | ||
pull-requests: write | ||
|
||
jobs: | ||
labeler: | ||
runs-on: ubuntu-latest | ||
name: Label the PR size | ||
steps: | ||
- uses: codelytv/pr-size-labeler@v1 | ||
- name: Label PR size | ||
uses: actions/github-script@v7 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
xs_label: 'size-xs' | ||
xs_max_size: '10' | ||
s_label: 'size-s' | ||
s_max_size: '100' | ||
m_label: 'size-m' | ||
m_max_size: '500' | ||
l_label: 'size-l' | ||
l_max_size: '1000' | ||
xl_label: 'size-xl' | ||
fail_if_xl: 'false' | ||
github_api_url: 'api.github.com' | ||
files_to_ignore: '' | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const prNumber = context.payload.pull_request.number; | ||
const { data: prData } = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: prNumber, | ||
}); | ||
const additions = prData.additions; | ||
const deletions = prData.deletions; | ||
const totalChanges = additions + deletions; | ||
let label = ""; | ||
if (totalChanges < 10) { | ||
label = "size:XS"; | ||
} else if (totalChanges < 100) { | ||
label = "size:S"; | ||
} else if (totalChanges < 300) { | ||
label = "size:M"; | ||
} else if (totalChanges < 1000) { | ||
label = "size:L"; | ||
} else { | ||
label = "size:XL"; | ||
} | ||
// Apply the label | ||
await github.rest.issues.addLabels({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: prNumber, | ||
labels: [label], | ||
}); | ||
console.log(`Total lines of changes: ${totalChanges}`); | ||
console.log(`Label: ${label}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
name: Scheduled Workflow | ||
|
||
on: | ||
schedule: | ||
# Runs every 5 minutes | ||
- cron: '*/5 * * * *' | ||
pull_request: | ||
types: [ opened, edited, reopened, synchronize ] | ||
|
||
permissions: | ||
statuses: write | ||
pull-requests: read | ||
issues: read | ||
|
||
jobs: | ||
process-new-and-updated-prs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Process new and updated PRs | ||
# We have to run any actions that require write permissions here | ||
# since the workflow triggered by events from a PR in a fork | ||
# (not apache/hudi but other_owner/hudi) does not run on a | ||
# GITHUB_TOKEN with write permissions (this is prohibited by | ||
# Apache). | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const since = new Date(new Date().getTime() - (60 * 60 * 1000)).toISOString(); | ||
const query = `repo:${context.repo.owner}/${context.repo.repo} type:pr updated:>=${since}`; | ||
const response = await github.rest.search.issuesAndPullRequests({ | ||
q: query | ||
}); | ||
// Filter for open PRs | ||
const openPrs = response.data.items.filter(pr => pr.state === 'open'); | ||
const checkAzureCiAndCreateCommitStatus = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/azure_ci.js`); | ||
for (const pr of openPrs) { | ||
console.log(`*** Processing PR: ${pr.title}, URL: ${pr.html_url}`); | ||
if (!pr.body.includes('HOTFIX: SKIP AZURE CI')) { | ||
const { data: pullRequest } = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: pr.number | ||
}); | ||
const latestCommitHash = pullRequest.head.sha; | ||
// Create commit status based on Azure CI report to PR | ||
await checkAzureCiAndCreateCommitStatus({ | ||
github, | ||
context, | ||
prNumber: pr.number, | ||
latestCommitHash: latestCommitHash | ||
}); | ||
} | ||
} |