-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (125 loc) · 3.93 KB
/
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
name: on-pull-request
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
PRE_BUILD_DIR: "_pre_build"
PRE_BUILD_FLAGS: "--disclaimer"
defaults:
run:
shell: bash -l {0}
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pre-commit/[email protected]
deploy-preview:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
needs: pre-commit
steps:
- uses: actions/checkout@v4
- run: git fetch origin gh-pages
- uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: 'pip'
- uses: actions/checkout@v4
- name: Get changed notebooks
id: changed-files
uses: tj-actions/changed-files@v45
with:
files: |
**.ipynb
- name: Remove untouched notebooks
id: remove-untouched-notebooks
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |-
for file in ${ALL_CHANGED_FILES}; do
mv "$file" "$file".keep
done
rm ./**/*.ipynb
for file in ${ALL_CHANGED_FILES}; do
mv "$file".keep "$file"
done
- run: pip install -r requirements.txt
- run: make build-book PRE_BUILD_DIR=${{ env.PRE_BUILD_DIR }} PRE_BUILD_FLAGS=${{ env.PRE_BUILD_FLAGS }}
- uses: rossjrw/pr-preview-action@v1
with:
source-dir: "${{ env.PRE_BUILD_DIR }}/_build/html"
comment-pr:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Get changed notebooks
id: changed-files
uses: tj-actions/changed-files@v45
with:
files: |
**.ipynb
- name: Build permalinks
id: build-permalinks
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |-
permalinks="<ul>"
for fullfile in ${ALL_CHANGED_FILES}; do
fullfile="${fullfile//\\&/&}"
commit=$(git rev-list -1 HEAD "$fullfile")
suffix="${fullfile//&/%26}"
url=${{ github.server_url }}/${{ github.repository }}/blob/$commit/$suffix
permalinks+="<li><a href=\"$url\">$url</a></li>"
done
permalinks+="</ul>"
echo "permalinks=$permalinks" >>"$GITHUB_OUTPUT"
- name: Build URLs
id: build-urls
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |-
permalinks="<ul>"
previews="<ul>"
for fullfile in ${ALL_CHANGED_FILES}; do
fullfile="${fullfile//\\&/&}"
commit=$(git rev-list -1 HEAD "$fullfile")
suffix="${fullfile//&/%26}"
permalink=${{ github.server_url }}/${{ github.repository }}/blob/$commit/$suffix
permalinks+="<li><a href=\"$permalink\">$permalink</a></li>"
suffix="${fullfile/.ipynb/.html}"
preview=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.number }}/$suffix
previews+="<li><a href=\"$preview\">$preview</a></li>"
done
permalinks+="</ul>"
echo "permalinks=$permalinks" >>"$GITHUB_OUTPUT"
previews+="</ul>"
echo "previews=$previews" >>"$GITHUB_OUTPUT"
- name: Comment PR with permalinks
uses: thollander/actions-comment-pull-request@v3
with:
message: |
**Permalinks:**
${{ steps.build-urls.outputs.permalinks }}
comment-tag: permalinks
- name: Comment PR with previews
uses: thollander/actions-comment-pull-request@v3
with:
message: |
**Previews:**
${{ steps.build-urls.outputs.previews }}
comment-tag: previews