Skip to content

Commit 6bbf82b

Browse files
authored
add test runners for PR submissions
add workflow for running tests
2 parents 9ec15ae + 0cb78f7 commit 6bbf82b

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Test
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: [main]
11+
12+
jobs:
13+
# Discover packages that have test directories
14+
discover:
15+
permissions:
16+
contents: read
17+
runs-on: ubuntu-latest
18+
outputs:
19+
packages: ${{ steps.find-packages.outputs.packages }}
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Find packages with tests
25+
id: find-packages
26+
run: |
27+
# Find all packages that have a test directory or test files
28+
packages=$(find packages -maxdepth 2 -type d -name "test" | sed 's|packages/||' | sed 's|/test||' | jq -R -s -c 'split("\n") | map(select(length > 0))')
29+
30+
# If no test directories found, check for *.test.ts files in src
31+
if [ "$packages" = "[]" ]; then
32+
packages=$(find packages -maxdepth 3 -name "*.test.ts" | sed 's|packages/||' | cut -d'/' -f1 | sort -u | jq -R -s -c 'split("\n") | map(select(length > 0))')
33+
else
34+
# Also include packages with *.test.ts files in src
35+
src_packages=$(find packages -maxdepth 3 -name "*.test.ts" | sed 's|packages/||' | cut -d'/' -f1 | sort -u)
36+
if [ -n "$src_packages" ]; then
37+
all_packages=$(echo -e "$packages\n$src_packages" | tr -d '[]"' | tr ',' '\n' | sort -u | jq -R -s -c 'split("\n") | map(select(length > 0))')
38+
packages="$all_packages"
39+
fi
40+
fi
41+
42+
echo "packages=$packages" >> $GITHUB_OUTPUT
43+
echo "Found packages with tests: $packages"
44+
45+
test:
46+
permissions:
47+
contents: read
48+
needs: discover
49+
if: ${{ needs.discover.outputs.packages != '[]' }}
50+
runs-on: ubuntu-latest
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
package: ${{ fromJson(needs.discover.outputs.packages) }}
55+
56+
steps:
57+
- name: Checkout
58+
uses: actions/checkout@v4
59+
60+
- name: Setup Node
61+
uses: actions/setup-node@v4
62+
with:
63+
node-version: "23.x"
64+
cache: "npm"
65+
66+
- name: Install dependencies
67+
run: npm ci
68+
69+
- name: Install rollup linux binary
70+
run: npm install @rollup/rollup-linux-x64-gnu --no-save
71+
72+
- name: Build
73+
run: npm run build
74+
75+
- name: Run tests for ${{ matrix.package }}
76+
run: npm run test --workspace=packages/${{ matrix.package }}

0 commit comments

Comments
 (0)