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
      - .github/workflows/*

  pull_request:
    paths:
      - requirements.txt
      - Dockerfile
      - .github/workflows/*

  # 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@v4
        - name: Set up Python 3.11
          uses: actions/setup-python@v4
          with:
            python-version: 3.11

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

        - name: Set up Docker Buildx
          id: buildx
          uses: docker/setup-buildx-action@v3
          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_musl
          uses: docker/build-push-action@v5
          with:
            context: ./
            file: ./.github/test/Dockerfile-alpine
            platforms: linux/amd64,linux/arm64

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

