name: PR
on: [pull_request]

jobs:
  build:
    name: Lint, format, test and build
    runs-on: ubuntu-latest

    steps:
      - name: Checkout 🛎️
        uses: actions/checkout@v3

      - name: Use Node LTS ✨
        uses: actions/setup-node@v3
        with:
          node-version: lts/*
          cache: yarn

      - name: Installing dependencies 📦️
        run: yarn install --immutable

      - name: Lint 💅
        run: yarn lint

      - name: Format 🔍
        run: yarn format:check

      - name: Test 🧪
        run: yarn test --passWithNoTests

      - name: Build 🔨
        run: yarn build

  build-container:
    name: Build container
    runs-on: ubuntu-latest

    env:
      # Consider replacing Docker repository below, e.g. like this:
      # IMAGE_NAME: ${{ secrets.CONTAINER_REPOSITORY }}/${{ inputs.name }}
      IMAGE_NAME: bjerkio/${{ github.event.repository.name }}

    steps:
      - name: Checkout 🛎️
        uses: actions/checkout@v3

      - name: Docker meta 🏷
        id: meta
        uses: docker/metadata-action@v4
        with:
          images: ${{ env.IMAGE_NAME }}
          tags: |
            type=ref,event=pr

      - name: Set up Docker Buildx 🔨
        id: buildx
        uses: docker/setup-buildx-action@v2

      - name: Build Docker 🛠
        uses: docker/build-push-action@v4
        with:
          context: ./
          file: ./Dockerfile
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          # Uncomment to enable caching
          # cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:latest
          cache-to: type=inline
