🏡 index : quine-global-labs/mirror-ublue-os-titanoboa.git

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow
name: Build Examples CI

on:
  workflow_dispatch:
  merge_group:
  pull_request:
    branches:
      - main
    paths:
      - "examples/**"
      - ".github/workflows/ci.yml"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    name: Build ${{ matrix.example }} ${{ matrix.arch }}
    permissions:
      contents: read
    runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-24.04' || 'ubuntu-24.04-arm64' }}

    strategy:
      fail-fast: false
      matrix:
        example: [bazzite, zirconium]
        arch: [amd64]
        include:
          - example: zirconium
            arch: arm64
    steps:
      - name: Maximize Build Space
        if: matrix.arch == 'amd64'
        uses: ublue-os/remove-unwanted-software@v9
        with:
          remove-codeql: true

      - name: Checkout
        uses: actions/checkout@v4

      - name: Build Container Image
        id: build-container
        shell: bash
        run: |
          IMAGE_NAME="titanoboa-example-${{ matrix.example }}:${{ github.sha }}"
          sudo podman build \
            --cap-add sys_admin \
            --security-opt label=disable \
            --volume /var/lib/containers/storage:/usr/lib/containers/storage:ro \
            --tag "${IMAGE_NAME}" \
            "./examples/${{ matrix.example }}"
          echo "IMAGE_NAME=${IMAGE_NAME}" >> "$GITHUB_OUTPUT"

      - name: Build ISO
        id: build-iso
        uses: ./
        with:
          image-ref: ${{ steps.build-container.outputs.IMAGE_NAME }}

      - name: Create Image Name
        id: name
        shell: bash
        run: |
          IMAGE_NAME="titanoboa-example-${{ matrix.example }}"
          echo "IMAGE_NAME=$IMAGE_NAME" >> "$GITHUB_OUTPUT"

      - name: Upload Output Artifacts
        if: github.event_name != 'pull_request'
        uses: actions/upload-artifact@v4
        with:
          name: ${{ steps.name.outputs.IMAGE_NAME }}-${{ matrix.arch }}
          retention-days: 5
          if-no-files-found: error
          path: |
            ${{ steps.build-iso.outputs.iso-dest }}
  check:
    name: Check all builds successful
    if: always()
    runs-on: ubuntu-latest
    needs: [build]
    steps:
      - name: Check Jobs
        env:
          JOBS: ${{ toJson(needs) }}
        run: |
          echo "Job status:"
          echo $JOBS | jq -r 'to_entries[] | " - \(.key): \(.value.result)"'

          for i in $(echo $JOBS | jq -r 'to_entries[] | .value.result'); do
            if [ "$i" != "success" ] && [ "$i" != "skipped" ]; then
              echo ""
              echo "Status check not okay!"
              exit 1
            fi
          done