|
| 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 |
| 19 | + |
| 20 | +on: |
| 21 | + issue_comment: |
| 22 | + types: [ created, edited, deleted ] |
| 23 | + |
| 24 | +permissions: |
| 25 | + pull-requests: read |
| 26 | + issues: read |
| 27 | + |
| 28 | +jobs: |
| 29 | + check-azure-ci-report: |
| 30 | + if: "!contains(github.event.pull_request.body, 'HOTFIX: SKIP AZURE CI')" |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - name: Get last commit hash |
| 34 | + id: last_commit |
| 35 | + uses: actions/github-script@v7 |
| 36 | + with: |
| 37 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 38 | + script: | |
| 39 | + const pr = context.payload.pull_request; |
| 40 | + const lastCommitHash = pr.head.sha; |
| 41 | + console.log(`Last commit hash: ${lastCommitHash}`); |
| 42 | + // Set the output variable to be used in subsequent step |
| 43 | + core.setOutput("last_commit_hash", lastCommitHash); |
| 44 | +
|
| 45 | + - name: Check Azure CI report in PR comment |
| 46 | + uses: actions/github-script@v7 |
| 47 | + with: |
| 48 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 49 | + script: | |
| 50 | + const lastCommitHash = '${{ steps.last_commit.outputs.last_commit_hash }}' |
| 51 | + const botUsername = 'hudi-bot'; |
| 52 | + |
| 53 | + const issueNumber = context.payload.pull_request.number; |
| 54 | + const comments = await github.rest.issues.listComments({ |
| 55 | + owner: context.repo.owner, |
| 56 | + repo: context.repo.repo, |
| 57 | + issue_number: issueNumber, |
| 58 | + }); |
| 59 | + |
| 60 | + // Find the last comment from hudi-bot containing the Azure CI report |
| 61 | + const botComments = comments.data.filter(comment => comment.user.login === botUsername); |
| 62 | + const lastComment = botComments.pop(); |
| 63 | + |
| 64 | + if (lastComment) { |
| 65 | + const reportPrefix = '${lastCommitHash} Azure: ' |
| 66 | + const successReportString = '${reportPrefix}[SUCCESS]' |
| 67 | + const failureReportString = '${reportPrefix}[FAILURE]' |
| 68 | + if (lastComment.body.includes(reportPrefix)) { |
| 69 | + if (lastComment.body.includes(successReportString)) { |
| 70 | + console.log(`Azure CI succeeded on the latest commit of the PR.`); |
| 71 | + return true; |
| 72 | + } 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; |
| 76 | + } 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; |
| 80 | + } |
| 81 | + } 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; |
| 85 | + } |
| 86 | + } 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; |
| 90 | + } |
| 91 | + env: |
| 92 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
0 commit comments