-
Notifications
You must be signed in to change notification settings - Fork 250
152 lines (133 loc) · 5.94 KB
/
breaking-change-review.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: PR Review Workflow for Breaking Changes
on:
pull_request:
types:
- opened
- reopened
- labeled
- unlabeled
- synchronize
pull_request_review:
types:
- submitted
- edited
- dismissed
jobs:
check_breaking_change:
runs-on: ubuntu-latest
steps:
- name: Check for breaking change label
id: check_label
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const hasBreakingChange = labels.some(label => label.name === 'breaking change');
console.log(`Has breaking change label: ${hasBreakingChange}`);
return hasBreakingChange;
- name: Fetch QA team members
if: steps.check_label.outputs.result == 'true'
id: fetch_qa_teams
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
async function getTeamMembers(teamSlug) {
const { data: members } = await github.rest.teams.listMembersInOrg({
org: 'status-im',
team_slug: teamSlug,
});
return members.map(member => member.login);
}
const mobileQA = await getTeamMembers('mobile-qa');
const desktopQA = await getTeamMembers('desktop-qa');
console.log('Mobile QA team:', mobileQA);
console.log('Desktop QA team:', desktopQA);
core.setOutput('mobile_qa', mobileQA.join(','));
core.setOutput('desktop_qa', desktopQA.join(','));
- name: Request QA reviews
if: steps.check_label.outputs.result == 'true'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const mobileQA = '${{ steps.fetch_qa_teams.outputs.mobile_qa }}'.split(',');
const desktopQA = '${{ steps.fetch_qa_teams.outputs.desktop_qa }}'.split(',');
const reviewers = [...mobileQA, ...desktopQA];
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
reviewers: reviewers
});
- name: Check QA approvals
if: steps.check_label.outputs.result == 'true'
id: check_approvals
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { data: reviews } = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const mobileQA = '${{ steps.fetch_qa_teams.outputs.mobile_qa }}'.split(',');
const desktopQA = '${{ steps.fetch_qa_teams.outputs.desktop_qa }}'.split(',');
const mobileQAApproved = reviews.some(review =>
review.state === 'APPROVED' && mobileQA.includes(review.user.login)
);
const desktopQAApproved = reviews.some(review =>
review.state === 'APPROVED' && desktopQA.includes(review.user.login)
);
console.log(`Mobile QA approved: ${mobileQAApproved}`);
console.log(`Desktop QA approved: ${desktopQAApproved}`);
core.setOutput('mobile-qa-approved', mobileQAApproved);
core.setOutput('desktop-qa-approved', desktopQAApproved);
return mobileQAApproved && desktopQAApproved;
- name: Block PR if conditions not met
if: steps.check_label.outputs.result == 'true' && steps.check_approvals.outputs.result != 'true'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const mobileQAApproved = ${{ steps.check_approvals.outputs.mobile-qa-approved }};
const desktopQAApproved = ${{ steps.check_approvals.outputs.desktop-qa-approved }};
let message = 'This PR has the breaking change label and requires approval from both mobile-qa and desktop-qa teams before it can be merged.\n\n';
if (!mobileQAApproved && !desktopQAApproved) {
message += 'Both mobile-qa and desktop-qa teams have not approved this PR yet.';
} else if (!mobileQAApproved) {
message += 'The mobile-qa team has not approved this PR yet.';
} else if (!desktopQAApproved) {
message += 'The desktop-qa team has not approved this PR yet.';
}
await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'QA Approval Check',
head_sha: context.payload.pull_request.head.sha,
status: 'completed',
conclusion: 'failure',
output: {
title: 'QA Approval Required',
summary: message
}
});
- name: Allow PR merge if conditions are met
if: steps.check_label.outputs.result == 'true' && steps.check_approvals.outputs.result == 'true'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
await github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
event: 'APPROVE',
body: 'Breaking changes have been tested by Mobile and Desktop QA teams. This PR can now be merged.'
});