name: Image Builder Template

on:
  workflow_call:
    inputs:
      push:
        required: true
        type: boolean
    secrets:
      GHCR_TOKEN:
        required: false

env:
  # Our build metadata
  BUILD_USER: android-builder
  BUILD_HOST: github.syncthing.net
  # template var
  image: ghcr.io/catfriend1/syncthing-android-builder

jobs:
  build-image:
    name: Build Builder Docker
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
          fetch-depth: 0

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

      - uses: docker/login-action@v3
        if: ${{ inputs.push }}
        with:
          registry: ghcr.io
          username: catfriend1
          password: ${{ secrets.GHCR_TOKEN }}

      - uses: docker/build-push-action@v4
        with:
          context: .
          file: ./docker/Dockerfile
          tags: '${{ env.image }}:latest,${{ env.image }}:${{ github.sha }}'
          push: ${{ inputs.push }}
