name: Build WASM

on:
  push:
    paths:
      - "scripts/**"
    branches-ignore:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build WASM
        run: scripts/build.sh
      - name: Commit WASM
        run: |
          if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then
            git config --global user.name 'GitHub Action'
            git config --global user.email 'domoritz@users.noreply.github.com'
            git add src/clingo.wasm src/clingo.js
            git commit -m "[CI] Automated build of WASM files."
            git push
          else
            echo "No changes detected in WASM file."
          fi
