-
Notifications
You must be signed in to change notification settings - Fork 20
143 lines (127 loc) · 5.28 KB
/
build-pr.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
name: build test site on trigger comment
on:
issue_comment:
types: [created]
jobs:
deploy:
name: Deploy
runs-on: doc-gen
if: (toJSON(github.event.issue.pull_request) != 'null') && (startsWith(github.event.comment.body, '#deploy') || contains(toJSON(github.event.comment.body), '\r\n#deploy'))
steps:
- uses: octokit/[email protected]
name: Get PR head
id: get_pr_head
with:
route: GET /repos/:repository/pulls/:pull_number
repository: ${{ github.repository }}
pull_number: ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Parse steps.get_pr_head.outputs.data, since it is a string
- id: parse_pr_head
name: Parse PR head
uses: gr2m/[email protected]
with:
json: ${{ steps.get_pr_head.outputs.data }}
head_user: 'head.user.login'
- uses: octokit/[email protected]
name: Get comment author
id: get_user
with:
route: GET /repos/:repository/collaborators/:username/permission
repository: ${{ github.repository }}
username: ${{ github.event.comment.user.login }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Parse steps.get_user.outputs.data, since it is a string
- id: parse_user
name: Parse comment author permission
uses: gr2m/[email protected]
with:
json: ${{ steps.get_user.outputs.data }}
permission: 'permission'
- name: Add reaction
if: (steps.parse_user.outputs.permission == 'admin')
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ github.event.comment.id }}
reactions: rocket
# this step is needed to get the PR ref from an issue comment
# https://github.com/actions/checkout/issues/331
- uses: actions/github-script@v3
if: (steps.parse_user.outputs.permission == 'admin')
id: get-pr
with:
script: |
const request = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
}
core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`)
try {
const result = await github.pulls.get(request)
return result.data
} catch (err) {
core.setFailed(`Request failed with error ${err}`)
}
- uses: actions/checkout@v2
if: (steps.parse_user.outputs.permission == 'admin')
with:
repository: ${{ fromJSON(steps.get-pr.outputs.result).head.repo.full_name }}
ref: ${{ fromJSON(steps.get-pr.outputs.result).head.sha }} # or .head.ref for branch name
- name: Checkout mathlib
if: (steps.parse_user.outputs.permission == 'admin')
run: git clone https://github.com/leanprover-community/mathlib
- name: install elan
if: (steps.parse_user.outputs.permission == 'admin')
run: |
set -o pipefail
curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh -s -- --default-toolchain none -y
cd mathlib
~/.elan/bin/lean --version
echo "$HOME/.elan/bin" >> $GITHUB_PATH
# - name: install Python
# if: (steps.parse_user.outputs.permission == 'admin')
# uses: actions/setup-python@v1
# with:
# python-version: 3.8
- name: setup python venv
if: (steps.parse_user.outputs.permission == 'admin')
run: |
python3 -m venv .venv
echo "$PWD/.venv/bin" >> $GITHUB_PATH
- name: install Python dependencies
if: (steps.parse_user.outputs.permission == 'admin')
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: run leanproject
if: (steps.parse_user.outputs.permission == 'admin')
run: |
cd mathlib
leanproject up
- name: generate docs
if: (steps.parse_user.outputs.permission == 'admin')
run: ./deploy_docs.sh "mathlib" ".." "mathlib" "leanprover-community" "mathlib_docs_demo" "true"
env:
DEPLOY_GITHUB_TOKEN: ${{ secrets.DEPLOY_GITHUB_TOKEN }}
github_repo: ${{ github.repository }}
github_event: ${{ github.event_name }}
github_ref: ${{ github.ref }}
# https://stackoverflow.com/questions/58066966/commenting-a-pull-request-in-a-github-action
- name: Post link
if: (steps.parse_user.outputs.permission == 'admin')
env:
URL: ${{ github.event.issue.comments_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl \
-X POST \
$URL \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
--data '{ "body": "This PR has been successfully deployed! You can find it at <http://leanprover-community.github.io/mathlib_docs_demo> in around 10 minutes, or watch the deployment progress by going to <http://github.com/leanprover-community/mathlib_docs_demo>" }'
- name: clean up working directory and elan
if: always()
run: rm -rf * $HOME/.elan