|
| 1 | +# Publish NPM package and Docker image |
| 2 | +name: Release |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + pull_request: |
| 7 | + |
| 8 | +jobs: |
| 9 | + # Run tests using node, publish a package when tagged |
| 10 | + # https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages |
| 11 | + |
| 12 | + publish-npm: |
| 13 | + runs-on: ubuntu-20.04 |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v2 |
| 16 | + - uses: actions/setup-node@v1 |
| 17 | + with: |
| 18 | + node-version: 14 |
| 19 | + registry-url: https://registry.npmjs.org/ |
| 20 | + - run: npm ci |
| 21 | + - run: npm publish |
| 22 | + if: startsWith(github.ref, 'refs/tags/') |
| 23 | + env: |
| 24 | + NODE_AUTH_TOKEN: ${{ secrets.npm_token }} |
| 25 | + |
| 26 | + publish-docker: |
| 27 | + runs-on: ubuntu-20.04 |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v2 |
| 30 | + |
| 31 | + # Setup docker to build for multiple platforms (requires qemu). |
| 32 | + # See: |
| 33 | + # https://github.com/docker/build-push-action/tree/v2.3.0#usage |
| 34 | + # https://github.com/docker/build-push-action/blob/v2.3.0/docs/advanced/multi-platform.md |
| 35 | + |
| 36 | + - name: Set up QEMU |
| 37 | + uses: docker/setup-qemu-action@v1 |
| 38 | + |
| 39 | + - name: Set up Docker Buildx |
| 40 | + uses: docker/setup-buildx-action@v1 |
| 41 | + |
| 42 | + # https://github.com/docker/login-action/tree/v1.8.0#docker-hub |
| 43 | + - name: Login to Docker Hub |
| 44 | + uses: docker/login-action@v1 |
| 45 | + if: startsWith(github.ref, 'refs/tags/') |
| 46 | + with: |
| 47 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 48 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 49 | + |
| 50 | + # https://github.com/jupyterhub/action-major-minor-tag-calculator |
| 51 | + # If this is a tagged build this will return additional parent tags. |
| 52 | + # E.g. 1.2.3 is expanded to Docker tags |
| 53 | + # [{prefix}:1.2.3, {prefix}:1.2, {prefix}:1, {prefix}:latest] unless |
| 54 | + # this is a backported tag in which case the newer tags aren't updated. |
| 55 | + # For branches this will return the branch name. |
| 56 | + # If GITHUB_TOKEN isn't available (e.g. in PRs) returns no tags []. |
| 57 | + - name: Get list of tags |
| 58 | + id: gettags |
| 59 | + # TODO: Move to org? |
| 60 | + uses: jupyterhub/action-major-minor-tag-calculator@main |
| 61 | + with: |
| 62 | + githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + prefix: "jupyterhub/configurable-http-proxy:" |
| 64 | + |
| 65 | + - name: Display tags |
| 66 | + run: echo "Docker tags ${{ steps.gettags.outputs.tags }}" |
| 67 | + |
| 68 | + - name: Build and push |
| 69 | + uses: docker/build-push-action@v2 |
| 70 | + with: |
| 71 | + platforms: linux/amd64,linux/arm64 |
| 72 | + push: ${{ startsWith(github.ref, 'refs/tags/') }} |
| 73 | + # tags parameter must be a string input so convert `gettags` JSON |
| 74 | + # array into a comma separated list of tags |
| 75 | + tags: ${{ join(fromJson(steps.gettags.outputs.tags)) }} |
0 commit comments