name: Create containers
on:
  workflow_dispatch:
  schedule:
    - cron: "0 0 * * *"

permissions:
  contents: read

jobs:
  push_to_registry:
    permissions:
      packages: write # for docker/build-push-action
    runs-on: ${{ case(matrix.env.ARCH == 'arm64', 'ubuntu-24.04-arm', 'ubuntu-latest') }}
    strategy:
      fail-fast: false
      matrix:
        env:
          # NOTE: values are joined by '-' for name of container image
          - { DISTRO: arch, ARCH: amd64 }
          - { DISTRO: centos, ARCH: amd64 }
          - { DISTRO: debian, ARCH: amd64 }
          - { DISTRO: debian, ARCH: amd64, VARIANT: i386 }
          - { DISTRO: debian, ARCH: amd64, VARIANT: tartan }
          - { DISTRO: debian, ARCH: arm64 }
          # - { DISTRO: debian, ARCH: arm64, VARIANT: cross-s390x }
          - { DISTRO: fedora, ARCH: amd64 }
          - { DISTRO: ubuntu, ARCH: amd64 }
    env: ${{ matrix.env }}
    steps:
      - name: Check out the repo
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - name: Generate Dockerfile
        run: ./contrib/ci/generate_docker.py
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
      - name: Login to GitHub Container Registry
        uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Push to GitHub Packages
        uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
        with:
          context: .
          push: true
          tags: "ghcr.io/fwupd/fwupd/fwupd-${{ join(matrix.env.*, '-') }}:latest"
