name: 📼 VHS
on:
  push:
    paths:
      - 'docs/tapes/*.tape'
  workflow_dispatch:

permissions:
  contents: read

jobs:
  vhs:
    name: Create VHS
    runs-on: macos-latest
    if: ${{ github.repository == 'wxt-dev/wxt' }}
    permissions:
      contents: write
    steps:
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Setup
        uses: ./.github/actions/setup
        with:
          install: false

      - name: Setup Go
        uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00
        with:
          go-version: '1.25.1'

      # This prevents pnpm dlx from downloading WXT in the video
      - name: Pre-install WXT
        run: |
          pnpm store add wxt@latest
          pnpm dlx wxt@latest --version

      - name: Record VHS
        run: |
          brew install ttyd ffmpeg
          go install github.com/charmbracelet/vhs@517bcda0faf416728bcf6b7fe489eb0e2469d9b5 # v0.10.0
          vhs docs/tapes/init-demo.tape

      - name: Save recorded GIF
        uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7.1.0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          commit_message: 'docs: Update `wxt init` GIF'
          # https://github.com/charmbracelet/vhs#output
          file_pattern: 'docs/assets/*.gif'
