name: Update flake.lock

on:
  push:
    branches: [master]
    paths: [go.sum]
  workflow_dispatch:

jobs:
  update:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - uses: DeterminateSystems/nix-installer-action@main

      - name: Update flake.lock
        run: nix flake update

      - name: Commit changes
        run: |

      - name: Configure Git
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"

      - name: Push changes
        env:
          GH_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
        run: |
          git diff --quiet flake.lock && exit 0`
          git add .
          git commit -m "chore: update flake.lock (#228)"
          git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git
          git push origin HEAD:${GITHUB_REF}
