# When git main branch changes it will build a image based on the main branch, the tag of the image will be latest.
# When a git semver tag is pushed it will build a image based on it, the tag will be the same as git's.
# It will do nothing on other git events.
# For the usage of the image, check lib/examples/launch-managed .

name: Release docker image

on: [push, pull_request]

permissions:
  packages: write

jobs:
  # TODO: we should merge job docker-amd and job docker-arm once the github actions fix their issue with cross-platform building.
  docker-amd:
    runs-on: ubuntu-22.04

    steps:
      - uses: actions/setup-go@v4
        with:
          go-version: 1.19

      - uses: docker/setup-qemu-action@v2

      - uses: actions/checkout@v3

      - run: go run ./lib/docker $GITHUB_REF
        env:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

      - uses: actions/upload-artifact@v2
        with:
          name: review-fonts-docker
          path: tmp/fonts.pdf

      - uses: actions/upload-artifact@v2
        if: ${{ always() }}
        with:
          name: cdp-log-docker
          path: tmp/cdp-log

  docker-arm:
    runs-on: ubuntu-22.04

    steps:
      - uses: actions/setup-go@v4
        with:
          go-version: 1.19

      - uses: docker/setup-qemu-action@v2

      - uses: actions/checkout@v3

      - run: go run ./lib/docker $GITHUB_REF
        env:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
          ARCH: arm
