18
18
name : Azure CI
19
19
20
20
on :
21
+ pull_request :
22
+ types : [ opened, edited, reopened, synchronize ]
21
23
issue_comment :
22
24
types : [ created, edited, deleted ]
23
25
24
26
permissions :
27
+ checks : write
25
28
pull-requests : read
26
29
issues : read
27
30
28
31
jobs :
29
32
check-azure-ci-report :
30
- if : " !contains(github.event.pull_request.body, 'HOTFIX: SKIP AZURE CI')"
33
+ if : true # |
34
+ # github.event.issue.pull_request != null &&
35
+ # !contains(github.event.pull_request.body, 'HOTFIX: SKIP AZURE CI')
31
36
runs-on : ubuntu-latest
32
37
steps :
33
38
- name : Get last commit hash
@@ -36,13 +41,20 @@ jobs:
36
41
with :
37
42
github-token : ${{secrets.GITHUB_TOKEN}}
38
43
script : |
39
- const pr = context.payload.pull_request;
40
- const lastCommitHash = pr.head.sha;
41
- console.log(`Last commit hash: ${lastCommitHash}`);
44
+ const issueNumber = 10740; // github.event.issue.number;
45
+ const { data: pullRequest } = await github.rest.pulls.get({
46
+ owner: context.repo.owner,
47
+ repo: context.repo.repo,
48
+ pull_number: issueNumber
49
+ });
50
+
51
+ const commitHash = pullRequest.head.sha;
52
+ console.log(`Latest commit hash: ${commitHash}`);
42
53
// Set the output variable to be used in subsequent step
43
- core.setOutput("last_commit_hash", lastCommitHash );
54
+ core.setOutput("last_commit_hash", commitHash );
44
55
45
56
- name : Check Azure CI report in PR comment
57
+ id : check_report_in_pr_comment
46
58
uses : actions/github-script@v7
47
59
with :
48
60
github-token : ${{secrets.GITHUB_TOKEN}}
@@ -61,32 +73,69 @@ jobs:
61
73
const botComments = comments.data.filter(comment => comment.user.login === botUsername);
62
74
const lastComment = botComments.pop();
63
75
76
+ let message = '';
77
+ let result = false;
78
+
64
79
if (lastComment) {
65
80
const reportPrefix = '${lastCommitHash} Azure: '
66
81
const successReportString = '${reportPrefix}[SUCCESS]'
67
82
const failureReportString = '${reportPrefix}[FAILURE]'
68
83
if (lastComment.body.includes(reportPrefix)) {
69
84
if (lastComment.body.includes(successReportString)) {
70
- console.log(` Azure CI succeeded on the latest commit of the PR.`) ;
71
- return true;
85
+ message = ' Azure CI succeeded on the latest commit of the PR.' ;
86
+ result = true;
72
87
} 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;
88
+ message = 'Azure CI failed on the latest commit of the PR';
89
+ result = false;
76
90
} 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;
91
+ message = 'Azure CI is in progress on the latest commit of the PR.';
92
+ result = false;
80
93
}
81
94
} 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;
95
+ message = 'No Azure CI report on the latest commit of the PR.';
96
+ result = false;
85
97
}
86
98
} 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;
99
+ message = 'Azure CI report does not seem to be ready yet.';
100
+ result = false;
90
101
}
102
+ console.log(`${message}`);
103
+ core.setOutput("check_result_message", message);
104
+ core.setOutput("is_check_successful", result);
91
105
env :
92
106
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
107
+
108
+ - name : Attach Azure CI report check to the PR
109
+ uses : actions/github-script@v5
110
+ with :
111
+ github-token : ${{ secrets.GITHUB_TOKEN }}
112
+ script : |
113
+ let conclusionString = 'failure';
114
+ if (${{ steps.check_report_in_pr_comment.outputs.is_check_successful }}) {
115
+ conclusionString = 'success';
116
+ }
117
+ console.log(`Check status: ${conclusionString}`);
118
+ await github.rest.checks.create({
119
+ owner: context.repo.owner,
120
+ repo: context.repo.repo,
121
+ name: 'Azure CI Report Check',
122
+ head_sha: '${{ steps.last_commit.outputs.last_commit_hash }}',
123
+ status: 'completed',
124
+ conclusion: '${conclusionString}',
125
+ completed_at: new Date(),
126
+ output: {
127
+ title: 'Azure CI Report Check',
128
+ summary: '${{ steps.check_report_in_pr_comment.outputs.check_result_message }}',
129
+ }
130
+ });
131
+
132
+ - name : Remove Azure CI Blocker check
133
+ run : |
134
+ curl -X GET \
135
+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
136
+ -H "Accept: application/vnd.github.v3+json" \
137
+ 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 \
138
+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
139
+ -H "Accept: application/vnd.github.v3+json" \
140
+ -d '{"status": "neutral"}' \
141
+ https://api.github.com/repos/${{ github.repository }}/check-runs/{}
0 commit comments