name: Generate Everything We Need And Push to Forgejo

on:
  push:
    branches: [ "main" ]
  workflow_dispatch: {}

permissions:
  contents: write

jobs:
  build-and-generate:
    if: github.actor != 'github-actions[bot]'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          fetch-depth: 0
          fetch-tags: true

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

      - name: Install dependencies
        run: npm ci || npm install --no-audit --no-fund

      - name: Lint & Format Check
        run: npm run lint && npm run format:check

      - name: Generate YAML files
        run: npm run generate

      - name: Minify convert.js
        run: npx --yes terser convert.js -o convert.min.js -c -m --comments "/^!/"

      - name: Commit changes
        id: auto-commit
        uses: stefanzweifel/git-auto-commit-action@v7
        with:
          commit_message: "CI: Auto Generate Files"
