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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          persist-credentials: false
      - name: Generate Dockerfile
        run: ./contrib/ci/generate_docker.py
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
      - name: Login to GitHub Container Registry
        uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Push to GitHub Packages
        uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
        with:
          context: .
          push: true
          tags: "ghcr.io/fwupd/fwupd/fwupd-${{ join(matrix.env.*, '-') }}:latest"
