-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (125 loc) · 4.79 KB
/
ci.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
name: E2E Tests
on:
pull_request:
branches:
- '**'
push:
branches:
- 'main'
env:
TEAM_MEMBERS: "nachoaldamav"
permissions:
issues: write
pull-requests: write
jobs:
check-author:
runs-on: ubuntu-latest
outputs:
is-external: ${{ steps.check-author.outputs.is-external }}
steps:
- name: Check if PR is from a team member
id: check-author
run: |
if [ "${{ github.event.pull_request }}" != "" ]; then
if echo "$TEAM_MEMBERS" | grep -q "${{ github.actor }}"; then
echo "PR is from a team member."
echo "is-external=false" >> $GITHUB_ENV
else
echo "PR is from an external contributor."
echo "is-external=true" >> $GITHUB_ENV
fi
else
echo "Not a PR, running the workflow."
echo "is-external=false" >> $GITHUB_ENV
fi
require-approval:
runs-on: ubuntu-latest
needs: check-author
steps:
- name: Check for existing approval comment
id: check-comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = context.issue.number;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
});
const approvalComment = comments.data.find(comment => comment.body.includes('Please approve this PR by reacting with an "👍".') && comment.user.login === 'github-actions[bot]');
if (approvalComment) {
core.setOutput('commentExists', 'true');
core.setOutput('commentId', approvalComment.id);
return approvalComment.id;
} else {
core.setOutput('commentExists', 'false');
return '';
}
- name: Create Approval Comment
if: steps.check-comment.outputs.commentExists == 'false'
id: create-comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = context.issue.number;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: 'Please approve this PR by reacting with an "👍".'
});
core.setOutput('commentCreated', 'true');
- name: Get Comment ID
if: steps.create-comment.outputs.commentCreated == 'true'
id: get-comment-id
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = context.issue.number;
await new Promise(r => setTimeout(r, 5000)); // 5-second delay
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
});
const approvalComment = comments.data.find(comment => comment.body.includes('Please approve this PR by reacting with an "👍".') && comment.user.login === 'github-actions[bot]');
if (approvalComment) {
core.setOutput('commentId', approvalComment.id.toString());
}
- name: Wait for Approval
run: |
comment_id=${{ steps.check-comment.outputs.result || steps.get-comment-id.outputs.commentId}}
echo "Comment ID: $comment_id"
counter=0
while [ $counter -lt 15 ]; do
echo "Checking for approvals, attempt $((counter + 1))"
response=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.squirrel-girl-preview+json" "https://api.github.com/repos/${{ github.repository }}/issues/comments/$comment_id/reactions")
echo "Response: $response"
approved=$(echo "$response" | jq '.[] | select(.content == "+1") | .user.login')
echo "Approved: $approved"
if [ -n "$approved" ]; then
echo "PR has been approved by a team member."
break
fi
sleep 60
((counter++))
done
if [ $counter -ge 15 ]; then
echo "Timeout reached for Approval - 15m. Exiting..."
exit 1
fi
windows-tests:
needs: [require-approval]
uses: ./.github/workflows/windows.yml
secrets: inherit
macos-tests:
needs: [require-approval]
uses: ./.github/workflows/macos.yml
linux-tests:
needs: [require-approval]
uses: ./.github/workflows/linux.yml
secrets: inherit