-
Notifications
You must be signed in to change notification settings - Fork 2
146 lines (144 loc) · 5.34 KB
/
build_on_pull_request.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
name: Review and build
on:
workflow_run:
workflows:
- Trigger "Review and build" action
types:
- completed
jobs:
download_data:
name: Download event data
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
outputs:
event_data: ${{ steps.output_event_data.outputs.event_data }}
steps:
- name: Download artifact
uses: dawidd6/action-download-artifact@v6
with:
workflow: build_on_pull_request_trigger.yml
name: event_data
- name: Output event data
id: output_event_data
run: echo event_data=$(<./event_data.json) >> $GITHUB_OUTPUT
test:
name: Test
needs: download_data
uses: ./.github/workflows/test.yml
with:
ref: ${{ fromJSON(needs.download_data.outputs.event_data).pull_request.head.sha }}
continue_on_error: true
review:
name: Submit a review
needs:
- download_data
- test
runs-on: ubuntu-latest
permissions:
pull-requests: write
outputs:
review_data: ${{ steps.output_review.outputs.review_data }}
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
with:
ref: ${{ fromJSON(needs.download_data.outputs.event_data).pull_request.head.sha }}
- name: Setup Node.js
uses: actions/setup-node@v4.0.2
with:
node-version: 20.12.0
cache: npm
- name: Install dependencies
run: npm install
- name: Prepare output folder
run: mkdir ./out
- name: Get diff
run: gh pr diff ${{ fromJSON(needs.download_data.outputs.event_data).number }} --repo ${{ github.repository }} > ./out/diff.log
env:
GH_TOKEN: ${{ github.token }}
- name: Create review data
run: ../../node_modules/.bin/ts-node ./submit_review.ts ${{ fromJSON(needs.download_data.outputs.event_data).pull_request.head.sha }} '${{ needs.test.outputs.test_1 }}' '${{ needs.test.outputs.test_2 }}'
working-directory: ./src/tests/
- name: Output review data
id: output_review
run: echo review_data=$(<./out/review.json) >> $GITHUB_OUTPUT
- name: Submit review
run: |
curl -L \
-X POST \
-H 'Accept: application/vnd.github+json' \
-H 'Authorization: Bearer ${{ github.token }}' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ fromJSON(needs.download_data.outputs.event_data).number }}/reviews \
-d '${{ steps.output_review.outputs.review_data }}'
build:
name: Build
needs:
- download_data
- review
if: ${{ fromJSON(needs.review.outputs.review_data).event == 'COMMENT' }}
uses: ./.github/workflows/build.yml
with:
ref: ${{ fromJSON(needs.download_data.outputs.event_data).pull_request.head.sha }}
comment:
name: Send comment
needs:
- download_data
- build
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Create comment file
run: |
cat << EOF > ./comment.txt
Finished building translation data. You can get it from the following link:
https://github.com/Gakuto1112/Stormworks-JapaneseTranslation/actions/runs/${{ needs.build.outputs.run_id }}
EOF
- name: Send comment
run: gh pr comment ${{ fromJSON(needs.download_data.outputs.event_data).number }} --body-file ./comment.txt --repo ${{ github.repository }}
env:
GH_TOKEN: ${{ github.token }}
request_review:
name: Request a review for the pull request to Gakuto1112
needs:
- download_data
- review
if: ${{ fromJSON(needs.review.outputs.review_data).event == 'COMMENT' && fromJSON(needs.download_data.outputs.event_data).pull_request.user.login != 'Gakuto1112' }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Check requested reviewers
id: check_reviewers
continue-on-error: true
run: |
gh api \
-H 'Accept: application/vnd.github+json' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
/repos/${{ github.repository }}/pulls/${{ fromJSON(needs.download_data.outputs.event_data).number }}/requested_reviewers \
| jq .users[].login | grep Gakuto1112
env:
GH_TOKEN: ${{ github.token }}
- name: Check reviews
id: check_reviews
continue-on-error: true
run: |
gh api \
-H 'Accept: application/vnd.github+json' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
/repos/${{ github.repository }}/pulls/${{ fromJSON(needs.download_data.outputs.event_data).number }}/reviews \
| jq .[].user.login | grep Gakuto1112
env:
GH_TOKEN: ${{ github.token }}
- name: Request a review for the pull request to Gakuto1112
if: ${{ steps.check_reviewers.outcome == 'failure' && steps.check_reviews.outcome == 'failure' }}
run: |
gh api \
--method POST \
-H 'Accept: application/vnd.github+json' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
/repos/${{ github.repository }}/pulls/${{ fromJSON(needs.download_data.outputs.event_data).number }}/requested_reviewers \
-f 'reviewers[]=Gakuto1112'
env:
GH_TOKEN: ${{ github.token }}