-
Notifications
You must be signed in to change notification settings - Fork 1
166 lines (143 loc) · 6.05 KB
/
execute_notebooks.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Execute the jupyter notebooks, push them to dedicate branches,
# and trigger ReadTheDocs in the linked repository.
# This workflow was largely inspired by the following wradlib-notebooks CI task:
# https://github.com/wradlib/wradlib-notebooks/blob/main/.github/workflows/main.yml
name: Execute jupyter notebooks
env:
# URL for the external repository linked with the notebooks in this project.
LINKED_REPO: pySTEPS/pysteps
on:
push:
branches: [ main, dev ]
pull_request:
branches: [ main, dev ]
jobs:
run_notebooks:
name: Execute jupyter notebooks
runs-on: "ubuntu-latest"
defaults:
run:
shell: bash -l {0}
outputs:
rtd_branch: ${{steps.get_nb_render_branch.outputs.render_branch}}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install mamba and create environment
uses: mamba-org/provision-with-micromamba@main
with:
environment-file: environment.yml
environment-name: doc_builder
extra-specs: python=3.8
- name: Checkout linked repository
uses: actions/checkout@v2
with:
repository: ${{ env.LINKED_REPO }}
path: ${{ env.LINKED_REPO }}
- name: Install package from the linked repository
working-directory: ${{ env.LINKED_REPO }}
run: |
pip install .
# Since actions/checkout@v2 only checkouts a single commit without tags let's fetch the tags
git fetch --all --tags
git log HEAD
- name: Install pysteps-data
run: |
python ci/fetch_pysteps_data.py $HOME/pysteps_data
python -c "import pysteps; print(pysteps.config_fname())"
- name: Determine destination branch for the rendered notebooks and the RTD branch
id: get_nb_render_branch
working-directory: ${{ env.LINKED_REPO }}
run: |
########################################
# Find the branch that trigger the event
if [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then
event_branch=$(echo ${GITHUB_REF##*/})
elif [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
event_branch=$(echo $GITHUB_BASE_REF)
else
event_branch=unknown
fi
echo "::set-output name=event_branch::${event_branch}"
####################################################################
# Check if the Linked repository current commit corresponds to a tag
LINKED_REPO_TAG=$(git name-rev --name-only --tags HEAD)
echo "::set-output name=linked_repo_tag::${LINKED_REPO_TAG}"
###################################
# Determine destination branch name
if [[ "${LINKED_REPO_TAG}" == "undefined" ]]; then
# Not a tagged version
if [[ "${event_branch}" == "dev" ]]; then
echo "::set-output name=render_branch::test"
else
echo "::set-output name=render_branch::latest"
fi
else
# Save tagged versions in their own branch
echo "::set-output name=render_branch::${LINKED_REPO_TAG}"
fi
- name: Execute notebooks
working-directory: ./notebooks
run: |
jupyter nbconvert --to notebook --inplace --execute ./*.ipynb
- name: Print debug information
env:
RENDER_BRANCH: ${{steps.get_nb_render_branch.outputs.render_branch}}
EVENT_BRANCH: ${{steps.get_nb_render_branch.outputs.event_branch}}
LINKED_REPO_TAG: ${{steps.get_nb_render_branch.outputs.linked_repo_tag}}
run: |
echo "EVENT_BRANCH=${EVENT_BRANCH}"
echo "LINKED_REPO_TAG=${LINKED_REPO_TAG}"
echo "GITHUB_SHA=${GITHUB_SHA}"
echo "RENDER_BRANCH=${RENDER_BRANCH}"
- name: Commit notebooks
env:
RENDER_BRANCH: ${{steps.get_nb_render_branch.outputs.render_branch}}
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
# Checkout changes in an orphan branch first.
# We want to update only the notebooks.
git checkout --orphan tmp
git reset
git add -A notebooks
git commit -m "Rendering $GITHUB_SHA"
# Clean rest of the files.
git clean -d -f -f
# Switch to destination branch
action=$(git ls-remote --exit-code --heads origin ${RENDER_BRANCH} > /dev/null || echo "push")
if [ "$action" != "push" ] ; then
git fetch origin ${RENDER_BRANCH}
# If it exits, merge the changes and push.
git merge --strategy=ours --allow-unrelated-histories origin/${RENDER_BRANCH} -m "Commit"
# Add changes to the RENDER_BRANCH.
git checkout -b ${RENDER_BRANCH} origin/${RENDER_BRANCH}
git merge --squash tmp
git commit --allow-empty -m "Rendering $GITHUB_SHA"
fi
#Otherwise, the next task will push the orpahn branch.
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{steps.get_nb_render_branch.outputs.render_branch}}
# trigger_rtd:
# # Task adapted from the wradlib project
# # https://github.com/wradlib/wradlib-notebooks/blob/main/.github/workflows/render_notebooks.yml
# needs: [run_notebooks]
# name: Trigger readthedocs
# runs-on: ubuntu-latest
# defaults:
# run:
# shell: bash -l {0}
# env:
# RTD_TOKEN: ${{ secrets.RTD_TOKEN }}
# RTD_URL: ${{ secrets.RTD_URL }}
# RTD_BRANCH: ${{ needs.run_notebooks.outputs.rtd_branch }}
# steps:
# - name: Trigger readthedocs for the corresponding branch (latest or tag)
# run: |
# # Ignore triggering if this workflow was triggered by the dev branch.
# if [[ "${RTD_BRANCH}" != "test" ]]; then
# curl -X POST -d "branches=${RTD_BRANCH}" -d "token=${RTD_TOKEN}" "${RTD_URL}"
# fi