name: Playwright — Update snapshots

on:
  workflow_dispatch:

jobs:
  update-snapshots:
    timeout-minutes: 60
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: tests/e2e
    steps:
    - uses: actions/checkout@v4

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@stable

    - name: Cache Rust build
      uses: Swatinem/rust-cache@v2

    - uses: actions/setup-node@v4
      with:
        node-version: lts/*

    - name: Install Node dependencies
      run: npm ci

    - name: Build OxiCloud (release)
      working-directory: .
      run: cargo build --release

    - name: Install Playwright browsers
      run: npx playwright install --with-deps

    - name: Update snapshots
      run: npm test -- --update-snapshots=all
      env:
        BUILD_TARGET: release

    - name: Commit updated snapshots
      uses: stefanzweifel/git-auto-commit-action@v5
      with:
        commit_message: "test(e2e): update playwright linux snapshots"
        file_pattern: "tests/e2e/scenarios/**/*-linux.png"
