Debian Codegraph @

.github/workflows/test.yml

raw
1 # This is a GitHub workflow defining a set of jobs with a set of steps.
2 # ref: https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
3 #
4 name: Test
5
6 on:
7 pull_request:
8 paths-ignore:
9 - "docs/**"
10 - "**.md"
11 - "**.rst"
12 - ".github/workflows/*"
13 - "!.github/workflows/test.yml"
14 push:
15 paths-ignore:
16 - "docs/**"
17 - "**.md"
18 - "**.rst"
19 - ".github/workflows/*"
20 - "!.github/workflows/test.yml"
21 branches-ignore:
22 - "dependabot/**"
23 - "pre-commit-ci-update-config"
24 tags:
25 - "**"
26 workflow_dispatch:
27
28 env:
29 # UTF-8 content may be interpreted as ascii and causes errors without this.
30 LANG: C.UTF-8
31 SQLALCHEMY_WARN_20: "1"
32
33 permissions:
34 contents: read
35
36 jobs:
37 # Run "pytest jupyterhub/tests" in various configurations
38 pytest:
39 runs-on: ubuntu-22.04
40 timeout-minutes: 15
41
42 strategy:
43 # Keep running even if one variation of the job fail
44 fail-fast: false
45 matrix:
46 # We run this job multiple times with different parameterization
47 # specified below, these parameters have no meaning on their own and
48 # gain meaning on how job steps use them.
49 #
50 # subdomain:
51 # Tests everything when JupyterHub is configured to add routes for
52 # users with dedicated subdomains like user1.jupyter.example.com
53 # rather than jupyter.example.com/user/user1.
54 #
55 # db: [mysql/postgres]
56 # Tests everything when JupyterHub works against a dedicated mysql or
57 # postgresql server.
58 #
59 # legacy_notebook:
60 # Tests everything when the user instances are started with
61 # the legacy notebook server instead of jupyter_server.
62 #
63 # ssl:
64 # Tests everything using internal SSL connections instead of
65 # unencrypted HTTP
66 #
67 # main_dependencies:
68 # Tests everything when we use the latest available dependencies
69 # from: traitlets.
70 #
71 # NOTE: Since only the value of these parameters are presented in the
72 # GitHub UI when the workflow run, we avoid using true/false as
73 # values by instead duplicating the name to signal true.
74 # Python versions available at:
75 # https://github.com/actions/python-versions/blob/HEAD/versions-manifest.json
76 include:
77 - python: "3.8"
78 oldest_dependencies: oldest_dependencies
79 legacy_notebook: legacy_notebook
80 - python: "3.8"
81 jupyter_server: "1.*"
82 subset: singleuser
83 - python: "3.9"
84 db: mysql
85 - python: "3.10"
86 db: postgres
87 - python: "3.12"
88 subdomain: subdomain
89 serverextension: serverextension
90 - python: "3.11"
91 ssl: ssl
92 serverextension: serverextension
93 - python: "3.11"
94 jupyverse: jupyverse
95 subset: singleuser
96 - python: "3.11"
97 subdomain: subdomain
98 noextension: noextension
99 subset: singleuser
100 - python: "3.11"
101 ssl: ssl
102 noextension: noextension
103 subset: singleuser
104 - python: "3.11"
105 browser: browser
106 - python: "3.11"
107 subdomain: subdomain
108 browser: browser
109 - python: "3.12"
110 main_dependencies: main_dependencies
111
112 steps:
113 # NOTE: In GitHub workflows, environment variables are set by writing
114 # assignment statements to a file. They will be set in the following
115 # steps as if would used `export MY_ENV=my-value`.
116 - name: Configure environment variables
117 run: |
118 if [ "${{ matrix.subdomain }}" != "" ]; then
119 echo "JUPYTERHUB_TEST_SUBDOMAIN_HOST=http://localhost.jovyan.org:8000" >> $GITHUB_ENV
120 fi
121 if [ "${{ matrix.db }}" == "mysql" ]; then
122 echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV
123 echo "JUPYTERHUB_TEST_DB_URL=mysql+mysqldb://[email protected]:3306/jupyterhub" >> $GITHUB_ENV
124 fi
125 if [ "${{ matrix.ssl }}" == "ssl" ]; then
126 echo "SSL_ENABLED=1" >> $GITHUB_ENV
127 fi
128 if [ "${{ matrix.db }}" == "postgres" ]; then
129 echo "PGHOST=127.0.0.1" >> $GITHUB_ENV
130 echo "PGUSER=test_user" >> $GITHUB_ENV
131 echo "PGPASSWORD=hub[test/:?" >> $GITHUB_ENV
132 echo "JUPYTERHUB_TEST_DB_URL=postgresql://test_user:hub%5Btest%2F%3A%[email protected]:5432/jupyterhub" >> $GITHUB_ENV
133 fi
134 if [ "${{ matrix.serverextension }}" != "" ]; then
135 echo "JUPYTERHUB_SINGLEUSER_EXTENSION=1" >> $GITHUB_ENV
136 elif [ "${{ matrix.noextension }}" != "" ]; then
137 echo "JUPYTERHUB_SINGLEUSER_EXTENSION=0" >> $GITHUB_ENV
138 fi
139 if [ "${{ matrix.jupyverse }}" != "" ]; then
140 echo "JUPYTERHUB_SINGLEUSER_APP=jupyverse" >> $GITHUB_ENV
141 fi
142 - uses: actions/checkout@v4
143 # NOTE: actions/setup-node@v4 make use of a cache within the GitHub base
144 # environment and setup in a fraction of a second.
145 - name: Install Node
146 uses: actions/setup-node@v4
147 with:
148 node-version: "20"
149 - name: Install Javascript dependencies
150 run: |
151 npm install
152 npm install -g configurable-http-proxy yarn
153 npm list
154
155 # NOTE: actions/setup-python@v5 make use of a cache within the GitHub base
156 # environment and setup in a fraction of a second.
157 - name: Install Python ${{ matrix.python }}
158 uses: actions/setup-python@v5
159 with:
160 python-version: "${{ matrix.python }}"
161 cache: pip
162 cache-dependency-path: |
163 pyproject.toml
164 requirements.txt
165 ci/oldest-dependencies/requirements.old
166
167 - name: Install Python dependencies
168 run: |
169 pip install --upgrade pip
170
171 if [ "${{ matrix.oldest_dependencies }}" != "" ]; then
172 # frozen env with oldest dependencies
173 # make sure our `>=` pins really do express our minimum supported versions
174 pip install -r ci/oldest-dependencies/requirements.old -e .
175 else
176 pip install --pre -e ".[test]"
177 fi
178
179 if [ "${{ matrix.main_dependencies }}" != "" ]; then
180 # Tests are broken:
181 # https://github.com/jupyterhub/jupyterhub/issues/4418
182 # pip install git+https://github.com/ipython/traitlets#egg=traitlets --force
183 pip install --upgrade --pre sqlalchemy
184 fi
185 if [ "${{ matrix.legacy_notebook }}" != "" ]; then
186 pip uninstall jupyter_server --yes
187 pip install 'notebook<7'
188 fi
189 if [ "${{ matrix.jupyter_server }}" != "" ]; then
190 pip install "jupyter_server==${{ matrix.jupyter_server }}"
191 fi
192 if [ "${{ matrix.jupyverse }}" != "" ]; then
193 pip install "jupyverse[jupyterlab,auth-jupyterhub]"
194 pip install -e .
195 fi
196 if [ "${{ matrix.db }}" == "mysql" ]; then
197 pip install mysqlclient
198 fi
199 if [ "${{ matrix.db }}" == "postgres" ]; then
200 pip install psycopg2-binary
201 fi
202 if [ "${{ matrix.serverextension }}" != "" ]; then
203 pip install 'jupyter-server>=2'
204 fi
205
206 pip freeze
207
208 # NOTE: If you need to debug this DB setup step, consider the following.
209 #
210 # 1. mysql/postgressql are database servers we start as docker containers,
211 # and we use clients named mysql/psql.
212 #
213 # 2. When we start a database server we need to pass environment variables
214 # explicitly as part of the `docker run` command. These environment
215 # variables are named differently from the similarly named environment
216 # variables used by the clients.
217 #
218 # - mysql server ref: https://hub.docker.com/_/mysql/
219 # - mysql client ref: https://dev.mysql.com/doc/refman/5.7/en/environment-variables.html
220 # - postgres server ref: https://hub.docker.com/_/postgres/
221 # - psql client ref: https://www.postgresql.org/docs/9.5/libpq-envars.html
222 #
223 # 3. When we connect, they should use 127.0.0.1 rather than the
224 # default way of connecting which leads to errors like below both for
225 # mysql and postgresql unless we set MYSQL_HOST/PGHOST to 127.0.0.1.
226 #
227 # - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
228 #
229 - name: Start a database server (${{ matrix.db }})
230 if: ${{ matrix.db }}
231 run: |
232 if [ "${{ matrix.db }}" == "mysql" ]; then
233 if [[ -z "$(which mysql)" ]]; then
234 sudo apt-get update
235 sudo apt-get install -y mysql-client
236 fi
237 DB=mysql bash ci/docker-db.sh
238 DB=mysql bash ci/init-db.sh
239 fi
240 if [ "${{ matrix.db }}" == "postgres" ]; then
241 if [[ -z "$(which psql)" ]]; then
242 sudo apt-get update
243 sudo apt-get install -y postgresql-client
244 fi
245 DB=postgres bash ci/docker-db.sh
246 DB=postgres bash ci/init-db.sh
247 fi
248
249 - name: Configure browser tests
250 if: matrix.browser
251 run: echo "PYTEST_ADDOPTS=$PYTEST_ADDOPTS -m browser" >> "${GITHUB_ENV}"
252
253 - name: Ensure browsers are installed for playwright
254 if: matrix.browser
255 run: python -m playwright install --with-deps
256
257 - name: Run pytest
258 run: |
259 pytest -k "${{ matrix.subset }}" --maxfail=2 --cov=jupyterhub jupyterhub/tests
260
261 - uses: codecov/codecov-action@v4
262
263 docker-build:
264 runs-on: ubuntu-22.04
265 timeout-minutes: 20
266
267 steps:
268 - uses: actions/checkout@v4
269
270 - name: build images
271 run: |
272 DOCKER_BUILDKIT=1 docker build -t jupyterhub/jupyterhub .
273 docker build -t jupyterhub/jupyterhub-onbuild onbuild
274 docker build -t jupyterhub/singleuser singleuser
275
276 - name: smoke test jupyterhub
277 run: |
278 docker run --rm -t jupyterhub/jupyterhub jupyterhub --help
279
280 - name: verify static files
281 run: |
282 docker run --rm -t -v $PWD/dockerfiles:/io jupyterhub/jupyterhub python3 /io/test.py