| 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 |
# Test build release artifacts (PyPI package, Docker images) and publish them on |
| 5 |
# pushed git tags. |
| 6 |
# |
| 7 |
name: Release |
| 8 |
|
| 9 |
on: |
| 10 |
pull_request: |
| 11 |
paths-ignore: |
| 12 |
- "docs/**" |
| 13 |
- "**.md" |
| 14 |
- "**.rst" |
| 15 |
- ".github/workflows/*" |
| 16 |
- "!.github/workflows/release.yml" |
| 17 |
push: |
| 18 |
paths-ignore: |
| 19 |
- "docs/**" |
| 20 |
- "**.md" |
| 21 |
- "**.rst" |
| 22 |
- ".github/workflows/*" |
| 23 |
- "!.github/workflows/release.yml" |
| 24 |
branches-ignore: |
| 25 |
- "dependabot/**" |
| 26 |
- "pre-commit-ci-update-config" |
| 27 |
tags: |
| 28 |
- "**" |
| 29 |
workflow_dispatch: |
| 30 |
|
| 31 |
jobs: |
| 32 |
build-release: |
| 33 |
runs-on: ubuntu-22.04 |
| 34 |
steps: |
| 35 |
- uses: actions/checkout@v4 |
| 36 |
- uses: actions/setup-python@v5 |
| 37 |
with: |
| 38 |
python-version: "3.11" |
| 39 |
cache: pip |
| 40 |
|
| 41 |
- uses: actions/setup-node@v4 |
| 42 |
with: |
| 43 |
node-version: "20" |
| 44 |
|
| 45 |
- name: install build requirements |
| 46 |
run: | |
| 47 |
npm install -g yarn |
| 48 |
pip install --upgrade pip |
| 49 |
pip install build |
| 50 |
pip freeze |
| 51 |
|
| 52 |
- name: build release |
| 53 |
run: | |
| 54 |
python -m build --sdist --wheel . |
| 55 |
ls -l dist |
| 56 |
|
| 57 |
- name: verify sdist |
| 58 |
run: | |
| 59 |
./ci/check_sdist.py dist/jupyterhub-*.tar.gz |
| 60 |
|
| 61 |
- name: verify data-files are installed where they are found |
| 62 |
run: | |
| 63 |
pip install dist/*.whl |
| 64 |
./ci/check_installed_data.py |
| 65 |
|
| 66 |
- name: verify sdist can be installed without npm/yarn |
| 67 |
run: | |
| 68 |
docker run --rm -v $PWD/dist:/dist:ro docker.io/library/python:3.9-slim-bullseye bash -c 'pip install /dist/jupyterhub-*.tar.gz' |
| 69 |
|
| 70 |
# ref: https://github.com/actions/upload-artifact#readme |
| 71 |
- uses: actions/upload-artifact@v4 |
| 72 |
with: |
| 73 |
name: jupyterhub-${{ github.sha }} |
| 74 |
path: "dist/*" |
| 75 |
if-no-files-found: error |
| 76 |
|
| 77 |
- name: Publish to PyPI |
| 78 |
if: startsWith(github.ref, 'refs/tags/') |
| 79 |
env: |
| 80 |
TWINE_USERNAME: __token__ |
| 81 |
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} |
| 82 |
run: | |
| 83 |
pip install twine |
| 84 |
twine upload --skip-existing dist/* |
| 85 |
|
| 86 |
publish-docker: |
| 87 |
runs-on: ubuntu-22.04 |
| 88 |
timeout-minutes: 30 |
| 89 |
|
| 90 |
services: |
| 91 |
# So that we can test this in PRs/branches |
| 92 |
local-registry: |
| 93 |
image: registry:2 |
| 94 |
ports: |
| 95 |
- 5000:5000 |
| 96 |
|
| 97 |
steps: |
| 98 |
- name: Should we push this image to a public registry? |
| 99 |
run: | |
| 100 |
if [ "${{ startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main') }}" = "true" ]; then |
| 101 |
echo "REGISTRY=quay.io/" >> $GITHUB_ENV |
| 102 |
else |
| 103 |
echo "REGISTRY=localhost:5000/" >> $GITHUB_ENV |
| 104 |
fi |
| 105 |
|
| 106 |
- uses: actions/checkout@v4 |
| 107 |
|
| 108 |
# Setup docker to build for multiple platforms, see: |
| 109 |
# https://github.com/docker/build-push-action/tree/v2.4.0#usage |
| 110 |
# https://github.com/docker/build-push-action/blob/v2.4.0/docs/advanced/multi-platform.md |
| 111 |
- name: Set up QEMU (for docker buildx) |
| 112 |
uses: docker/setup-qemu-action@v3 |
| 113 |
|
| 114 |
- name: Set up Docker Buildx (for multi-arch builds) |
| 115 |
uses: docker/setup-buildx-action@v3 |
| 116 |
with: |
| 117 |
# Allows pushing to registry on localhost:5000 |
| 118 |
driver-opts: network=host |
| 119 |
|
| 120 |
- name: Setup push rights to Docker Hub |
| 121 |
# This was setup by... |
| 122 |
# 1. Creating a [Robot Account](https://quay.io/organization/jupyterhub?tab=robots) in the JupyterHub |
| 123 |
# . Quay.io org |
| 124 |
# 2. Giving it enough permissions to push to the jupyterhub and singleuser images |
| 125 |
# 3. Putting the robot account's username and password in GitHub actions environment |
| 126 |
if: env.REGISTRY != 'localhost:5000/' |
| 127 |
run: | |
| 128 |
docker login -u "${{ secrets.QUAY_USERNAME }}" -p "${{ secrets.QUAY_PASSWORD }}" "${{ env.REGISTRY }}" |
| 129 |
docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" docker.io |
| 130 |
|
| 131 |
# image: jupyterhub/jupyterhub |
| 132 |
# |
| 133 |
# https://github.com/jupyterhub/action-major-minor-tag-calculator |
| 134 |
# If this is a tagged build this will return additional parent tags. |
| 135 |
# E.g. 1.2.3 is expanded to Docker tags |
| 136 |
# [{prefix}:1.2.3, {prefix}:1.2, {prefix}:1, {prefix}:latest] unless |
| 137 |
# this is a backported tag in which case the newer tags aren't updated. |
| 138 |
# For branches this will return the branch name. |
| 139 |
# If GITHUB_TOKEN isn't available (e.g. in PRs) returns no tags []. |
| 140 |
- name: Get list of jupyterhub tags |
| 141 |
id: jupyterhubtags |
| 142 |
uses: jupyterhub/action-major-minor-tag-calculator@v3 |
| 143 |
with: |
| 144 |
githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 145 |
prefix: >- |
| 146 |
${{ env.REGISTRY }}jupyterhub/jupyterhub: |
| 147 |
jupyterhub/jupyterhub: |
| 148 |
defaultTag: "${{ env.REGISTRY }}jupyterhub/jupyterhub:noref" |
| 149 |
branchRegex: ^\w[\w-.]*$ |
| 150 |
|
| 151 |
- name: Build and push jupyterhub |
| 152 |
uses: docker/build-push-action@v6 |
| 153 |
with: |
| 154 |
context: . |
| 155 |
platforms: linux/amd64,linux/arm64 |
| 156 |
push: true |
| 157 |
# tags parameter must be a string input so convert `gettags` JSON |
| 158 |
# array into a comma separated list of tags |
| 159 |
tags: ${{ join(fromJson(steps.jupyterhubtags.outputs.tags)) }} |
| 160 |
|
| 161 |
# image: jupyterhub/jupyterhub-onbuild |
| 162 |
# |
| 163 |
- name: Get list of jupyterhub-onbuild tags |
| 164 |
id: onbuildtags |
| 165 |
uses: jupyterhub/action-major-minor-tag-calculator@v3 |
| 166 |
with: |
| 167 |
githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 168 |
prefix: >- |
| 169 |
${{ env.REGISTRY }}jupyterhub/jupyterhub-onbuild: |
| 170 |
jupyterhub/jupyterhub-onbuild: |
| 171 |
defaultTag: "${{ env.REGISTRY }}jupyterhub/jupyterhub-onbuild:noref" |
| 172 |
branchRegex: ^\w[\w-.]*$ |
| 173 |
|
| 174 |
- name: Build and push jupyterhub-onbuild |
| 175 |
uses: docker/build-push-action@v6 |
| 176 |
with: |
| 177 |
build-args: | |
| 178 |
BASE_IMAGE=${{ fromJson(steps.jupyterhubtags.outputs.tags)[0] }} |
| 179 |
context: onbuild |
| 180 |
platforms: linux/amd64,linux/arm64 |
| 181 |
push: true |
| 182 |
tags: ${{ join(fromJson(steps.onbuildtags.outputs.tags)) }} |
| 183 |
|
| 184 |
# image: jupyterhub/jupyterhub-demo |
| 185 |
# |
| 186 |
- name: Get list of jupyterhub-demo tags |
| 187 |
id: demotags |
| 188 |
uses: jupyterhub/action-major-minor-tag-calculator@v3 |
| 189 |
with: |
| 190 |
githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 191 |
prefix: >- |
| 192 |
${{ env.REGISTRY }}jupyterhub/jupyterhub-demo: |
| 193 |
jupyterhub/jupyterhub-demo: |
| 194 |
defaultTag: "${{ env.REGISTRY }}jupyterhub/jupyterhub-demo:noref" |
| 195 |
branchRegex: ^\w[\w-.]*$ |
| 196 |
|
| 197 |
- name: Build and push jupyterhub-demo |
| 198 |
uses: docker/build-push-action@v6 |
| 199 |
with: |
| 200 |
build-args: | |
| 201 |
BASE_IMAGE=${{ fromJson(steps.onbuildtags.outputs.tags)[0] }} |
| 202 |
context: demo-image |
| 203 |
# linux/arm64 currently fails: |
| 204 |
# ERROR: Could not build wheels for argon2-cffi which use PEP 517 and cannot be installed directly |
| 205 |
# ERROR: executor failed running [/bin/sh -c python3 -m pip install notebook]: exit code: 1 |
| 206 |
platforms: linux/amd64 |
| 207 |
push: true |
| 208 |
tags: ${{ join(fromJson(steps.demotags.outputs.tags)) }} |
| 209 |
|
| 210 |
# image: jupyterhub/singleuser |
| 211 |
# |
| 212 |
- name: Get list of jupyterhub/singleuser tags |
| 213 |
id: singleusertags |
| 214 |
uses: jupyterhub/action-major-minor-tag-calculator@v3 |
| 215 |
with: |
| 216 |
githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 217 |
prefix: >- |
| 218 |
${{ env.REGISTRY }}jupyterhub/singleuser: |
| 219 |
jupyterhub/singleuser: |
| 220 |
defaultTag: "${{ env.REGISTRY }}jupyterhub/singleuser:noref" |
| 221 |
branchRegex: ^\w[\w-.]*$ |
| 222 |
|
| 223 |
- name: Build and push jupyterhub/singleuser |
| 224 |
uses: docker/build-push-action@v6 |
| 225 |
with: |
| 226 |
build-args: | |
| 227 |
JUPYTERHUB_VERSION=${{ github.ref_type == 'tag' && github.ref_name || format('git:{0}', github.sha) }} |
| 228 |
context: singleuser |
| 229 |
platforms: linux/amd64,linux/arm64 |
| 230 |
push: true |
| 231 |
tags: ${{ join(fromJson(steps.singleusertags.outputs.tags)) }} |