name: Deploy
on:
  pull_request:
    types:
    - closed
    branches:
    - main
  push:
    branches:
    - main

jobs:
  deployment:
    runs-on: ubuntu-latest
    if: github.event.pull_request.merged == true

    steps:
      - uses: actions/checkout@v2

      - name: Docker meta back
        id: meta
        uses: docker/metadata-action@v4
        with:
          images: ghcr.io/${{github.repository_owner}}/back
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v2
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
      -
        name: Login to ghcr
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{github.repository_owner}}
          password: ${{secrets.GITHUB_TOKEN}}
      -
        name: Build and push
        uses: docker/build-push-action@v3
        with:
          context: ./back
          push: true
          tags: ${{steps.meta.outputs.tags}}
      - name: Docker meta front
        id: meta_front
        uses: docker/metadata-action@v4
        with:
          images: ghcr.io/${{github.repository_owner}}/front
      -
        name: Build and push front
        uses: docker/build-push-action@v3
        with:
          context: ./front
          push: true
          tags: ${{steps.meta_front.outputs.tags}}
          build-args: |
            API_URL=${{secrets.API_URL}}
            SCORO_URL=${{secrets.SCORO_URL}}

      - name: Docker meta scorometer
        id: meta_scorometer
        uses: docker/metadata-action@v4
        with:
          images: ghcr.io/${{github.repository_owner}}/scorometer
      -
        name: Build and push scorometer
        uses: docker/build-push-action@v3
        with:
          context: ./scorometer
          push: true
          tags: ${{steps.meta_scorometer.outputs.tags}}

