name: xc_admin_frontend Docker Image
on:
  push:
    branches: [main]
    paths: ["governance/xc_admin/**"]
  pull_request:
    paths: ["governance/xc_admin/**"]
permissions:
  contents: read
  id-token: write
  packages: write
env:
  REGISTRY: ghcr.io
  IMAGE_NAME: pyth-network/xc-admin-frontend
jobs:
  xc-admin-frontend-image:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set image tag to timestamp and shortened commit hash
        run: |
          SHORT_HASH=$(echo ${{ github.sha }} | cut -c1-7)
          TIMESTAMP=$(date +%s)
          echo "IMAGE_TAG=${TIMESTAMP}-${SHORT_HASH}" >> "${GITHUB_ENV}"
      - name: Log in to the Container registry
        uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build docker image
        run: |
          DOCKER_BUILDKIT=1 docker build -t builder-base --target builder-base -f Dockerfile.node .
          DOCKER_BUILDKIT=1 docker build -t runner-base --target runner-base -f Dockerfile.node .
          DOCKER_BUILDKIT=1 docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \
            --build-arg NEXT_PUBLIC_RPC_POOL_TOKEN=${{ secrets.NEXT_PUBLIC_RPC_POOL_TOKEN }} \
            -f governance/xc_admin/packages/xc_admin_frontend/Dockerfile .
      - name: Push docker image
        if: github.ref == 'refs/heads/main'
        run: |
          docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
