name: Update lockfiles

on:
  schedule:
    # run every friday
    - cron: "0 0 * * 5"
  workflow_dispatch:

jobs:
  update-locks:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: cachix/install-nix-action@v23

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

      - name: Update flake inputs
        run: |
          nix flake update \
            --commit-lock-file --commit-lockfile-summary "chore: update flake inputs"

      - name: Update upstream sources
        run: |
          nix run nixpkgs#nvfetcher

      - name: Create PR
        uses: peter-evans/create-pull-request@v5
        with:
          token: ${{ secrets.LOCKFILE_TOKEN }}
          base: "main"
          branch: "update-lock"
          delete-branch: true
          committer: github-actions[bot] github-actions[bot]@users.noreply.github.com
          commit-message: "chore: update nvfetcher sources"
          title: "chore: update lockfiles"
          body: "Automated pull request updating flake inputs and nvfetcher sources"
