name: Frontend / E2E

on:
  workflow_call:
    inputs:
      tag:
        required: true
        type: string
      release:
        required: false
        type: boolean
        default: false

    secrets:
      GH_TOKEN:
        required: true

jobs:
  publish:
    name: "Publish Homebox"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.19

      - name: Set up QEMU
        id: qemu
        uses: docker/setup-qemu-action@v1
        with:
          image: tonistiigi/binfmt:latest
          platforms: all

      - name: install buildx
        id: buildx
        uses: docker/setup-buildx-action@v1
        with:
          install: true

      - name: login to container registry
        run: docker login ghcr.io --username hay-kot --password $CR_PAT
        env:
          CR_PAT: ${{ secrets.GH_TOKEN }}

      - name: build nightly the image
        if: ${{ inputs.release == false }}
        run: |
          docker build --push --no-cache \
            --tag=ghcr.io/hay-kot/homebox:${{ inputs.tag }} \
            --build-arg=COMMIT=$(git rev-parse HEAD) \
            --build-arg=BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
            --platform=linux/amd64,linux/arm64,linux/arm/v7 .

      - name: build release tagged the image
        if: ${{ inputs.release == true }}
        run: |
          docker build --push --no-cache \
            --tag ghcr.io/hay-kot/homebox:nightly \
            --tag ghcr.io/hay-kot/homebox:latest \
            --tag ghcr.io/hay-kot/homebox:${{ inputs.tag }} \
            --build-arg COMMIT=$(git rev-parse HEAD) \
            --build-arg BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
            --platform linux/amd64,linux/arm64,linux/arm/v7 .