# Split the image builds into a separate workflow so we can easily run it
# when only the Containerfiles have changed without introducing new external
# GitHub Actions dependencies, such as the `tj-actions/changed-files` action.
name: ci images

on:
  pull_request:
    paths:
      - "container-images/**"
      - ".github/workflows/ci-images.yml"
  push:
    branches:
      - main
    paths:
      - "container-images/**"
      - ".github/workflows/ci-images.yml"

jobs:
  build:
    runs-on: ubuntu-24.04
    timeout-minutes: 120
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Upgrade to podman 5
        run: |
          set -e
          # Enable universe repository which contains podman
          sudo add-apt-repository "deb http://old-releases.ubuntu.com/ubuntu oracular universe"
          # Update package lists
          sudo apt-get update
          sudo apt-get purge firefox
          # Install specific podman version
          sudo apt-get upgrade

      - name: install
        shell: bash
        run: |
          sudo apt-get update
          sudo apt-get install podman bash
          make install-requirements

      - name: Print disk space before cleanup
        shell: bash
        run: |
          df -h

      - name: Free Disk Space Linux
        shell: bash
        run: |
          sudo mkdir -m a=rwx -p /mnt/tmp /mnt/runner
          sudo mkdir -m o=rwx -p /home/runner/.local
          sudo chown runner:runner /mnt/runner /home/runner/.local
          sudo mount --bind /mnt/runner /home/runner/.local
          sudo rm -rf \
            /usr/share/dotnet /usr/local/lib/android /opt/ghc \
            /usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \
            /usr/share/dotnet /usr/lib/jvm /opt/hostedtoolcache/CodeQL \
            "$AGENT_TOOLSDIRECTORY" || true
          sudo swapoff -a
          sudo rm -f /mnt/Swapfile

      - name: Print disk space after cleanup
        shell: bash
        run: |
          df -h

      - name: Build Images
        run: |
          ./container_build.sh -r -c -s build
