name: ChangeDetection.io Container Build Test

# Triggers the workflow on push or pull request events

# This line doesnt work, even tho it is the documented one
#on: [push, pull_request]

on:
  push:
    paths:
      - requirements.txt
      - Dockerfile

  pull_request:
    paths:
      - requirements.txt
      - Dockerfile

  # Changes to requirements.txt packages and Dockerfile may or may not always be compatible with arm etc, so worth testing
  # @todo: some kind of path filter for requirements.txt and Dockerfile
jobs:
  test-container-build:
    runs-on: ubuntu-latest
    steps:
        - uses: actions/checkout@v2
        - name: Set up Python 3.9
          uses: actions/setup-python@v2
          with:
            python-version: 3.9

        # Just test that the build works, some libraries won't compile on ARM/rPi etc
        - name: Set up QEMU
          uses: docker/setup-qemu-action@v1
          with:
            image: tonistiigi/binfmt:latest
            platforms: all

        - name: Set up Docker Buildx
          id: buildx
          uses: docker/setup-buildx-action@v1
          with:
            install: true
            version: latest
            driver-opts: image=moby/buildkit:master

        # https://github.com/dgtlmoon/changedetection.io/pull/1067
        # Check we can still build under alpine/musl
        - name: Test that the docker containers can build (musl via alpine check)
          id: docker_build
          uses: docker/build-push-action@v2
          with:
            context: ./
            file: ./.github/test/Dockerfile-alpine
            platforms: linux/amd64,linux/arm64,
            cache-from: type=local,src=/tmp/.buildx-cache
            cache-to: type=local,dest=/tmp/.buildx-cache

        - name: Test that the docker containers can build
          id: docker_build
          uses: docker/build-push-action@v2
          # https://github.com/docker/build-push-action#customizing
          with:
            context: ./
            file: ./Dockerfile
            platforms: linux/arm/v7,linux/arm/v6,linux/amd64,linux/arm64,
            cache-from: type=local,src=/tmp/.buildx-cache
            cache-to: type=local,dest=/tmp/.buildx-cache