name: yarn
on:
  pull_request_target:
    branches:
      - main
  push:
    branches:
      - main

jobs:
  autoupdate-lockfiles:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        if: github.event_name == 'push'
        with:
          token: ${{ secrets.GH_TOKEN_FOR_UPDATES || secrets.GITHUB_TOKEN }}
      - uses: actions/checkout@v3
        if: github.event_name == 'pull_request_target'
        with:
          token: ${{ secrets.GH_TOKEN_FOR_UPDATES || secrets.GITHUB_TOKEN }}
          # pull_request_target checks out the base branch by default
          ref: ${{ github.event.pull_request.head.sha }}
      - uses: cachix/install-nix-action@v18
      - run: nix run .#packages.x86_64-linux.updateFrontendDeps
      - uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: Update yarn.nix
          token: ${{ secrets.GH_TOKEN_FOR_UPDATES || secrets.GITHUB_TOKEN }}
