generated from fastai/fastpages
-
Notifications
You must be signed in to change notification settings - Fork 40
186 lines (163 loc) · 6.92 KB
/
chatops.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
name: Chatops
on: [issue_comment]
jobs:
trigger-chatops:
if: (github.event.issue.pull_request != null) && contains(github.event.comment.body, '/preview') && (github.repository == 'kubeflow/blog')
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
CHECK_RUN_NAME: "Draft-Site-Build"
runs-on: ubuntu-latest
steps:
- name: verify env exists
id: get_status
run: |
if [ -z ${NETLIFY_AUTH_TOKEN} ]; then echo "::set-output name=status::public"; else echo "::set-output name=status::private"; fi
- name: make comment on PR if env does not exist
if: steps.get_status.outputs.status == 'public'
run: |
./_action_files/pr_comment.sh "Was not able to generate site preview due to absent credentials."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
- name: Fetch context about the PR that has been commented on
id: chatops
uses: machine-learning-apps/actions-chatops@master
with:
TRIGGER_PHRASE: "/preview"
env: # you must supply GITHUB_TOKEN
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.6
- name: install requests
run: pip3 install requests
- name: add check run
id: create_check
if: steps.get_status.outputs.status == 'private'
shell: python
run: |
import os, requests
sha = os.getenv('SHA')
token = os.getenv('GITHUB_TOKEN')
nwo = os.getenv('GITHUB_REPOSITORY')
name = os.getenv('CHECK_RUN_NAME')
url = f'https://api.github.com/repos/{nwo}/check-runs'
headers = {'authorization': f'token {token}',
'accept': 'application/vnd.github.antiope-preview+json'}
payload = {
'name': f'{name}',
'head_sha': f'{sha}',
'status': 'in_progress',
'output':{
'title': f'Building preview of site for {sha}.',
'summary': ' ',
'text': ' '
},
}
response = requests.post(url=url, headers=headers, json=payload)
print(response)
id = response.json()['id']
print(f"::set-output name=id::{id}")
env:
SHA: ${{ steps.chatops.outputs.SHA }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: add label
if: steps.get_status.outputs.status == 'private'
run: |
import os, requests
nwo = os.getenv('GITHUB_REPOSITORY')
token = os.getenv('GITHUB_TOKEN')
pr_num = os.getenv('PR_NUM')
headers = {'Accept': 'application/vnd.github.symmetra-preview+json',
'Authorization': f'token {token}'}
url = f"https://api.github.com/repos/{nwo}/issues/{pr_num}/labels"
data = {"labels": ["draft build pending"]}
result = requests.post(url=url, headers=headers, json=data)
# assert response.status_code == 201, f"Received status code of {response.status_code}"
print(result)
shell: python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUM: ${{ steps.chatops.outputs.PULL_REQUEST_NUMBER }}
GITHUB_REPOSITORY: $GITHUB_REPOSITORY
- name: Copy The PR's Branch Repository Contents
uses: actions/checkout@master
if: steps.get_status.outputs.status == 'private'
with:
ref: ${{ steps.chatops.outputs.SHA }}
- name: convert notebooks and word docs to posts
uses: ./_action_files
- name: setup directories for Jekyll build
if: steps.get_status.outputs.status == 'private'
run: |
rm -rf _site
sudo chmod -R 777 .
- name: Jekyll build with baseurl as root for netifly
if: steps.get_status.outputs.status == 'private'
uses: docker://hamelsmu/fastpages-jekyll
with:
args: bash -c "gem install bundler && jekyll build"
- name: deploy to netlify
if: steps.get_status.outputs.status == 'private'
id: py
run: |
sudo npm install netlify-cli -g
netlify deploy --dir _site | tee _netlify_logs.txt
cat _netlify_logs.txt | python _action_files/parse_netlify.py
- name: make comment on PR
if: steps.get_status.outputs.status == 'private'
run: |
MSG="A preview build of this branch has been generated for SHA: $SHA and can be viewed **live** at: ${URL}\n\nThe current fastpages site built from master can be viewed for comparison [here](https://blog.kubeflow.org/)"
echo "$MSG"
./_action_files/pr_comment.sh "${MSG}"
env:
URL: ${{ steps.py.outputs.draft_url }}
SHA: ${{ steps.chatops.outputs.SHA }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
- name: remove label
if: always()
run: |
import os, requests
nwo = os.getenv('GITHUB_REPOSITORY')
token = os.getenv('GITHUB_TOKEN')
pr_num = os.getenv('PR_NUM')
headers = {'Accept': 'application/vnd.github.symmetra-preview+json',
'Authorization': f'token {token}'}
url = f"https://api.github.com/repos/{nwo}/issues/{pr_num}/labels/draft%20build%20pending"
result = requests.delete(url=url, headers=headers)
print(result)
shell: python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUM: ${{ steps.chatops.outputs.PULL_REQUEST_NUMBER }}
GITHUB_REPOSITORY: $GITHUB_REPOSITORY
# defensively clear check run each time
- name: clear check run
if: always()
continue-on-error: true
shell: python
run: |
import os, requests
sha = os.getenv('SHA')
conclusion = os.getenv('WORKFLOW_CONCLUSION').lower()
token = os.getenv('GITHUB_TOKEN')
nwo = os.getenv('GITHUB_REPOSITORY')
check_run_id = os.getenv('CHECK_RUN_ID')
if not check_run_id:
quit()
url = f'https://api.github.com/repos/{nwo}/check-runs/{check_run_id}'
headers = {'authorization': f'token {token}',
'accept': 'application/vnd.github.antiope-preview+json'}
data = {
'conclusion': f'{conclusion}',
}
response = requests.patch(url=url, headers=headers, json=data)
print(response)
env:
SHA: ${{ steps.chatops.outputs.SHA }}
WORKFLOW_CONCLUSION: ${{ job.status }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHECK_RUN_ID: ${{ steps.create_check.outputs.id }}