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