name: Sync Gemfile.saas.lock

on:
  push:
    branches:
      - "dependabot/bundler/**"
    paths:
      - Gemfile.lock

permissions:
  contents: write

jobs:
  sync:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 # zizmor: ignore[artipacked] -- credentials needed for git push

      - uses: ruby/setup-ruby@319994f95fa847cf3fb3cd3dbe89f6dcde9f178f # v1.295.0
        with:
          ruby-version: .ruby-version

      - name: Forward Gemfile.lock changes to Gemfile.saas.lock
        run: bin/bundle-drift forward

      - name: Commit updated lockfile
        run: |
          git add Gemfile.saas.lock
          if ! git diff --cached --quiet; then
            git config user.name "github-actions[bot]"
            git config user.email "github-actions[bot]@users.noreply.github.com"
            git commit -m "Sync Gemfile.saas.lock"
            git push
          fi
