-
Notifications
You must be signed in to change notification settings - Fork 1
138 lines (133 loc) · 6.29 KB
/
deploy.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
on:
push:
branches:
- staging
- master
pull_request:
branches:
- staging
- master
workflow_dispatch:
# Only allow one such workflow to run at a time
# (since the supplied VirES tokens will only allow 2 max async jobs)
concurrency:
group: ${{ github.workflow }}
env:
DOCKER_IMAGE: 'registry.gitlab.eox.at/esa/vires_vre_ops/vre-swarm-notebook'
PRODUCTION_TAG: '1.0.1'
STAGING_TAG: '1.0.1'
jobs:
book:
name: Build Jupyter Book
runs-on: ubuntu-latest
steps:
- name: Set run references (to switch master/staging/pr behaviour), and target docker image
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
RUN_REF="pr${{ github.event.number }}"
BRANCH_NAME="${{ github.event.pull_request.base.ref }}"
NETLIFY_ALIAS="${{ github.sha }}"
GH_DEPLOY_ENV="pull request"
ENABLE_GH_DEPLOY="false"
elif [ "${{ github.event_name }}" == "push" ]; then
RUN_REF=$(echo "${{ github.ref }}" | sed 's|.*/||')
BRANCH_NAME=${RUN_REF}
NETLIFY_ALIAS="preview-${BRANCH_NAME}"
GH_DEPLOY_ENV="${BRANCH_NAME}"
ENABLE_GH_DEPLOY="true"
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
RUN_REF=$(echo "${{ github.ref }}" | sed 's|.*/||')
BRANCH_NAME="${{ github.ref }}"
NETLIFY_ALIAS="preview-${BRANCH_NAME}"
GH_DEPLOY_ENV="${BRANCH_NAME}"
ENABLE_GH_DEPLOY=$(if [[ "$BRANCH_NAME" == "master" || "$BRANCH_NAME" == "staging" ]]; then echo "true"; else echo "false"; fi)
fi
if [ "$BRANCH_NAME" == "master" ]; then
RESOLVED_DOCKER_IMAGE="${{ env.DOCKER_IMAGE }}:${{ env.PRODUCTION_TAG }}"
else
RESOLVED_DOCKER_IMAGE="${{ env.DOCKER_IMAGE }}:${{ env.STAGING_TAG }}"
fi
echo "RUN_REF=${RUN_REF}" >> $GITHUB_ENV
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
echo "NETLIFY_ALIAS=${NETLIFY_ALIAS}" >> $GITHUB_ENV
echo "GH_DEPLOY_ENV=${GH_DEPLOY_ENV}" >> $GITHUB_ENV
echo "ENABLE_GH_DEPLOY=${ENABLE_GH_DEPLOY}" >> $GITHUB_ENV
echo "RESOLVED_DOCKER_IMAGE=${RESOLVED_DOCKER_IMAGE}" >> $GITHUB_ENV
- name: Pull the relevant docker image
run: |
echo ${{ secrets.EOX_REGISTRY_PASSWORD }} | docker login -u ${{ secrets.EOX_REGISTRY_USER }} --password-stdin registry.gitlab.eox.at
docker pull ${{ env.RESOLVED_DOCKER_IMAGE }}
- uses: actions/checkout@v4
- name: Add bookbuilder environment to container
run: |
docker run --name temp-container -v $GITHUB_WORKSPACE:/home/jovyan -u root ${{ env.RESOLVED_DOCKER_IMAGE }} \
bash -c \
'
mamba run --no-capture-output -n base python -m ipykernel install --user --name base && \
mamba create --name bookbuilder --file .bookbuilder/conda-linux-64.lock
'
docker commit temp-container ${{ env.DOCKER_IMAGE }}:customized
- name: Execute notebooks using nbmake (staging / other)
if: env.BRANCH_NAME != 'master'
run: |
docker run -v $GITHUB_WORKSPACE:/home/jovyan -u root \
-e VIRES_TOKEN=${{ secrets.VIRES_TOKEN }} \
-e VIRES_TOKEN_STAGING=${{ secrets.VIRES_TOKEN_STAGING }} \
-e VIRES_TOKEN_STAGING_DISC=${{ secrets.VIRES_TOKEN_STAGINGDISC}} \
${{ env.DOCKER_IMAGE }}:customized \
bash -c \
'
export CDF_LIB=/opt/conda/lib && \
pip install --upgrade 'git+https://github.com/ESA-VirES/VirES-Python-Client@staging#egg=viresclient' && \
viresclient set_token https://vires.services/ows $VIRES_TOKEN && \
viresclient set_token https://staging.vires.services/ows $VIRES_TOKEN_STAGING && \
viresclient set_token https://staging.viresdisc.vires.services/ows $VIRES_TOKEN_STAGING_DISC && \
viresclient set_default_server https://vires.services/ows && \
mamba run -n bookbuilder pytest --numprocesses 2 --nbmake --overwrite --nbmake-kernel=base \
notebooks/*.ipynb \
--deselect=notebooks/04c1_Geomag-Ground-Data-FTP.ipynb
'
- name: Execute notebooks using nbmake (production)
if: env.BRANCH_NAME == 'master'
run: |
docker run -v $GITHUB_WORKSPACE:/home/jovyan -u root \
-e VIRES_TOKEN=${{ secrets.VIRES_TOKEN }} \
${{ env.DOCKER_IMAGE }}:customized \
bash -c \
'
export CDF_LIB=/opt/conda/lib && \
viresclient set_token https://vires.services/ows $VIRES_TOKEN && \
viresclient set_default_server https://vires.services/ows && \
mamba run -n bookbuilder pytest --numprocesses 2 --nbmake --overwrite --nbmake-kernel=base \
notebooks/*.ipynb \
--deselect=notebooks/04c1_Geomag-Ground-Data-FTP.ipynb
'
- name: Build book
if: always()
run: |
docker run -v $GITHUB_WORKSPACE:/home/jovyan -u root ${{ env.DOCKER_IMAGE }}:customized \
bash -c \
'
mamba run -n bookbuilder jupyter-book build --config _config-ci-${{ env.BRANCH_NAME }}.yml .
'
- name: Deploy preview to Netlify
if: always()
uses: nwtgck/[email protected]
with:
publish-dir: './_build/html'
production-deploy: false
github-token: ${{ secrets.GITHUB_TOKEN }}
# RUN_REF is set to one of "master", "staging", "pr#"
deploy-message: "Deploy from GitHub Actions (${{ env.RUN_REF }})"
# Alias is used in netlify URL
# This is set to one of: "preview-master", "preview-staging", git sha
alias: ${{ env.NETLIFY_ALIAS }}
# Github deployment environment is one of "master", "staging"
enable-github-deployment: ${{ env.ENABLE_GH_DEPLOY }}
github-deployment-environment: ${{ env.GH_DEPLOY_ENV }}
enable-pull-request-comment: true
enable-commit-comment: true
overwrites-pull-request-comment: true
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_API_ID }}