Skip to content

Commit 7c791dd

Browse files
authored
Improve unit test workflow performance (#2096)
* shard unit tests * temp enable for all pushes * fix test workflow * update to latest vitest and only add to root package.json * additionally use default reporter * gather reports before uploading * split up slow replication tests * split up unit tests workflow * move workflows to parent dir * use new paths in parent workflow * prevent artifact clashes * we always need to create the reports dir * speed up merge reports * gather reports even when tests fail * fix artifact patterns * increase shards * disable push trigger again * improve dequeue snapshot test reliability
1 parent cf37359 commit 7c791dd

21 files changed

+1114
-1521
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: "🧪 Unit Tests: Internal"
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_call:
8+
9+
jobs:
10+
unitTests:
11+
name: "🧪 Unit Tests: Internal"
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
shardIndex: [1, 2, 3, 4, 5, 6, 7, 8]
16+
shardTotal: [8]
17+
env:
18+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
19+
SHARD_INDEX: ${{ matrix.shardIndex }}
20+
SHARD_TOTAL: ${{ matrix.shardTotal }}
21+
steps:
22+
- name: 🔧 Disable IPv6
23+
run: |
24+
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
25+
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
26+
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1
27+
28+
- name: 🔧 Configure docker address pool
29+
run: |
30+
CONFIG='{
31+
"default-address-pools" : [
32+
{
33+
"base" : "172.17.0.0/12",
34+
"size" : 20
35+
},
36+
{
37+
"base" : "192.168.0.0/16",
38+
"size" : 24
39+
}
40+
]
41+
}'
42+
mkdir -p /etc/docker
43+
echo "$CONFIG" | sudo tee /etc/docker/daemon.json
44+
45+
- name: 🔧 Restart docker daemon
46+
run: sudo systemctl restart docker
47+
48+
- name: ⬇️ Checkout repo
49+
uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0
52+
53+
- name: ⎔ Setup pnpm
54+
uses: pnpm/action-setup@v4
55+
with:
56+
version: 8.15.5
57+
58+
- name: ⎔ Setup node
59+
uses: buildjet/setup-node@v4
60+
with:
61+
node-version: 20.11.1
62+
cache: "pnpm"
63+
64+
# ..to avoid rate limits when pulling images
65+
- name: 🐳 Login to DockerHub
66+
if: ${{ env.DOCKERHUB_USERNAME }}
67+
uses: docker/login-action@v3
68+
with:
69+
username: ${{ secrets.DOCKERHUB_USERNAME }}
70+
password: ${{ secrets.DOCKERHUB_TOKEN }}
71+
- name: 🐳 Skipping DockerHub login (no secrets available)
72+
if: ${{ !env.DOCKERHUB_USERNAME }}
73+
run: echo "DockerHub login skipped because secrets are not available."
74+
75+
- name: 📥 Download deps
76+
run: pnpm install --frozen-lockfile
77+
78+
- name: 📀 Generate Prisma Client
79+
run: pnpm run generate
80+
81+
- name: 🧪 Run Internal Unit Tests
82+
run: pnpm run test:internal --reporter=default --reporter=blob --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
83+
84+
- name: Gather all reports
85+
if: ${{ !cancelled() }}
86+
run: |
87+
mkdir -p .vitest-reports
88+
find . -type f -path '*/.vitest-reports/blob-*.json' \
89+
-exec bash -c 'src="$1"; basename=$(basename "$src"); pkg=$(dirname "$src" | sed "s|^\./||;s|/\.vitest-reports$||;s|/|_|g"); cp "$src" ".vitest-reports/${pkg}-${basename}"' _ {} \;
90+
91+
- name: Upload blob reports to GitHub Actions Artifacts
92+
if: ${{ !cancelled() }}
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: internal-blob-report-${{ matrix.shardIndex }}
96+
path: .vitest-reports/*
97+
include-hidden-files: true
98+
retention-days: 1
99+
100+
merge-reports:
101+
name: "📊 Merge Reports"
102+
if: ${{ !cancelled() }}
103+
needs: [unitTests]
104+
runs-on: ubuntu-latest
105+
steps:
106+
- name: ⬇️ Checkout repo
107+
uses: actions/checkout@v4
108+
with:
109+
fetch-depth: 0
110+
111+
- name: ⎔ Setup pnpm
112+
uses: pnpm/action-setup@v4
113+
with:
114+
version: 8.15.5
115+
116+
- name: ⎔ Setup node
117+
uses: buildjet/setup-node@v4
118+
with:
119+
node-version: 20.11.1
120+
# no cache enabled, we're not installing deps
121+
122+
- name: Download blob reports from GitHub Actions Artifacts
123+
uses: actions/download-artifact@v4
124+
with:
125+
path: .vitest-reports
126+
pattern: internal-blob-report-*
127+
merge-multiple: true
128+
129+
- name: Merge reports
130+
run: pnpm dlx vitest run --merge-reports
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: "🧪 Unit Tests: Packages"
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_call:
8+
9+
jobs:
10+
unitTests:
11+
name: "🧪 Unit Tests: Packages"
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
shardIndex: [1]
16+
shardTotal: [1]
17+
env:
18+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
19+
SHARD_INDEX: ${{ matrix.shardIndex }}
20+
SHARD_TOTAL: ${{ matrix.shardTotal }}
21+
steps:
22+
- name: 🔧 Disable IPv6
23+
run: |
24+
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
25+
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
26+
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1
27+
28+
- name: 🔧 Configure docker address pool
29+
run: |
30+
CONFIG='{
31+
"default-address-pools" : [
32+
{
33+
"base" : "172.17.0.0/12",
34+
"size" : 20
35+
},
36+
{
37+
"base" : "192.168.0.0/16",
38+
"size" : 24
39+
}
40+
]
41+
}'
42+
mkdir -p /etc/docker
43+
echo "$CONFIG" | sudo tee /etc/docker/daemon.json
44+
45+
- name: 🔧 Restart docker daemon
46+
run: sudo systemctl restart docker
47+
48+
- name: ⬇️ Checkout repo
49+
uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0
52+
53+
- name: ⎔ Setup pnpm
54+
uses: pnpm/action-setup@v4
55+
with:
56+
version: 8.15.5
57+
58+
- name: ⎔ Setup node
59+
uses: buildjet/setup-node@v4
60+
with:
61+
node-version: 20.11.1
62+
cache: "pnpm"
63+
64+
# ..to avoid rate limits when pulling images
65+
- name: 🐳 Login to DockerHub
66+
if: ${{ env.DOCKERHUB_USERNAME }}
67+
uses: docker/login-action@v3
68+
with:
69+
username: ${{ secrets.DOCKERHUB_USERNAME }}
70+
password: ${{ secrets.DOCKERHUB_TOKEN }}
71+
- name: 🐳 Skipping DockerHub login (no secrets available)
72+
if: ${{ !env.DOCKERHUB_USERNAME }}
73+
run: echo "DockerHub login skipped because secrets are not available."
74+
75+
- name: 📥 Download deps
76+
run: pnpm install --frozen-lockfile
77+
78+
- name: 📀 Generate Prisma Client
79+
run: pnpm run generate
80+
81+
- name: 🧪 Run Package Unit Tests
82+
run: pnpm run test:packages --reporter=default --reporter=blob --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
83+
84+
- name: Gather all reports
85+
if: ${{ !cancelled() }}
86+
run: |
87+
mkdir -p .vitest-reports
88+
find . -type f -path '*/.vitest-reports/blob-*.json' \
89+
-exec bash -c 'src="$1"; basename=$(basename "$src"); pkg=$(dirname "$src" | sed "s|^\./||;s|/\.vitest-reports$||;s|/|_|g"); cp "$src" ".vitest-reports/${pkg}-${basename}"' _ {} \;
90+
91+
- name: Upload blob reports to GitHub Actions Artifacts
92+
if: ${{ !cancelled() }}
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: packages-blob-report-${{ matrix.shardIndex }}
96+
path: .vitest-reports/*
97+
include-hidden-files: true
98+
retention-days: 1
99+
100+
merge-reports:
101+
name: "📊 Merge Reports"
102+
if: ${{ !cancelled() }}
103+
needs: [unitTests]
104+
runs-on: ubuntu-latest
105+
steps:
106+
- name: ⬇️ Checkout repo
107+
uses: actions/checkout@v4
108+
with:
109+
fetch-depth: 0
110+
111+
- name: ⎔ Setup pnpm
112+
uses: pnpm/action-setup@v4
113+
with:
114+
version: 8.15.5
115+
116+
- name: ⎔ Setup node
117+
uses: buildjet/setup-node@v4
118+
with:
119+
node-version: 20.11.1
120+
# no cache enabled, we're not installing deps
121+
122+
- name: Download blob reports from GitHub Actions Artifacts
123+
uses: actions/download-artifact@v4
124+
with:
125+
path: .vitest-reports
126+
pattern: packages-blob-report-*
127+
merge-multiple: true
128+
129+
- name: Merge reports
130+
run: pnpm dlx vitest run --merge-reports
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: "🧪 Unit Tests: Webapp"
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_call:
8+
9+
jobs:
10+
unitTests:
11+
name: "🧪 Unit Tests: Webapp"
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
shardIndex: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
16+
shardTotal: [10]
17+
env:
18+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
19+
SHARD_INDEX: ${{ matrix.shardIndex }}
20+
SHARD_TOTAL: ${{ matrix.shardTotal }}
21+
steps:
22+
- name: 🔧 Disable IPv6
23+
run: |
24+
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
25+
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
26+
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1
27+
28+
- name: 🔧 Configure docker address pool
29+
run: |
30+
CONFIG='{
31+
"default-address-pools" : [
32+
{
33+
"base" : "172.17.0.0/12",
34+
"size" : 20
35+
},
36+
{
37+
"base" : "192.168.0.0/16",
38+
"size" : 24
39+
}
40+
]
41+
}'
42+
mkdir -p /etc/docker
43+
echo "$CONFIG" | sudo tee /etc/docker/daemon.json
44+
45+
- name: 🔧 Restart docker daemon
46+
run: sudo systemctl restart docker
47+
48+
- name: ⬇️ Checkout repo
49+
uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0
52+
53+
- name: ⎔ Setup pnpm
54+
uses: pnpm/action-setup@v4
55+
with:
56+
version: 8.15.5
57+
58+
- name: ⎔ Setup node
59+
uses: buildjet/setup-node@v4
60+
with:
61+
node-version: 20.11.1
62+
cache: "pnpm"
63+
64+
# ..to avoid rate limits when pulling images
65+
- name: 🐳 Login to DockerHub
66+
if: ${{ env.DOCKERHUB_USERNAME }}
67+
uses: docker/login-action@v3
68+
with:
69+
username: ${{ secrets.DOCKERHUB_USERNAME }}
70+
password: ${{ secrets.DOCKERHUB_TOKEN }}
71+
- name: 🐳 Skipping DockerHub login (no secrets available)
72+
if: ${{ !env.DOCKERHUB_USERNAME }}
73+
run: echo "DockerHub login skipped because secrets are not available."
74+
75+
- name: 📥 Download deps
76+
run: pnpm install --frozen-lockfile
77+
78+
- name: 📀 Generate Prisma Client
79+
run: pnpm run generate
80+
81+
- name: 🧪 Run Webapp Unit Tests
82+
run: pnpm run test:webapp --reporter=default --reporter=blob --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
83+
env:
84+
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
85+
DIRECT_URL: postgresql://postgres:postgres@localhost:5432/postgres
86+
SESSION_SECRET: "secret"
87+
MAGIC_LINK_SECRET: "secret"
88+
ENCRYPTION_KEY: "secret"
89+
90+
- name: Gather all reports
91+
if: ${{ !cancelled() }}
92+
run: |
93+
mkdir -p .vitest-reports
94+
find . -type f -path '*/.vitest-reports/blob-*.json' \
95+
-exec bash -c 'src="$1"; basename=$(basename "$src"); pkg=$(dirname "$src" | sed "s|^\./||;s|/\.vitest-reports$||;s|/|_|g"); cp "$src" ".vitest-reports/${pkg}-${basename}"' _ {} \;
96+
97+
- name: Upload blob reports to GitHub Actions Artifacts
98+
if: ${{ !cancelled() }}
99+
uses: actions/upload-artifact@v4
100+
with:
101+
name: webapp-blob-report-${{ matrix.shardIndex }}
102+
path: .vitest-reports/*
103+
include-hidden-files: true
104+
retention-days: 1
105+
106+
merge-reports:
107+
name: "📊 Merge Reports"
108+
if: ${{ !cancelled() }}
109+
needs: [unitTests]
110+
runs-on: ubuntu-latest
111+
steps:
112+
- name: ⬇️ Checkout repo
113+
uses: actions/checkout@v4
114+
with:
115+
fetch-depth: 0
116+
117+
- name: ⎔ Setup pnpm
118+
uses: pnpm/action-setup@v4
119+
with:
120+
version: 8.15.5
121+
122+
- name: ⎔ Setup node
123+
uses: buildjet/setup-node@v4
124+
with:
125+
node-version: 20.11.1
126+
# no cache enabled, we're not installing deps
127+
128+
- name: Download blob reports from GitHub Actions Artifacts
129+
uses: actions/download-artifact@v4
130+
with:
131+
path: .vitest-reports
132+
pattern: webapp-blob-report-*
133+
merge-multiple: true
134+
135+
- name: Merge reports
136+
run: pnpm dlx vitest run --merge-reports

0 commit comments

Comments
 (0)