#!/usr/bin/env bash

. $(dirname $0)/util
set -e

: ${TARGETPLATFORM=linux/amd64,linux/arm/v7,linux/arm64,darwin/amd64,windows/amd64,linux/ppc64le,linux/s390x}
: ${EXPORT_LOCAL=}

importCacheFlags=""
if [ "$GITHUB_ACTIONS" = "true" ]; then
  if [ -n "$cacheRefFrom" ]; then
    importCacheFlags="--cache-from=type=local,src=$cacheRefFrom"
  fi
fi

exportFlag=""
if [ -n "$EXPORT_LOCAL" ]; then
  exportFlag="--output=type=local,dest=$EXPORT_LOCAL"
fi

buildxCmd build $importCacheFlags $exportFlag \
  --target "binaries" \
  --platform "$TARGETPLATFORM" \
  $currentcontext
