-
Notifications
You must be signed in to change notification settings - Fork 13
224 lines (221 loc) · 9.04 KB
/
proposal-review.yaml
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: Proposal Reviewers Check
permissions:
contents: read
pull-requests: write
on:
pull_request_review:
pull_request_target:
types: [opened, reopened, synchronize]
branches:
- 'dev'
- 'main'
jobs:
get_proposal_slug:
name: Get Proposal Slug
if: ${{startsWith(github.event.pull_request.head.ref, 'tutorials/')}}
runs-on: ubuntu-latest
defaults:
run:
shell: bash
outputs:
slug: ${{ steps.set_output.outputs.slug }}
steps:
- uses: actions/github-script@v6
id: regex_extract_proposal_id
with:
result-encoding: string
script: |
const headBranch = context.payload.pull_request.head.ref
const regex = /tutorials\/([A-z0-9]+(?:[_-][A-z0-9]+)*)/
const slug = headBranch.match(regex)
return slug && slug[1] || ''
- name: Set Output
id: set_output
run: |
echo "::set-output name=slug::${{ steps.regex_extract_proposal_id.outputs.result }}"
fetch_proposal:
name: Fetch Proposal
needs: get_proposal_slug
if: ${{ needs.get_proposal_slug.outputs.slug }} != ''
runs-on: ubuntu-latest
defaults:
run:
shell: bash
outputs:
proposalId: ${{ steps.fetch.outputs.proposalId }}
proposalState: ${{ steps.fetch.outputs.proposalState }}
reviewer1: ${{ steps.fetch.outputs.reviewer1 }}
reviewer2: ${{ steps.fetch.outputs.reviewer2 }}
reviewer1_githubName: ${{ steps.fetch.outputs.reviewer1_githubName }}
reviewer2_githubName: ${{ steps.fetch.outputs.reviewer2_githubName }}
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/build-builderdao-cli/
- id: fetch
env:
SLUG: ${{ needs.get_proposal_slug.outputs.slug }}
run: |
builderdao proposal get -s $SLUG
REVIEWER1=$(builderdao proposal get -s $SLUG -k reviewer1 --skip-ceramic)
REVIEWER2=$(builderdao proposal get -s $SLUG -k reviewer2 --skip-ceramic)
PROPOSAL_ID=$(builderdao proposal get -s $SLUG -k id --skip-ceramic)
PROPOSAL_STATE=$(builderdao proposal get -s $SLUG -k state --skip-ceramic)
REVIEWER1_GITHUBNAME=$(builderdao reviewer get -p $REVIEWER1 -k githubName)
REVIEWER2_GITHUBNAME=$(builderdao reviewer get -p $REVIEWER2 -k githubName)
echo "::set-output name=reviewer1::$REVIEWER1"
echo "::set-output name=reviewer2::$REVIEWER2"
echo "::set-output name=proposalId::$PROPOSAL_ID"
echo "::set-output name=proposalState::$PROPOSAL_STATE"
echo "::set-output name=reviewer1_githubName::$REVIEWER1_GITHUBNAME"
echo "::set-output name=reviewer2_githubName::$REVIEWER2_GITHUBNAME"
comment:
name: Create comment
needs: [fetch_proposal, get_proposal_slug]
if: ${{ needs.get_proposal_slug.outputs.slug }} != ''
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Find Status Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Tutorial Details
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
:open_book: Tutorial Details
```
ID: ${{ needs.fetch_proposal.outputs.proposalId }}
```
```
SLUG: ${{ needs.get_proposal_slug.outputs.slug }}
```
REVIEWER1: [${{ needs.fetch_proposal.outputs.reviewer1_githubName }}](https://github.com/${{ needs.fetch_proposal.outputs.reviewer1_githubName }})
REVIEWER2: [${{ needs.fetch_proposal.outputs.reviewer2_githubName }}](https://github.com/${{ needs.fetch_proposal.outputs.reviewer2_githubName }})
See [:scroll: Proposal](https://kafe-git-${{steps.extract_branch.outputs.branch}}-builder-dao.vercel.app/vote/${{ needs.get_proposal_slug.outputs.slug }})
edit-mode: replace
check_review_status:
needs: [fetch_proposal]
name: Check reviewers approved
runs-on: ubuntu-latest
defaults:
run:
shell: bash
outputs:
state: ${{ steps.check_all_reviewers_approved.outputs.state }}
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/check-required-reviewer
id: reviewer1_review
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AUTHOR: ${{needs.fetch_proposal.outputs.reviewer1_githubName}}
- uses: ./.github/actions/check-required-reviewer
id: reviewer2_review
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AUTHOR: ${{needs.fetch_proposal.outputs.reviewer2_githubName}}
- env:
REVIEWER1_REVIEW: ${{ steps.reviewer1_review.outputs.state }}
REVIEWER2_REVIEW: ${{ steps.reviewer2_review.outputs.state }}
run: |
echo "reviewer1 $REVIEWER1_REVIEW"
echo "reviewer2 $REVIEWER2_REVIEW"
- id: check_all_reviewers_approved
env:
ALL_REQUIRED_REVIEWERS_APPROVED: ${{steps.reviewer1_review.outputs.state == 'APPROVED' && steps.reviewer2_review.outputs.state == 'APPROVED'}}
run: |
echo $ALL_REQUIRED_REVIEWERS_APPROVED
STATUS=$([ "$ALL_REQUIRED_REVIEWERS_APPROVED" == true ] && echo "readyToPublish" || echo "writing")
echo $STATUS
echo "::set-output name=state::$STATUS"
- uses: ./.github/actions/build-builderdao-cli/
- id: set_state
env:
PROPOSAL_ID: ${{ needs.fetch_proposal.outputs.proposalId }}
TESTNET_ADMIN_KP: ${{ secrets.TESTNET_ADMIN_KP }}
NEW_STATE: ${{ steps.check_all_reviewers_approved.outputs.state }}
run: |
builderdao proposal setstate $PROPOSAL_ID --state=$NEW_STATE --adminKp $TESTNET_ADMIN_KP
- name: ready_label
if: contains(steps.check_all_reviewers_approved.outputs.state, 'readyToPublish')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.setLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['tutorial', 'ready_to_publish']
})
- name: pending_label
if: contains(steps.check_all_reviewers_approved.outputs.state, 'writing')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.setLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['tutorial', 'pending_review']
})
update_algolia_index:
name: Update Algolia Index
needs: [get_proposal_slug, check_review_status]
if: contains(needs.check_review_status.outputs.state, 'readyToPublish')
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/build-builderdao-cli/
- id: fetch
env:
SLUG: ${{ needs.get_proposal_slug.outputs.slug }}
run: |
builderdao proposal get -s $SLUG
PROPOSAL_ID=$(builderdao proposal get -s $SLUG -k id --skip-ceramic)
PROPOSAL_STATE=$(builderdao proposal get -s $SLUG -k state --skip-ceramic)
echo "::set-output name=proposalId::$PROPOSAL_ID"
echo "::set-output name=proposalState::$PROPOSAL_STATE"
- id: update_algolia_index
env:
OBJECT_ID: ${{ steps.fetch.outputs.proposalId }}
PROPOSAL_STATE: ${{ steps.fetch.outputs.proposalState }}
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_ACCESS_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }}
ALGOLIA_INDEX_NAME: ${{ secrets.ALGOLIA_INDEX_NAME }}
run: |
builderdao algolia updateIndex $OBJECT_ID --data='{"state": "$PROPOSAL_STATE"}' --appId $ALGOLIA_APP_ID --accessKey $ALGOLIA_ACCESS_KEY --indexName $ALGOLIA_INDEX_NAME
# TODO: after ready_to_publish if they push code set state back to writing.
request_reviews:
needs: [check_review_status, fetch_proposal]
if: contains(needs.check_review_status.outputs.state, 'writing')
name: Assign Reviewer 2 to PR
runs-on: ubuntu-latest
steps:
- name: Create PR review request
uses: actions/github-script@v6
with:
script: |
github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{github.event.pull_request.number}},
reviewers: [
"${{needs.fetch_proposal.outputs.reviewer1_githubName}}",
"${{needs.fetch_proposal.outputs.reviewer2_githubName}}"
]
});