-
Notifications
You must be signed in to change notification settings - Fork 95
140 lines (119 loc) · 4.49 KB
/
tutorial_exporter.yml
File metadata and controls
140 lines (119 loc) · 4.49 KB
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
name: "Export Tutorials"
on:
workflow_dispatch:
push:
branches:
- "dev"
- "master"
paths:
- 'tutorials/**/*.ipynb'
jobs:
# run on push
export_tutorials_on_push:
if: ${{ github.event_name == 'push' }}
permissions: write-all
runs-on: ubuntu-latest
env:
TUTORIAL_TIMEOUT: 1200s
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
# Dependencies for tutorials
python3 -m pip install --upgrade pip .[tutorial] black[jupyter]
- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v2
- id: files
uses: jitterbit/get-changed-files@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
format: space-delimited
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- name: Run formatter
run: black tutorials/
- name: Export tutorials to .py and .html
run: |
set -x
for file in ${{ steps.files.outputs.all }}; do
if [[ $file == *.ipynb ]]; then
filename=$(basename $file)
pyfilename=$(echo ${filename%?????})py
timeout --signal=SIGKILL $TUTORIAL_TIMEOUT python -Xfrozen_modules=off -m jupyter nbconvert $file --to python --output $pyfilename --output-dir=$(dirname $file)
htmlfilename=$(echo ${filename%?????} | sed -e 's/-//g')html
htmldir="docs/source"/$(echo ${file%??????????????} | sed -e 's/-//g')
timeout --signal=SIGKILL $TUTORIAL_TIMEOUT python -Xfrozen_modules=off -m jupyter nbconvert --execute $file --to html --output $htmlfilename --output-dir=$htmldir
fi
done
set +x
- uses: benjlevesque/short-sha@v2.1
id: short-sha
- name: Remove unwanted files
run: |
rm -rf build/ tutorials/tutorial4/data/
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5.0.2
with:
labels: maintenance
title: Export tutorial changed in ${{ steps.short-sha.outputs.sha }}
branch: export-tutorial-${{ steps.short-sha.outputs.sha }}
base: ${{ github.head_ref }}
commit-message: export tutorials changed in ${{ steps.short-sha.outputs.sha }}
delete-branch: true
# run on workflow_dispatch
export_tutorials_workflow_dispatch:
if: ${{ github.event_name == 'workflow_dispatch' }}
permissions: write-all
runs-on: ubuntu-latest
env:
TUTORIAL_TIMEOUT: 1200s
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip .[tutorial] black[jupyter]
- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v2
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- name: Run formatter
run: black tutorials/
- name: Export all tutorials to .py and .html
run: |
set -x
# Find all .ipynb files in the tutorials directory
for file in $(find tutorials -type f -name "*.ipynb"); do
filename=$(basename $file)
pyfilename="${filename%.ipynb}.py"
timeout --signal=SIGKILL $TUTORIAL_TIMEOUT python -Xfrozen_modules=off -m jupyter nbconvert $file --to python --output $pyfilename --output-dir=$(dirname $file)
htmlfilename="${filename%.ipynb}.html"
htmldir="docs/source"/$(dirname $file)
timeout --signal=SIGKILL $TUTORIAL_TIMEOUT python -Xfrozen_modules=off -m jupyter nbconvert --execute $file --to html --output $htmlfilename --output-dir=$htmldir
done
set +x
- uses: benjlevesque/short-sha@v2.1
id: short-sha
- name: Remove unwanted files
run: |
rm -rf build/ tutorials/tutorial4/data/
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5.0.2
with:
labels: maintenance
title: Export tutorial changed in ${{ steps.short-sha.outputs.sha }}
branch: export-tutorial-${{ steps.short-sha.outputs.sha }}
base: ${{ github.head_ref }}
commit-message: export tutorials changed in ${{ steps.short-sha.outputs.sha }}
delete-branch: true