-
Notifications
You must be signed in to change notification settings - Fork 37
144 lines (131 loc) · 4.76 KB
/
updateDatabase.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
name: Update database
on:
issue_comment:
types: [created]
defaults:
run:
working-directory: backend/api
jobs:
# The base job checks if comment is the right function and made on a pull request
base_check:
if: |
github.event.issue.pull_request &&
github.event.comment.body == '/UpdateDatabase'
runs-on: ubuntu-latest
permissions:
pull-requests: write
outputs:
eyes_id: ${{ fromJson(steps.eyes.outputs.data).id }}
steps:
# Using the post request directly to be able to remove the reaction later (Need reaction id for this)
# This allows the reaction to act as a status for the function.
- name: React to comment
uses: octokit/[email protected]
id: eyes
with:
route: POST /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions
content: "eyes"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Need to curl for the PR state as this does not exist in the github.event payload for issue_comment
get_review_state:
needs: base_check
runs-on: windows-latest
outputs:
review_approved: ${{ contains(fromJson(steps.get.outputs.data).*.state, 'APPROVED') }}
eyes_id: ${{ needs.base_check.outputs.eyes_id }}
steps:
- uses: octokit/[email protected]
id: get
with: # Search in PR's for this ID with review approved.
# If no results, the PR is not approved
route: GET /repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}/reviews
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if_not_approved_then_stop:
needs: get_review_state
if: ${{ needs.get_review_state.outputs.review_approved == 'false' }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Remove 'eyes' reaction
uses: octokit/[email protected]
with:
route: DELETE /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions/${{ needs.get_review_state.outputs.eyes_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: React to comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.comment.id }}
reactions: confused, -1
- name: Add comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.issue.number }}
body: |
:no_entry: Cannot update database until the Pull Request is approved! :no_entry:
database_update_start:
needs: get_review_state
if: ${{ needs.get_review_state.outputs.review_approved == 'true' }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Remove 'eyes' reaction
uses: octokit/[email protected]
with:
route: DELETE /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions/${{ needs.get_review_state.outputs.eyes_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: React to comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.comment.id }}
reactions: rocket, +1
- name: Add comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.issue.number }}
body: |
:eyes: Running migration command... :eyes:
run_migrations:
needs: database_update_start
uses: ./.github/workflows/runMigrations.yml
with:
PullRequestCheckout: true
Environment: Development
secrets:
ClientId: ${{secrets.CLIENTID}}
ClientSecret: ${{secrets.CLIENTSECRET}}
database_success:
needs: run_migrations
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Add comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.issue.number }}
body: |
:sparkles: Successfully ran migration command! :sparkles:
database_failure:
needs: run_migrations
if: ${{ failure() }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Add comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.issue.number }}
body: |
:x: Migration failed, please see action log below for details :x:
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}