name: Node.js CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
  schedule:
    - cron: "0 0 */1 * *" # Every day at midnight UTC

jobs:
  build:
    runs-on: docker

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '21.5.0'

      - name: Install dependencies
        run: npm install

      - name: Build project
        run: npm run build

      - name: Temporarily allow build directory
        run: |
          sed -i '/^build\//d' .gitignore

      - name: Stage build artifacts
        run: |
          git add build/
          git restore --staged .gitignore

      - name: Commit and push changes
        run: |
          git config --global user.name 'forgejo-actions[bot]'
          git config --global user.email 'forgejo-actions[bot]@forgejo.localhost'
          git commit -m 'Build and commit changes'
          git push
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
