Skip to content

Commit 80c9165

Browse files
[Quality Gates] add new or changes tests gate (#23)
1 parent ddb5d80 commit 80c9165

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Run changed or added tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
base_ref:
7+
description: 'Base branch to compare against'
8+
required: false
9+
default: 'main'
10+
type: string
11+
workflow_dispatch:
12+
inputs:
13+
base_ref:
14+
description: 'Base branch to compare against'
15+
required: false
16+
default: 'main'
17+
type: string
18+
19+
jobs:
20+
run-changed-or-added-tests:
21+
timeout-minutes: 30
22+
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
project: [chromium, firefox, webkit, mobile-chrome, mobile-safari]
26+
fail-fast: false
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Set up Node.js and Playwright
34+
uses: ./.github/actions/setup-playwright
35+
36+
- name: Find new or changed tests
37+
id: find-new-tests
38+
run: |
39+
BASE_REF="${{ inputs.base_ref || 'main' }}"
40+
git fetch origin "$BASE_REF"
41+
NEW_TESTS=$(git diff --name-only --diff-filter=ACMR "$BASE_REF"...HEAD -- tests/ || echo '')
42+
43+
if [ -z "$NEW_TESTS" ]; then
44+
echo "No new or changed tests found"
45+
echo "has_new_tests=false" >> $GITHUB_OUTPUT
46+
exit 0
47+
else
48+
echo "New tests found: $NEW_TESTS"
49+
echo "has_new_tests=true" >> $GITHUB_OUTPUT
50+
51+
{
52+
echo 'new_test_files<<EOF'
53+
echo "$NEW_TESTS"
54+
echo 'EOF'
55+
} >> $GITHUB_OUTPUT
56+
fi
57+
58+
- name: List new tests to run
59+
if: ${{ steps.find-new-tests.outputs.has_new_tests == 'true' }}
60+
id: list-tests
61+
run: |
62+
TEST_FILES=$(echo "${{ steps.find-new-tests.outputs.new_test_files }}" | tr '\n' ' ')
63+
64+
if [ -z "$TEST_FILES" ]; then
65+
echo "No test files to process"
66+
echo "has_new_tests=false" >> $GITHUB_OUTPUT
67+
exit 0
68+
fi
69+
70+
TEST_LIST=$(yarn playwright test --project=${{ matrix.project }} "$TEST_FILES" --list || echo '')
71+
72+
if [ -z "$TEST_LIST" ]; then
73+
echo "No tests found for project ${{ matrix.project }}"
74+
echo "has_new_tests=false" >> $GITHUB_OUTPUT
75+
else
76+
echo "Tests found for project ${{ matrix.project }}:"
77+
echo "$TEST_LIST"
78+
echo "has_new_tests=true" >> $GITHUB_OUTPUT
79+
echo "test_files=$TEST_FILES" >> $GITHUB_OUTPUT
80+
fi
81+
82+
- name: Run tests
83+
if: ${{ steps.list-tests.outputs.has_new_tests == 'true' }}
84+
run: |
85+
yarn playwright test --project=${{ matrix.project }} "${{ steps.list-tests.outputs.test_files }}"
86+
87+
- name: Upload test results
88+
if: ${{ steps.list-tests.outputs.has_new_tests == 'true' }}
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: new-tests-results-${{ matrix.project }}-${{ github.run_id }}
92+
path: playwright-report/
93+
retention-days: 7

0 commit comments

Comments
 (0)