# Minora — Build Pipeline
# Runs on every push to main, builds CSS + JS, and commits dist/
name: Build

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: write

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      # 1. Checkout repository
      - name: Checkout
        uses: actions/checkout@v4

      # 2. Setup Node.js
      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'npm'

      # 3. Install dependencies
      - name: Install
        run: npm ci

      # 4. Build CSS + JS
      - name: Build
        run: npm run build:all

      # 5. Commit dist/ if there are changes
      - name: Commit dist
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add -f dist/
          git diff --cached --quiet || git commit -m "chore: build dist"
          git push
