# This is a basic workflow that is manually triggered

name: Compilation and Format Check

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:
  compile:
    runs-on: ubuntu-latest
    name: Compilation Check
    steps:
      - uses: actions/checkout@v3
      - uses: mlugg/setup-zig@v2
        with:
          version: 0.15.0-dev.1034+bd97b6618
      - run: sudo apt install libgl-dev libasound2-dev libx11-dev glslang-tools
      - run: echo "zigPath=$(command -v zig | sed 's/.\{3\}$//')" >> $GITHUB_ENV
      - run: wget -O $zigPath/lib/std/zig/render.zig https://github.com/PixelGuys/Cubyz-std-lib/releases/download/0.15.0-dev.1034+bd97b6618/render.zig
      - run: zig build
      - run: zig build -Dtarget=x86_64-windows-gnu
      - run: zig build test
      - run: zig build format --summary none
      - run: find assets/cubyz/shaders -type f | xargs -L1 glslangValidator -G100
      - run: |
          if zig build fmt -- *.zig src/*.zig src/*/*.zig src/*/*/*.zig src/*/*/*/*.zig src/*/*/*/*/*.zig src/*/*/*/*/*/*.zig src/*/*/*/*/*/*/*.zig src/*/*/*/*/*/*/*/*.zig src/*/*/*/*/*/*/*/*/*.zig src/*/*/*/*/*/*/*/*/*/*.zig | grep -q . ; then
            git diff --color=always;
            exit 1;
          fi
      - run: |
          if zig build fmt -- --zon *.zon assets/*.zon assets/*/*.zon assets/*/*/*.zon assets/*/*/*/*.zon assets/*/*/*/*/*.zon assets/*/*/*/*/*/*.zon assets/*/*/*/*/*/*/*.zon assets/*/*/*/*/*/*/*/*.zon assets/*/*/*/*/*/*/*/*/*.zon assets/*/*/*/*/*/*/*/*/*/*.zon | grep -q . ; then
            git diff --color=always;
            exit 1;
          fi
