diff --git a/.github/workflows/visual-regression.yml b/.github/workflows/visual-regression.yml index d57764c67c5..49c02335fe5 100644 --- a/.github/workflows/visual-regression.yml +++ b/.github/workflows/visual-regression.yml @@ -10,6 +10,7 @@ jobs: runs-on: ubuntu-latest outputs: matched: ${{ steps.filter.outputs.matched }} + is_fork: ${{ steps.fork-check.outputs.is_fork }} steps: - uses: actions/checkout@v4 - uses: Kilo-Org/paths-filter@master @@ -25,6 +26,14 @@ jobs: - "packages/kilo-vscode/.storybook/**" - "packages/kilo-vscode/tests/visual-regression*" - ".github/workflows/visual-regression.yml" + - name: Check if PR is from a fork + id: fork-check + run: | + if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then + echo "is_fork=true" >> "$GITHUB_OUTPUT" + else + echo "is_fork=false" >> "$GITHUB_OUTPUT" + fi visual-regression: needs: check-paths @@ -34,13 +43,20 @@ jobs: timeout-minutes: 15 steps: - - name: Checkout + - name: Checkout (internal) + if: needs.check-paths.outputs.is_fork != 'true' uses: actions/checkout@v4 with: lfs: true token: ${{ secrets.BOT_PAT }} ref: ${{ github.head_ref }} + - name: Checkout (fork) + if: needs.check-paths.outputs.is_fork == 'true' + uses: actions/checkout@v4 + with: + lfs: true + - name: Setup Bun uses: oven-sh/setup-bun@v2 with: @@ -90,7 +106,22 @@ jobs: CI: true PLAYWRIGHT_WORKERS: "4" + - name: Check for baseline changes (fork PRs) + if: needs.check-paths.outputs.is_fork == 'true' + run: | + git add packages/kilo-ui/tests/visual-regression.spec.ts-snapshots/ + if git diff --cached --quiet; then + echo "No visual regression detected." + else + echo "::error::Visual regression detected. Screenshot baselines have changed." + echo "::error::Since this PR is from a fork, updated screenshots cannot be committed automatically." + echo "::error::Please ask a Kilo developer for help updating the screenshots." + git diff --cached --stat + exit 1 + fi + - name: Commit and push new baselines (if any) + if: needs.check-paths.outputs.is_fork != 'true' id: commit-baselines env: GH_TOKEN: ${{ secrets.BOT_PAT }} @@ -109,7 +140,7 @@ jobs: fi - name: Fail if baselines changed - if: steps.commit-baselines.outputs.changed == 'true' + if: needs.check-paths.outputs.is_fork != 'true' && steps.commit-baselines.outputs.changed == 'true' run: | echo "::error::Visual regression baselines changed. New baselines have been committed to the branch. Please pull and review." exit 1 @@ -130,13 +161,20 @@ jobs: timeout-minutes: 15 steps: - - name: Checkout + - name: Checkout (internal) + if: needs.check-paths.outputs.is_fork != 'true' uses: actions/checkout@v4 with: lfs: true token: ${{ secrets.BOT_PAT }} ref: ${{ github.head_ref }} + - name: Checkout (fork) + if: needs.check-paths.outputs.is_fork == 'true' + uses: actions/checkout@v4 + with: + lfs: true + - name: Setup Bun uses: oven-sh/setup-bun@v2 with: @@ -186,7 +224,22 @@ jobs: CI: true PLAYWRIGHT_WORKERS: "4" + - name: Check for baseline changes (fork PRs) + if: needs.check-paths.outputs.is_fork == 'true' + run: | + git add packages/kilo-vscode/tests/visual-regression.spec.ts-snapshots/ + if git diff --cached --quiet; then + echo "No visual regression detected." + else + echo "::error::Visual regression detected. Screenshot baselines have changed." + echo "::error::Since this PR is from a fork, updated screenshots cannot be committed automatically." + echo "::error::Please ask a Kilo developer for help updating the screenshots." + git diff --cached --stat + exit 1 + fi + - name: Commit and push new baselines (if any) + if: needs.check-paths.outputs.is_fork != 'true' id: commit-baselines-vscode env: GH_TOKEN: ${{ secrets.BOT_PAT }} @@ -205,7 +258,7 @@ jobs: fi - name: Fail if baselines changed - if: steps.commit-baselines-vscode.outputs.changed == 'true' + if: needs.check-paths.outputs.is_fork != 'true' && steps.commit-baselines-vscode.outputs.changed == 'true' run: | echo "::error::Visual regression baselines changed. New baselines have been committed to the branch. Please pull and review." exit 1