|
| 1 | +name: deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - v2 |
| 8 | +jobs: |
| 9 | + tag_and_dockerise: |
| 10 | + # When merging to one of the branches above and the commit message matches |
| 11 | + if: "startsWith(github.event.head_commit.message, 'Bump version:')" |
| 12 | + name: Tag and dockerise |
| 13 | + runs-on: ubuntu-latest |
| 14 | + defaults: |
| 15 | + run: |
| 16 | + shell: bash -l {0} |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v2 |
| 20 | + - name: Get package version |
| 21 | + id: package-version |
| 22 | + uses: martinbeentjes/npm-get-version-action@master |
| 23 | + - name: Tag based on version |
| 24 | + uses: actions/github-script@v5 |
| 25 | + env: |
| 26 | + VERSION: ${{ steps.package-version.outputs.current-version }} |
| 27 | + with: |
| 28 | + script: | |
| 29 | + const the_tag = 'refs/tags/v' + process.env.VERSION |
| 30 | + github.rest.git.createRef({ |
| 31 | + owner: context.repo.owner, |
| 32 | + repo: context.repo.repo, |
| 33 | + ref: the_tag, |
| 34 | + sha: context.sha |
| 35 | + }) |
| 36 | +
|
| 37 | + # checkout tag from above |
| 38 | + - name: Checkout code |
| 39 | + uses: actions/checkout@v2 |
| 40 | + with: |
| 41 | + ref: v${{ steps.package-version.outputs.current-version }} |
| 42 | + # Use qemu to perform multiplatform builds |
| 43 | + - name: Set up QEMU |
| 44 | + uses: docker/setup-qemu-action@v1 |
| 45 | + # Use docker buildx to build multi-platform containers |
| 46 | + - name: Set up Docker Buildx |
| 47 | + uses: docker/setup-buildx-action@v1 |
| 48 | + with: |
| 49 | + use: true |
| 50 | + install: true |
| 51 | + config-inline: | |
| 52 | + [worker.oci] |
| 53 | + max-parallelism = 2 |
| 54 | + - name: Login to GitHub Container Registry |
| 55 | + uses: docker/login-action@v1 |
| 56 | + with: |
| 57 | + registry: ghcr.io |
| 58 | + username: ${{ github.actor }} |
| 59 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + - name: Build and push docker image |
| 61 | + uses: docker/build-push-action@v2 |
| 62 | + env: |
| 63 | + VERSION: ${{ steps.package-version.outputs.current-version }} |
| 64 | + with: |
| 65 | + context: . |
| 66 | + platforms: linux/amd64,linux/arm64 |
| 67 | + push: true |
| 68 | + tags: | |
| 69 | + ghcr.io/${{ github.repository }}:${{ env.VERSION }} |
0 commit comments