Skip to content

Commit b4ca353

Browse files
committed
deploy from github actions
1 parent 888719a commit b4ca353

File tree

8 files changed

+170
-12
lines changed

8 files changed

+170
-12
lines changed

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pypi"
4+
directory: "/"
5+
# needed to update requirements.txt
6+
allow:
7+
- dependency-type: all
8+
schedule:
9+
interval: "monthly"
10+
open-pull-requests-limit: 3
11+
- package-ecosystem: "github-actions"
12+
directory: "/"
13+
schedule:
14+
interval: "monthly"
15+
open-pull-requests-limit: 3

.github/workflows/cd.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Continuous Deployment
2+
3+
# only allow one deploy workflow to be running at a time
4+
# serializes multiple outstanding deploys if PRs are merged before the last deploy finishes
5+
# ref: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency
6+
concurrency: deploy
7+
8+
# Only trigger the workflow when pushing to master or a label is applied to a
9+
# Pull Request
10+
on:
11+
push:
12+
branches:
13+
- main
14+
paths-ignore:
15+
- "*.md"
16+
- .pre-commit-config.yaml
17+
- .github/**
18+
- "!.github/workflows/cd.yml"
19+
20+
# Global environment variables
21+
env:
22+
KUBECTL_VERSION: "v1.29.15"
23+
HELM_VERSION: "v3.12.0"
24+
KUBECONFIG: secrets/ovh-kubeconfig.yaml
25+
26+
jobs:
27+
# In this dedicated job to deploy our staging environment we build and push
28+
# images that the jobs to deploy to the production environments depend on.
29+
deploy:
30+
runs-on: ubuntu-24.04
31+
32+
steps:
33+
- name: Checkout repo
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Setup Python
39+
uses: actions/setup-python@v5
40+
with:
41+
python-version: "3.13"
42+
cache: pip
43+
44+
- name: "Stage 1: Install dependencies"
45+
run: |
46+
pip install --upgrade setuptools pip
47+
pip install --upgrade -r requirements.txt
48+
49+
- name: "Stage 1: Install kubectl ${{ env.KUBECTL_VERSION }}"
50+
uses: azure/setup-kubectl@v4
51+
with:
52+
version: ${{ env.KUBECTL_VERSION }}
53+
54+
- name: "Stage 1: Install and setup helm ${{ env.HELM_VERSION }}"
55+
run: |
56+
curl -sf https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | DESIRED_VERSION=${HELM_VERSION} bash
57+
58+
- name: Unlock git-crypt secrets
59+
uses: sliteteam/github-action-git-crypt-unlock@f99c0c6b60bb7ec30dcec033a8f0a3b3d48f21e1
60+
env:
61+
GIT_CRYPT_KEY: ${{ secrets.GIT_CRYPT_KEY }}
62+
63+
- name: get nbviewer chart
64+
run: |
65+
git clone https://github.com/jupyter/nbviewer
66+
cd nbviewer
67+
git reset "${NBVIEWER_VERSION}" --hard
68+
git log -1
69+
70+
- name: deploy
71+
run: |
72+
bash deploy.sh
73+
74+
- name: "Test"
75+
run: |
76+
pytest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ coverage.xml
5252
# Sphinx documentation
5353
docs/_build/
5454

55+
.ipynb_checkpoints
56+
.DS_Store

deploy.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,29 @@ set -euo pipefail
44
# TODO: move this to CI, don't make assumptions about local repo checkouts
55

66
export KUBECONFIG=$PWD/secrets/ovh-kubeconfig.yaml
7-
nbviewer_chart="../nbviewer/helm-chart/nbviewer"
8-
echo "Is $PWD/../nbviewer up to date?"
7+
8+
nbviewer_chart="${NBVIEWER_CHART:-../nbviewer/helm-chart/nbviewer}"
9+
echo "Is $nbviewer_chart up to date?"
910
helm dep up $nbviewer_chart
1011

1112
upgrade="upgrade nbviewer $nbviewer_chart -f config/nbviewer.yaml -f secrets/config/nbviewer.yaml"
1213
helm diff -C 5 $upgrade
14+
exit 1
1315

14-
echo "Deploy these changes? (y|[N]) "
15-
read confirm
16+
if [[ -z "${CI:-}" ]]; then
17+
echo "Deploy these changes? (y|[N]) "
18+
read confirm
1619

17-
if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then
18-
echo "Upgrading..."
19-
helm $upgrade
20-
else
21-
echo "Cancelled"
22-
exit 1
20+
if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then
21+
echo "confirmed"
22+
else
23+
echo "Cancelled"
24+
exit 1
25+
fi
2326
fi
2427

28+
echo "Upgrading..."
29+
helm $upgrade --cleanup-on-fail
30+
2531
# watch deployment rollout
2632
kubectl rollout status -w deployment/nbviewer

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
[project]
3+
name = "nbviewer.org-deploy"
4+
5+
[tool.pytest.ini_options]
6+
addopts = "-v"
7+
testpaths = [
8+
"tests",
9+
]

requirements.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pytest
2+
requests

requirements.txt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
1-
invoke>=0.13
2-
requests
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.12
3+
# by the following command:
4+
#
5+
# pip-compile
6+
#
7+
certifi==2025.8.3
8+
# via requests
9+
charset-normalizer==3.4.3
10+
# via requests
11+
idna==3.10
12+
# via requests
13+
iniconfig==2.1.0
14+
# via pytest
15+
packaging==25.0
16+
# via pytest
17+
pluggy==1.6.0
18+
# via pytest
19+
pygments==2.19.2
20+
# via pytest
21+
pytest==8.4.2
22+
# via -r requirements.in
23+
requests==2.32.5
24+
# via -r requirements.in
25+
urllib3==2.5.0
26+
# via requests

tests/test_nbviewer.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
import requests
3+
from bs4 import BeautifulSoup
4+
5+
6+
NBVIEWER = "https://nbviewer.org"
7+
8+
frontpage_request = requests.get(NBVIEWER)
9+
frontpage = BeautifulSoup(frontpage_request.text, "html.parser")
10+
frontpage_links = frontpage.find_all("a", class_="thumbnail")
11+
frontpage_urls = [a["href"] for a in frontpage_links]
12+
13+
14+
def test_main_page():
15+
frontpage_request.raise_for_status()
16+
assert frontpage_request.status_code == 200
17+
assert len(frontpage_urls) > 5
18+
19+
20+
@pytest.mark.parametrize("path", frontpage_urls)
21+
def test_front_page(path):
22+
url = f"{NBVIEWER}{path}"
23+
r = requests.get(url)
24+
assert r.status_code == 200

0 commit comments

Comments
 (0)