Skip to content

Commit 848882f

Browse files
Anton StandrikAnton Standrik
authored andcommitted
fix: tests
1 parent 0dd5cb3 commit 848882f

File tree

2 files changed

+67
-59
lines changed

2 files changed

+67
-59
lines changed

.github/scripts/test-analyzer.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Creating temporary files..."
5+
current_tests_file=$(mktemp)
6+
base_tests_file=$(mktemp)
7+
8+
function cleanup {
9+
echo "Cleaning up temporary files..."
10+
rm -f "$current_tests_file" "$base_tests_file"
11+
}
12+
trap cleanup EXIT
13+
14+
function extract_tests() {
15+
local file=$1
16+
echo "Processing file: $file" >&2
17+
# Look for test declarations and extract just the test name between quotes
18+
perl -ne 'if (/test\(['\''"](.+?)['\''"]/) { print "$1|'$file'\n" }' "$file"
19+
}
20+
21+
echo "Extracting current branch tests..."
22+
while IFS= read -r file; do
23+
extract_tests "$file"
24+
done < <(find tests/suites -type f -name "*.test.ts") | sort > "$current_tests_file"
25+
26+
echo "Fetching main branch..."
27+
git fetch origin main:main
28+
29+
echo "Saving current branch name..."
30+
current_branch=$(git rev-parse --abbrev-ref HEAD)
31+
32+
echo "Checking out main branch..."
33+
git checkout main
34+
35+
echo "Extracting main branch tests..."
36+
while IFS= read -r file; do
37+
if [ -f "$file" ]; then
38+
extract_tests "$file"
39+
fi
40+
done < <(find tests/suites -type f -name "*.test.ts") | sort > "$base_tests_file"
41+
42+
echo "Returning to original branch..."
43+
git checkout "$current_branch"
44+
45+
echo "Comparing test files..."
46+
new_tests=0
47+
test_details=""
48+
49+
while IFS='|' read -r test_name file; do
50+
if ! grep -Fq "$test_name|" "$base_tests_file"; then
51+
((new_tests++))
52+
test_details+="- ✨ Added test: \`$test_name\` in \`$file\`\\n"
53+
fi
54+
done < "$current_tests_file"
55+
56+
# Output in GitHub Actions format
57+
echo "new_tests=$new_tests"
58+
echo "test_details<<EOF"
59+
echo -e "$test_details"
60+
echo "EOF"

.github/workflows/quality.yml

Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -217,68 +217,16 @@ jobs:
217217
name: playwright-artifacts
218218
path: playwright-artifacts
219219

220+
- name: Setup git config
221+
run: |
222+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
223+
git config --global user.name "github-actions[bot]"
224+
220225
- name: Analyze test changes
221226
id: analyze_tests
222-
shell: bash
223227
run: |
224-
set -e
225-
226-
echo "Creating temporary files..."
227-
current_tests_file=$(mktemp)
228-
base_tests_file=$(mktemp)
229-
230-
function cleanup {
231-
echo "Cleaning up temporary files..."
232-
rm -f "$current_tests_file" "$base_tests_file"
233-
}
234-
trap cleanup EXIT
235-
236-
function extract_tests() {
237-
local file=$1
238-
echo "Processing file: $file" >&2
239-
# Look for test declarations and extract just the test name between quotes
240-
perl -ne 'if (/test\(['\''"](.+?)['\''"]/) { print "$1|'$file'\n" }' "$file"
241-
}
242-
243-
echo "Extracting current branch tests..."
244-
while IFS= read -r file; do
245-
extract_tests "$file"
246-
done < <(find tests/suites -type f -name "*.test.ts") | sort > "$current_tests_file"
247-
248-
echo "Fetching main branch..."
249-
git fetch origin main:main
250-
251-
echo "Saving current branch name..."
252-
current_branch=$(git rev-parse --abbrev-ref HEAD)
253-
254-
echo "Checking out main branch..."
255-
git checkout main
256-
257-
echo "Extracting main branch tests..."
258-
while IFS= read -r file; do
259-
if [ -f "$file" ]; then
260-
extract_tests "$file"
261-
fi
262-
done < <(find tests/suites -type f -name "*.test.ts") | sort > "$base_tests_file"
263-
264-
echo "Returning to original branch..."
265-
git checkout "$current_branch"
266-
267-
echo "Comparing test files..."
268-
new_tests=0
269-
test_details=""
270-
271-
while IFS='|' read -r test_name file; do
272-
if ! grep -Fq "$test_name|" "$base_tests_file"; then
273-
((new_tests++))
274-
test_details+="- ✨ Added test: \`$test_name\` in \`$file\`\\n"
275-
fi
276-
done < "$current_tests_file"
277-
278-
echo "new_tests=$new_tests" >> $GITHUB_OUTPUT
279-
echo "test_details<<EOF" >> $GITHUB_OUTPUT
280-
echo -e "$test_details" >> $GITHUB_OUTPUT
281-
echo "EOF" >> $GITHUB_OUTPUT
228+
chmod +x .github/scripts/test-analyzer.sh
229+
./.github/scripts/test-analyzer.sh >> $GITHUB_OUTPUT
282230
283231
- name: Update PR description
284232
uses: actions/github-script@v6

0 commit comments

Comments
 (0)