|
| 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-20.04 |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v2 |
| 36 | + - uses: actions/setup-python@v2 |
| 37 | + with: |
| 38 | + python-version: 3.8 |
| 39 | + |
| 40 | + - uses: actions/setup-node@v1 |
| 41 | + with: |
| 42 | + node-version: "14" |
| 43 | + |
| 44 | + - name: install build package |
| 45 | + run: | |
| 46 | + pip install --upgrade pip |
| 47 | + pip install build |
| 48 | + pip freeze |
| 49 | +
|
| 50 | + - name: build release |
| 51 | + run: | |
| 52 | + python -m build --sdist --wheel . |
| 53 | + ls -l dist |
| 54 | +
|
| 55 | + - name: verify wheel |
| 56 | + run: | |
| 57 | + cd dist |
| 58 | + pip install ./*.whl |
| 59 | + # verify data-files are installed where they are found |
| 60 | + cat <<EOF | python |
| 61 | + import os |
| 62 | + from jupyterhub._data import DATA_FILES_PATH |
| 63 | + print(f"DATA_FILES_PATH={DATA_FILES_PATH}") |
| 64 | + assert os.path.exists(DATA_FILES_PATH), DATA_FILES_PATH |
| 65 | + for subpath in ( |
| 66 | + "templates/page.html", |
| 67 | + "static/css/style.min.css", |
| 68 | + "static/components/jquery/dist/jquery.js", |
| 69 | + ): |
| 70 | + path = os.path.join(DATA_FILES_PATH, subpath) |
| 71 | + assert os.path.exists(path), path |
| 72 | + print("OK") |
| 73 | + EOF |
| 74 | +
|
| 75 | + # ref: https://github.com/actions/upload-artifact#readme |
| 76 | + - uses: actions/upload-artifact@v2 |
| 77 | + with: |
| 78 | + name: jupyterhub-${{ github.sha }} |
| 79 | + path: "dist/*" |
| 80 | + if-no-files-found: error |
| 81 | + |
| 82 | + - name: Publish to PyPI |
| 83 | + if: startsWith(github.ref, 'refs/tags/') |
| 84 | + env: |
| 85 | + TWINE_USERNAME: __token__ |
| 86 | + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} |
| 87 | + run: | |
| 88 | + pip install twine |
| 89 | + twine upload --skip-existing dist/* |
| 90 | +
|
| 91 | + publish-docker: |
| 92 | + runs-on: ubuntu-20.04 |
| 93 | + |
| 94 | + services: |
| 95 | + # So that we can test this in PRs/branches |
| 96 | + local-registry: |
| 97 | + image: registry:2 |
| 98 | + ports: |
| 99 | + - 5000:5000 |
| 100 | + |
| 101 | + steps: |
| 102 | + - name: Should we push this image to a public registry? |
| 103 | + run: | |
| 104 | + if [ "${{ startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main') }}" = "true" ]; then |
| 105 | + # Empty => Docker Hub |
| 106 | + echo "REGISTRY=" >> $GITHUB_ENV |
| 107 | + else |
| 108 | + echo "REGISTRY=localhost:5000/" >> $GITHUB_ENV |
| 109 | + fi |
| 110 | +
|
| 111 | + - uses: actions/checkout@v2 |
| 112 | + |
| 113 | + # Setup docker to build for multiple platforms, see: |
| 114 | + # https://github.com/docker/build-push-action/tree/v2.4.0#usage |
| 115 | + # https://github.com/docker/build-push-action/blob/v2.4.0/docs/advanced/multi-platform.md |
| 116 | + - name: Set up QEMU (for docker buildx) |
| 117 | + uses: docker/setup-qemu-action@25f0500ff22e406f7191a2a8ba8cda16901ca018 # associated tag: v1.0.2 |
| 118 | + |
| 119 | + - name: Set up Docker Buildx (for multi-arch builds) |
| 120 | + uses: docker/setup-buildx-action@2a4b53665e15ce7d7049afb11ff1f70ff1610609 # associated tag: v1.1.2 |
| 121 | + with: |
| 122 | + # Allows pushing to registry on localhost:5000 |
| 123 | + driver-opts: network=host |
| 124 | + |
| 125 | + - name: Setup push rights to Docker Hub |
| 126 | + # This was setup by... |
| 127 | + # 1. Creating a Docker Hub service account "jupyterhubbot" |
| 128 | + # 2. Creating a access token for the service account specific to this |
| 129 | + # repository: https://hub.docker.com/settings/security |
| 130 | + # 3. Making the account part of the "bots" team, and granting that team |
| 131 | + # permissions to push to the relevant images: |
| 132 | + # https://hub.docker.com/orgs/jupyterhub/teams/bots/permissions |
| 133 | + # 4. Registering the username and token as a secret for this repo: |
| 134 | + # https://github.com/jupyterhub/jupyterhub/settings/secrets/actions |
| 135 | + if: env.REGISTRY != 'localhost:5000/' |
| 136 | + run: | |
| 137 | + docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}" |
| 138 | +
|
| 139 | + # image: jupyterhub/jupyterhub |
| 140 | + # |
| 141 | + # https://github.com/jupyterhub/action-major-minor-tag-calculator |
| 142 | + # If this is a tagged build this will return additional parent tags. |
| 143 | + # E.g. 1.2.3 is expanded to Docker tags |
| 144 | + # [{prefix}:1.2.3, {prefix}:1.2, {prefix}:1, {prefix}:latest] unless |
| 145 | + # this is a backported tag in which case the newer tags aren't updated. |
| 146 | + # For branches this will return the branch name. |
| 147 | + # If GITHUB_TOKEN isn't available (e.g. in PRs) returns no tags []. |
| 148 | + - name: Get list of jupyterhub tags |
| 149 | + id: jupyterhubtags |
| 150 | + uses: jupyterhub/action-major-minor-tag-calculator@v2 |
| 151 | + with: |
| 152 | + githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 153 | + prefix: "${{ env.REGISTRY }}jupyterhub/jupyterhub:" |
| 154 | + defaultTag: "${{ env.REGISTRY }}jupyterhub/jupyterhub:noref" |
| 155 | + branchRegex: ^\w[\w-.]*$ |
| 156 | + |
| 157 | + - name: Build and push jupyterhub |
| 158 | + uses: docker/build-push-action@e1b7f96249f2e4c8e4ac1519b9608c0d48944a1f |
| 159 | + with: |
| 160 | + context: . |
| 161 | + platforms: linux/amd64,linux/arm64 |
| 162 | + push: true |
| 163 | + # tags parameter must be a string input so convert `gettags` JSON |
| 164 | + # array into a comma separated list of tags |
| 165 | + tags: ${{ join(fromJson(steps.jupyterhubtags.outputs.tags)) }} |
| 166 | + |
| 167 | + # image: jupyterhub/jupyterhub-onbuild |
| 168 | + # |
| 169 | + - name: Get list of jupyterhub-onbuild tags |
| 170 | + id: onbuildtags |
| 171 | + uses: jupyterhub/action-major-minor-tag-calculator@v2 |
| 172 | + with: |
| 173 | + githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 174 | + prefix: "${{ env.REGISTRY }}jupyterhub/jupyterhub-onbuild:" |
| 175 | + defaultTag: "${{ env.REGISTRY }}jupyterhub/jupyterhub-onbuild:noref" |
| 176 | + branchRegex: ^\w[\w-.]*$ |
| 177 | + |
| 178 | + - name: Build and push jupyterhub-onbuild |
| 179 | + uses: docker/build-push-action@e1b7f96249f2e4c8e4ac1519b9608c0d48944a1f |
| 180 | + with: |
| 181 | + build-args: | |
| 182 | + BASE_IMAGE=${{ fromJson(steps.jupyterhubtags.outputs.tags)[0] }} |
| 183 | + context: onbuild |
| 184 | + platforms: linux/amd64,linux/arm64 |
| 185 | + push: true |
| 186 | + tags: ${{ join(fromJson(steps.onbuildtags.outputs.tags)) }} |
| 187 | + |
| 188 | + # image: jupyterhub/jupyterhub-demo |
| 189 | + # |
| 190 | + - name: Get list of jupyterhub-demo tags |
| 191 | + id: demotags |
| 192 | + uses: jupyterhub/action-major-minor-tag-calculator@v2 |
| 193 | + with: |
| 194 | + githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 195 | + prefix: "${{ env.REGISTRY }}jupyterhub/jupyterhub-demo:" |
| 196 | + defaultTag: "${{ env.REGISTRY }}jupyterhub/jupyterhub-demo:noref" |
| 197 | + branchRegex: ^\w[\w-.]*$ |
| 198 | + |
| 199 | + - name: Build and push jupyterhub-demo |
| 200 | + uses: docker/build-push-action@e1b7f96249f2e4c8e4ac1519b9608c0d48944a1f |
| 201 | + with: |
| 202 | + build-args: | |
| 203 | + BASE_IMAGE=${{ fromJson(steps.onbuildtags.outputs.tags)[0] }} |
| 204 | + context: demo-image |
| 205 | + # linux/arm64 currently fails: |
| 206 | + # ERROR: Could not build wheels for argon2-cffi which use PEP 517 and cannot be installed directly |
| 207 | + # ERROR: executor failed running [/bin/sh -c python3 -m pip install notebook]: exit code: 1 |
| 208 | + platforms: linux/amd64 |
| 209 | + push: true |
| 210 | + tags: ${{ join(fromJson(steps.demotags.outputs.tags)) }} |
| 211 | + |
| 212 | + # image: jupyterhub/singleuser |
| 213 | + # |
| 214 | + - name: Get list of jupyterhub/singleuser tags |
| 215 | + id: singleusertags |
| 216 | + uses: jupyterhub/action-major-minor-tag-calculator@v2 |
| 217 | + with: |
| 218 | + githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 219 | + prefix: "${{ env.REGISTRY }}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@e1b7f96249f2e4c8e4ac1519b9608c0d48944a1f |
| 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)) }} |
0 commit comments