name: Build

on:
  workflow_dispatch:
    inputs:
      bump-type:
        description: 'Type of version bump (major, minor, patch, build)'
        required: false
        default: 'build'

permissions:
  contents: write
  pull-requests: write
  packages: write
  id-token: write

jobs:
  build:
    name: build
    concurrency:
      group: validate-group
      cancel-in-progress: true
    if: github.event_name == 'workflow_dispatch' && github.event.inputs.bump-type == 'build'
    runs-on: ubuntu-latest
    steps:
      - name: ⬇️ Checkout Repo
        uses: actions/checkout@v7

      - name: 🗑️ Remove package-lock.json
        run: rm -f package-lock.json

      - name: 📦 Install Packages
        run: npm ci --ignore-scripts

      - name: � Setup Husky
        run: npm run prepare

      - name: 🧪 Test
        run: npm test

      - name: 🏗️ Production Build
        run: npm run build:dev

      - name: Commit and push new package-lock.json
        run: |
          git config --global user.name "github-actions[bot]"
          git config --global user.email "github-actions[bot]@users.noreply.github.com"
          git add package-lock.json
          git commit -m "ci: update package-lock.json [skip ci]" || echo "No changes to commit"
          git push || echo "No changes to push"
