Skip to content

Commit

Permalink
[HUDI-7438] Fix Azure CI report check with new issue comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yihua committed Feb 24, 2024
1 parent 47d9631 commit c4f0131
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 35 deletions.
87 changes: 68 additions & 19 deletions .github/workflows/azure_ci_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@
name: Azure CI

on:
pull_request:
types: [ opened, edited, reopened, synchronize ]
issue_comment:
types: [ created, edited, deleted ]

permissions:
checks: write
statuses: write
pull-requests: read
issues: read

jobs:
check-azure-ci-report:
if: "!contains(github.event.pull_request.body, 'HOTFIX: SKIP AZURE CI')"
if: true #|
#github.event.issue.pull_request != null &&
#!contains(github.event.pull_request.body, 'HOTFIX: SKIP AZURE CI')
runs-on: ubuntu-latest
steps:
- name: Get last commit hash
Expand All @@ -37,13 +42,20 @@ jobs:
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pr = context.payload.pull_request;
const lastCommitHash = pr.head.sha;
console.log(`Last commit hash: ${lastCommitHash}`);
const issueNumber = 10740; // github.event.issue.number;
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issueNumber
});
const commitHash = pullRequest.head.sha;
console.log(`Latest commit hash: ${commitHash}`);
// Set the output variable to be used in subsequent step
core.setOutput("last_commit_hash", lastCommitHash);
core.setOutput("last_commit_hash", commitHash);
- name: Check Azure CI report in PR comment
id: check_report_in_pr_comment
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
Expand All @@ -62,32 +74,69 @@ jobs:
const botComments = comments.data.filter(comment => comment.user.login === botUsername);
const lastComment = botComments.pop();
let message = '';
let result = false;
if (lastComment) {
const reportPrefix = '${lastCommitHash} Azure: '
const successReportString = '${reportPrefix}[SUCCESS]'
const failureReportString = '${reportPrefix}[FAILURE]'
if (lastComment.body.includes(reportPrefix)) {
if (lastComment.body.includes(successReportString)) {
console.log(`Azure CI succeeded on the latest commit of the PR.`);
return true;
message = 'Azure CI succeeded on the latest commit of the PR.';
result = true;
} else if (lastComment.body.includes(failureReportString)) {
console.log(`Azure CI failed on the latest commit of the PR.`);
core.setFailed("Azure CI failed on the latest commit of the PR.");
return false;
message = 'Azure CI failed on the latest commit of the PR';
result = false;
} else {
console.log(`Azure CI is in progress on the latest commit of the PR.`);
core.setFailed("Azure CI is in progress on the latest commit of the PR.");
return false;
message = 'Azure CI is in progress on the latest commit of the PR.';
result = false;
}
} else {
console.log(`No Azure CI report on the latest commit of the PR.`);
core.setFailed("No Azure CI report on the latest commit of the PR.");
return false;
message = 'No Azure CI report on the latest commit of the PR.';
result = false;
}
} else {
console.log(`Azure CI report does not seem to be ready yet.`);
core.setFailed("Azure CI report does not seem to be ready yet.");
return false;
message = 'Azure CI report does not seem to be ready yet.';
result = false;
}
console.log(`${message}`);
core.setOutput("check_result_message", message);
core.setOutput("is_check_successful", result);
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Attach Azure CI report check to the PR
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let conclusionString = 'failure';
if (${{ steps.check_report_in_pr_comment.outputs.is_check_successful }}) {
conclusionString = 'success';
}
console.log(`Check status: ${conclusionString}`);
await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'Azure CI Report Check',
head_sha: '${{ steps.last_commit.outputs.last_commit_hash }}',
status: 'completed',
conclusion: '${conclusionString}',
completed_at: new Date(),
output: {
title: 'Azure CI Report Check',
summary: '${{ steps.check_report_in_pr_comment.outputs.check_result_message }}',
}
});
- name: Remove Azure CI Blocker check
run: |
curl -X GET \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
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 \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{"status": "neutral"}' \
https://api.github.com/repos/${{ github.repository }}/check-runs/{}
82 changes: 82 additions & 0 deletions .github/workflows/create_azure_ci_check.yml
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.

name: Azure CI Blocker

on:
pull_request:
types: [ opened, edited, reopened, synchronize ]

permissions:
statuses: write
pull-requests: read
issues: read

jobs:
create-azure-ci-report-check:
if: "!contains(github.event.pull_request.body, 'HOTFIX: SKIP AZURE CI')"
runs-on: ubuntu-latest
steps:
- name: Test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo ${GITHUB_SHA}
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA} \
-d '{"state":"success","target_url":"https://example.com/build/status","description":"The build succeeded!","context":"continuous-integration/jenkins"}'
- name: Create a placeholder check for Azure CI report
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueNumber = 10743; // github.event.issue.number;
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issueNumber
});
const commitHash = pullRequest.head.sha;
console.log(`Latest commit hash: ${commitHash}`);
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: commitHash,
state: 'pending',
target_url: 'https://hudi.apache.org/',
description: 'running in progress',
context: 'External CI'
});
console.log('Sleeping for 30 seconds...');
await new Promise(resolve => setTimeout(resolve, 30000));
console.log('Done sleeping');
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: commitHash,
state: 'success',
target_url: 'https://hudi.apache.org/',
description: 'finished successfully',
context: 'External CI'
});
62 changes: 46 additions & 16 deletions .github/workflows/labeler.yml
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}`);

0 comments on commit c4f0131

Please sign in to comment.