-
Notifications
You must be signed in to change notification settings - Fork 5
101 lines (87 loc) · 4.13 KB
/
run_pr_on_binder.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
name: Interactive PRs
on:
pull_request:
types: [labeled, synchronize]
jobs:
setup-interactive-pr:
name: Setup interactive PR
runs-on: ubuntu-latest
steps:
- name: Check if this is a labelling event, and the 'interactive_review' label was added
if: ${{ github.event.action == 'labeled' && github.event.label.name == 'interactive_review' }}
id: checkLabelFromLabelling
shell: bash
run: echo "::set-output name=hasLabel::true"
- name: Check if this is a synchronise event and the 'interactive_review' label is present
uses: Dreamcodeio/pr-has-label-action@master
if: ${{ github.event.action != 'labeled' }}
id: checkLabelFromSync
with:
label: interactive_review
- name: Combine variables into a single output
if: ${{ steps.checkLabelFromLabelling.outputs.hasLabel || steps.checkLabelFromSync.outputs.hasLabel }}
shell: bash
id: checkLabel
run: echo "::set-output name=hasLabel::true"
- name: Calculate build finish time
id: buildFinish
if: ${{ steps.checkLabel.outputs.hasLabel }}
shell: bash
run: echo ::set-output name=finish_time::`TZ='Europe/London' date --date 'now + 5 minutes' +%H:%M`
- name: Find comment (in case one already exists)
if: ${{ steps.checkLabel.outputs.hasLabel }}
uses: peter-evans/find-comment@v1
id: findComment
with:
issue-number: ${{github.event.number}}
body-includes: <!-- GH Actions Binder Comment -->
- name: Create comment (if it doesn't exist)
id: createComment
if: ${{ steps.checkLabel.outputs.hasLabel && (steps.findComment.outputs.comment-id == 0) }}
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{github.event.number}}
body: |
<!-- GH Actions Binder Comment -->
Building interactive demo on Binder, due to complete at ${{ steps.buildFinish.outputs.finish_time }} UK time.
- name: Update comment (if it already exists)
if: ${{ steps.checkLabel.outputs.hasLabel && (steps.findComment.outputs.comment-id != 0) }}
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{github.event.number}}
comment-id: ${{ steps.findComment.outputs.comment-id }}
edit-mode: replace
body: |
<!-- GH Actions Binder Comment -->
Building interactive demo on Binder, due to complete at ${{ steps.buildFinish.outputs.finish_time }} UK time.
- name: Trigger builds on Binder
uses: s-weigand/trigger-mybinder-build@v1
if: ${{ steps.checkLabel.outputs.hasLabel }}
with:
target-repo: debrief/pepys-import
target-state: ${{ github.head_ref }}
- name: Wait for 5 minutes (to give time for all Binder instances to build)
if: ${{ steps.checkLabel.outputs.hasLabel }}
uses: jakejarvis/wait-action@master
with:
time: '5m'
# We can't just use the earlier output from findComment as we may have created a new comment
- name: Find comment from earlier
if: ${{ steps.checkLabel.outputs.hasLabel }}
uses: peter-evans/find-comment@v1
id: findComment2
with:
issue-number: ${{github.event.number}}
body-includes: <!-- GH Actions Binder Comment -->
- name: Update comment with link
if: ${{ steps.checkLabel.outputs.hasLabel }}
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{github.event.number}}
comment-id: ${{ steps.findComment2.outputs.comment-id }}
edit-mode: replace
body: |
<!-- GH Actions Binder Comment -->
:rocket: Interactive demo available via Binder [![logo](https://mybinder.org/static/logo.svg)](https://mybinder.org/v2/gh/debrief/pepys-import/${{github.head_ref}}?filepath=demos/).
*Note:* The Jupyter notebook browser will open in the `demos` folder. See comments above for which notebook to use,
otherwise use the `_Default_Demo.ipynb` notebook.