name: Build CCExtractor Docker Images

on:
  workflow_dispatch:
  push:
    paths:
    - '.github/workflows/build_docker.yml'
    - 'docker/**'
    - '**.c'
    - '**.h'
    - '**CMakeLists.txt'
    - '**.cmake'
    - 'src/rust/**'
  pull_request:
    types: [opened, synchronize, reopened]
    paths:
    - '.github/workflows/build_docker.yml'
    - 'docker/**'
    - '**.c'
    - '**.h'
    - '**CMakeLists.txt'
    - '**.cmake'
    - 'src/rust/**'

jobs:
  build_minimal:
    name: Docker build (minimal)
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6
    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v4
    - name: Build minimal image
      uses: docker/build-push-action@v7
      with:
        context: .
        file: docker/Dockerfile
        build-args: |
          BUILD_TYPE=minimal
          USE_LOCAL_SOURCE=1
        tags: ccextractor:minimal
        load: true
        cache-from: type=gha,scope=docker-minimal
        cache-to: type=gha,mode=max,scope=docker-minimal
    - name: Test minimal image
      run: |
        docker run --rm ccextractor:minimal --version
        echo "Minimal build successful"

  build_ocr:
    name: Docker build (ocr)
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6
    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v4
    - name: Build OCR image
      uses: docker/build-push-action@v7
      with:
        context: .
        file: docker/Dockerfile
        build-args: |
          BUILD_TYPE=ocr
          USE_LOCAL_SOURCE=1
        tags: ccextractor:ocr
        load: true
        cache-from: type=gha,scope=docker-ocr
        cache-to: type=gha,mode=max,scope=docker-ocr
    - name: Test OCR image
      run: |
        docker run --rm ccextractor:ocr --version
        echo "OCR build successful"

  build_hardsubx:
    name: Docker build (hardsubx)
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6
    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v4
    - name: Build HardSubX image
      uses: docker/build-push-action@v7
      with:
        context: .
        file: docker/Dockerfile
        build-args: |
          BUILD_TYPE=hardsubx
          USE_LOCAL_SOURCE=1
        tags: ccextractor:hardsubx
        load: true
        cache-from: type=gha,scope=docker-hardsubx
        cache-to: type=gha,mode=max,scope=docker-hardsubx
    - name: Test HardSubX image
      run: |
        docker run --rm ccextractor:hardsubx --version
        echo "HardSubX build successful"
