name: 🔒 Lockfile Consistency Check

on:
  pull_request:
    branches: [develop, master]
  push:
    branches: [develop, master]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  check-lockfile:
    name: 🔍 Check bun.lock and package.json consistency
    runs-on: ubuntu-24.04
    permissions:
      contents: read

    steps:
      - name: 📥 Checkout repository
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          ref: ${{ github.event.pull_request.head.sha || github.sha }}
          show-progress: false
          submodules: recursive
          fetch-depth: 0

      - name: 🍞 Setup Bun
        uses: oven-sh/setup-bun@3d267786b128fe76c2f16a390aa2448b815359f3 # v2.1.2
        with:
          bun-version: latest

      - name: 💾 Cache Bun dependencies
        uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2
        with:
          path: |
            ~/.bun/install/cache
          key: ${{ runner.os }}-bun-${{ hashFiles('bun.lock') }}

      - name: 🛡️ Verify lockfile consistency
        run: |
          set -euxo pipefail
          echo "➡️ Checking for discrepancies between bun.lock and package.json..."
          bun install --frozen-lockfile --dry-run --ignore-scripts
          echo "✅ Lockfile is consistent with package.json!"
