-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (118 loc) · 4.49 KB
/
renderNotebooks.yaml
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
# Github action that renders R markdown when PR is opened
# All R markdown is run in container/rmd.Dockerfile
on:
pull_request:
types: [opened, reopened, edited]
push:
workflow_dispatch:
name: render-notebooks
jobs:
render-rmarkdown:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if Dockerfile changed
id: dockerfile-check
run: |
if git diff --name-only HEAD^ HEAD | grep -q 'container/rmd.Dockerfile'; then
echo "dockerfile_changed=true" >> $GITHUB_ENV
else
echo "dockerfile_changed=false" >> $GITHUB_ENV
fi
- name: Extract metadata (tags, labels) for Rmd Docker
id: meta_rmd
uses: docker/[email protected]
with:
images: bcgsc/long-pog-rmd
- name: Build and push Docker image
if: env.dockerfile_changed == 'true'
uses: docker/build-push-action@v5
with:
file: container/rmd.Dockerfile
context: .
push: true
tags: ${{ steps.meta_rmd.outputs.tags }}
labels: ${{ steps.meta_rmd.outputs.labels }}
- name: Run Docker container to compile changed R Markdown files
uses: addnab/docker-run-action@v3
with:
image: ${{ steps.meta_rmd.outputs.tags }}
options: -v ${{ github.workspace }}:/workspace --rm -u root
run: |
CHANGED_RMD_FILES=$(git diff --name-only HEAD^ HEAD -- '*.Rmd' '*.rmd')
if [ -n "$CHANGED_RMD_FILES" ]; then
echo "Changed R Markdown files:"
echo "$CHANGED_RMD_FILES"
for RMD in $CHANGED_RMD_FILES; do
Rscript -e 'for (f in commandArgs(TRUE)) if (file.exists(f)) rmarkdown::render(f, output_format = "all")' /workspace/$RMD
done
else
echo "No changed R Markdown files found. Skipping execution."
fi
- name: Run Docker container to compile assets
uses: addnab/docker-run-action@v3
with:
image: ${{ steps.meta_rmd.outputs.tags }}
options: -v ${{ github.workspace }}:/workspace --rm -u root
run: |
RMD_FILES=$( find /workspace -name "*Rmd" -o -name "*rmd" )
if [ -n "$RMD_FILES" ]; then
echo $RMD_FILES
for RMD in $RMD_FILES
do
Rscript -e 'for (f in commandArgs(TRUE)) if (file.exists(f)) rmarkdown::render(f, output_format = "all")' $RMD
done
else
echo "No R markdown found. Skipping execution."
- uses: stefanzweifel/git-auto-commit-action@v5
render_jupyter:
runs-on: ubuntu-latest
needs: render-rmarkdown
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check if Dockerfile changed
id: dockerfile-check
run: |
if git diff --name-only HEAD^ HEAD | grep -q 'container/jupyter.Dockerfile'; then
echo "dockerfile_changed=true" >> $GITHUB_ENV
else
echo "dockerfile_changed=false" >> $GITHUB_ENV
fi
- name: Extract metadata (tags, labels) for Jupyter Docker
id: meta_jupyter
uses: docker/[email protected]
with:
images: bcgsc/long-pog-jupyter
- name: Build and push Docker image
if: env.dockerfile_changed == 'true'
uses: docker/build-push-action@v5
with:
file: container/jupyter.Dockerfile
context: .
push: true
tags: ${{ steps.meta_jupyter.outputs.tags }}
labels: ${{ steps.meta_jupyter.outputs.labels }}
- name: Run Docker container to compile JupyterNotebook
uses: addnab/docker-run-action@v3
with:
image: ${{ steps.meta_jupyter.outputs.tags }}
options: -v ${{ github.workspace }}:/workspace --rm -u root
run: |
changed_notebooks=$(git diff --name-only HEAD^ HEAD -- '*.ipynb')
if [ -n "$changed_notebooks" ]; then
echo "Changed notebooks:"
echo "$changed_notebooks"
for notebook in $changed_notebooks; do
jupyter nbconvert --to html --execute /workspace/$notebook
jupyter nbconvert --to markdown --execute /workspace/$notebook
done
else
echo "No changed Jupyter notebooks found. Skipping execution."
fi
- uses: stefanzweifel/git-auto-commit-action@v5