Skip to content

[HUDI-7438][DNM] Fix Azure CI report check with new issue comments #116

[HUDI-7438][DNM] Fix Azure CI report check with new issue comments

[HUDI-7438][DNM] Fix Azure CI report check with new issue comments #116

Workflow file for this run

# 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
on:
pull_request:
types: [ opened, edited, reopened, synchronize ]
issue_comment:
types: [ created, edited, deleted ]
permissions:
checks: write
pull-requests: read
issues: read
jobs:
check-azure-ci-report:
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
id: last_commit
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
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", 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}}
script: |
const lastCommitHash = '${{ steps.last_commit.outputs.last_commit_hash }}'
const botUsername = 'hudi-bot';
const issueNumber = context.payload.pull_request.number;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
});
// Find the last comment from hudi-bot containing the Azure CI report
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)) {
message = 'Azure CI succeeded on the latest commit of the PR.';
result = true;
} else if (lastComment.body.includes(failureReportString)) {
message = 'Azure CI failed on the latest commit of the PR';
result = false;
} else {
message = 'Azure CI is in progress on the latest commit of the PR.';
result = false;
}
} else {
message = 'No Azure CI report on the latest commit of the PR.';
result = false;
}
} else {
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/{}