name: CI
on:
  push:
    branches: [main]

jobs:
  smoke-test:
    runs-on: host
    steps:

      - name: debug env
        run:
          env | sort

      - name: Setup PATH
        run: |
          echo "/nix/var/nix/profiles/default/bin" >> $GITHUB_PATH
          echo "/var/lib/forgejo-runner/.nix-profile/bin" >> $GITHUB_PATH

      - name: Check PATH
        run:
          echo $PATH

      - name: Check cwd
        run:
          pwd

      - name: Check nix version
        run:
          echo $(nix --version)

      - name: nix store ping
        run:
          nix store info

      - name: checkout
        run: |
          # 1. actions/checkout@v4 stumbles b/c install is at conybeare.us/git
          #    checkout manually instead.
          # 2. could clone from /var/lib/forgejo/gitea-repositories/roland/xo-umbrella2.git
          # 3. instead rely on $GITHUB_SERVER_URL

          git clone --quiet --depth=1 $GITHUB_SERVER_URL/roland/xo-umbrella2.git .

      - name: build xo-cmake
        run:
          nix-build ci.nix -A xo-cmake

      - name: build xo-indentlog
        run:
          nix-build ci.nix -A xo-indentlog

      - name: build xo-subsys
        run:
          nix-build ci.nix -A xo-subsys

      - name: build xo-flatstring
        run:
          nix-build ci.nix -A xo-flatstring

      - name: build xo-randomgen
        run:
          nix-build ci.nix -A xo-randomgen

      - name: build xo-reflectutil
        run:
          nix-build ci.nix -A xo-reflectutil

      - name: build xo-arena
        run:
          nix-build ci.nix -A xo-arena

      - name: build xo-facet
        run: |
          echo -n nix-build ci.nix -A xo-type
          nix-build ci.nix -A xo-facet
          ls -l ./result

      - name: build xo-printable2
        run: |
          echo -n nix-build ci.nix -A xo-printable2
          nix-build ci.nix -A xo-printable2
          ls -l ./result

      - name: build xo-testutil
        run: |
          echo -n nix-build ci.nix -A xo-testutil
          nix-build ci.nix -A xo-testutil
          ls -l ./result

      - name: build xo-alloc2
        run: |
          echo -n nix-build ci.nix -A xo-alloc2
          nix-build ci.nix -A xo-alloc2
          ls -l ./result

      - name: build xo-refcnt
        run: |
          echo -n nix-build ci.nix -A xo-refcnt
          nix-build ci.nix -A xo-refcnt
          ls -l ./result

      - name: build xo-reflect
        run: |
          echo -n nix-build ci.nix -A xo-reflect
          nix-build ci.nix -A xo-reflect
          ls -l ./result

      - name: build xo-stringtable2
        run: |
          echo -n nix-build ci.nix -A xo-stringtable2
          nix-build ci.nix -A xo-stringtable2
          ls -l ./result

      - name: build xo-object2
        run: |
          echo -n nix-build ci.nix -A xo-object2
          nix-build ci.nix -A xo-object2
          ls -l ./result

      - name: build xo-gc
        run: |
          echo -n nix-build ci.nix -A xo-gc
          nix-build ci.nix -A xo-gc
          ls -l ./result

      - name: build xo-type
        run: |
          echo -n nix-build ci.nix -A xo-type
          nix-build ci.nix -A xo-type
          ls -l ./result
