-
Notifications
You must be signed in to change notification settings - Fork 85
133 lines (115 loc) · 3.93 KB
/
ci_html_build.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
name: Build HTML on merge
on:
pull_request_target:
types: [closed]
paths:
- '**.ipynb'
env:
CASJOBS_PW: ${{ secrets.CASJOBS_PW }}
CASJOBS_USERID: ${{ secrets.CASJOBS_USERID }}
jobs:
prepare_matrix:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- id: set-matrix
run: |
files=$(git diff --name-only ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} '*.ipynb')
#files_json=$(echo $files | jq -R -s -c 'split("\n")[:-1]')
files_json=$(echo "$files" | jq -R -s -c 'split("\n")[:-1]')
echo "::set-output name=matrix::${files_json}"
execute-notebooks:
if: github.event.pull_request.merged == true
needs: prepare_matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
notebook: ${{fromJson(needs.prepare_matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: ${{ vars.PYTHON_VERSION }}
- name: Install Dependencies (if requirements.txt exists) and Execute Notebook
run: |
notebook="${{ matrix.notebook }}"
dir=$(dirname "$notebook")
if [ -f "$dir/requirements.txt" ]; then
pip install -r "$dir/requirements.txt"
fi
pip install notebook
jupyter nbconvert --to notebook --execute --inplace "$notebook"
- name: Commit modified file on current branch
run: |
git config user.name 'CI Bot'
git config user.email 'action@github.com'
git add "${{ matrix.notebook }}"
git commit -m "Storing executed notebook ${{ matrix.notebook }}"
- name: Checkout only the file to the target branch
run: |
git fetch
git pull
git checkout -f gh-storage
git checkout @{-1} "${{ matrix.notebook }}"
- name: Commit and push modifications to target branch
run: |
git commit -m "Storing executed notebook ${{ matrix.notebook }}"
MAX_RETRIES=5
RETRY_DELAY=10s
for i in $(seq 1 $MAX_RETRIES); do
git push origin gh-storage --force && break || {
echo "Push $i failed... waiting $RETRY_DELAY"
sleep $RETRY_DELAY
}
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
generate_html:
if: github.event.pull_request.merged == true
needs: execute-notebooks
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ vars.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ vars.PYTHON_VERSION }}
- name: Install dependencies
run: |
pip install ghp-import
pip install jupyter-book==v0.15.1
pip install myst-nb
pip install astroid
pip install nbval
#pip install bs4
#pip install lxml
## test to bypass the jupyter-book lower version
pip install jsonschema==4.6.0
PATH="${PATH}:${HOME}/.local/bin"
- name: Build HTML
run: |
git fetch
git checkout origin/gh-storage -- notebooks/
jupyter-book build .
- name: Execute JDAVIZ placeholder substitution
run: |
cp jdaviz_placeholder_new.png _build/html
chmod +x placeholder.sh
./placeholder.sh
# Push the book's HTML to github-pages
- name: GitHub Pages action
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_build/html