Skip to content

Commit 832f61a

Browse files
committed
chore: add testbox workflows and scripts
1 parent 0119cf8 commit 832f61a

5 files changed

Lines changed: 487 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Blacksmith PR Testbox Windows
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
testbox_id:
7+
type: string
8+
description: "Testbox session ID"
9+
required: true
10+
pull_request:
11+
paths:
12+
- ".github/workflows/pr-testbox-windows.yml"
13+
- "scripts/test-pr-check-windows.ps1"
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
pr-testbox-windows:
20+
runs-on: blacksmith-4vcpu-windows-2025
21+
22+
steps:
23+
- name: Begin Testbox
24+
if: ${{ github.event_name == 'workflow_dispatch' }}
25+
uses: useblacksmith/begin-testbox@v2
26+
with:
27+
testbox_id: ${{ inputs.testbox_id }}
28+
29+
- name: ⬇️ Checkout repo
30+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
31+
with:
32+
fetch-depth: 0
33+
persist-credentials: false
34+
35+
- name: ⎔ Setup pnpm
36+
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
37+
with:
38+
version: 10.33.2
39+
40+
- name: ⎔ Setup node
41+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
42+
with:
43+
node-version: 20.20.2
44+
45+
- name: 📥 Download CLI deps
46+
run: pnpm install --frozen-lockfile --filter trigger.dev...
47+
48+
- name: 📀 Generate Prisma Client
49+
run: pnpm run generate
50+
51+
- name: 🔧 Build v3 cli monorepo dependencies
52+
run: pnpm run build --filter trigger.dev^...
53+
54+
- name: 🔧 Build worker template files
55+
run: pnpm --filter trigger.dev run --if-present build:workers
56+
57+
- name: Enable corepack
58+
run: corepack enable
59+
60+
- name: Run Testbox
61+
uses: useblacksmith/run-testbox@v2
62+
if: ${{ always() && github.event_name == 'workflow_dispatch' }}

.github/workflows/pr-testbox.yml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Blacksmith PR Testbox
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
testbox_id:
7+
type: string
8+
description: "Testbox session ID"
9+
required: true
10+
pull_request:
11+
paths:
12+
- ".github/workflows/pr-testbox.yml"
13+
- "scripts/test-pr-check.sh"
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
pr-testbox:
20+
runs-on: blacksmith-8vcpu-ubuntu-2404
21+
env:
22+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
23+
24+
steps:
25+
- name: Begin Testbox
26+
if: ${{ github.event_name == 'workflow_dispatch' }}
27+
uses: useblacksmith/begin-testbox@v2
28+
with:
29+
testbox_id: ${{ inputs.testbox_id }}
30+
31+
- name: 🔧 Disable IPv6
32+
run: |
33+
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
34+
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
35+
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1
36+
37+
- name: 🔧 Configure docker address pool
38+
run: |
39+
CONFIG='{
40+
"default-address-pools" : [
41+
{
42+
"base" : "172.17.0.0/12",
43+
"size" : 20
44+
},
45+
{
46+
"base" : "192.168.0.0/16",
47+
"size" : 24
48+
}
49+
]
50+
}'
51+
mkdir -p /etc/docker
52+
echo "$CONFIG" | sudo tee /etc/docker/daemon.json
53+
54+
- name: 🔧 Restart docker daemon
55+
run: sudo systemctl restart docker
56+
57+
- name: ⬇️ Checkout repo
58+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
59+
with:
60+
fetch-depth: 0
61+
persist-credentials: false
62+
63+
- name: ⎔ Setup pnpm
64+
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
65+
with:
66+
version: 10.33.2
67+
68+
- name: ⎔ Setup Node 22 for SDK compatibility checks
69+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
70+
with:
71+
node-version: 22.12
72+
73+
- name: ⎔ Setup active Node 20
74+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
75+
with:
76+
node-version: 20.20.2
77+
cache: "pnpm"
78+
79+
- name: 🥟 Setup Bun
80+
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
81+
with:
82+
bun-version: latest
83+
84+
- name: 🦕 Setup Deno
85+
uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2.0.4
86+
with:
87+
deno-version: v2.x
88+
89+
- name: 🐳 Login to DockerHub
90+
if: ${{ env.DOCKERHUB_USERNAME }}
91+
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
92+
with:
93+
username: ${{ secrets.DOCKERHUB_USERNAME }}
94+
password: ${{ secrets.DOCKERHUB_TOKEN }}
95+
96+
- name: 🐳 Skipping DockerHub login (no secrets available)
97+
if: ${{ !env.DOCKERHUB_USERNAME }}
98+
run: echo "DockerHub login skipped because secrets are not available."
99+
100+
- name: 🐳 Pre-pull testcontainer images
101+
if: ${{ env.DOCKERHUB_USERNAME }}
102+
run: |
103+
pull() {
104+
for attempt in 1 2 3; do
105+
docker pull "$1" && return 0
106+
echo "::warning::docker pull $1 failed (attempt ${attempt}/3); retrying in 10s"
107+
sleep 10
108+
done
109+
echo "::error::docker pull $1 failed after 3 attempts"
110+
return 1
111+
}
112+
113+
echo "Pre-pulling Docker images with authenticated session..."
114+
pull postgres:14
115+
pull clickhouse/clickhouse-server:26.2.19.43-alpine@sha256:c6ad6a7eb2fb5999df3adfb8b69a0c7222c68fa9b8f6b04a088564ebbc959251
116+
pull redis:7.2
117+
pull testcontainers/ryuk:0.11.0
118+
pull testcontainers/ryuk:0.14.0
119+
pull electricsql/electric:1.2.4
120+
pull minio/minio:latest
121+
echo "Image pre-pull complete"
122+
123+
- name: 📥 Download deps
124+
run: pnpm install --frozen-lockfile
125+
126+
- name: 📀 Generate Prisma Client
127+
run: pnpm run generate
128+
129+
- name: Run Testbox
130+
uses: useblacksmith/run-testbox@v2
131+
if: ${{ always() && github.event_name == 'workflow_dispatch' }}

scripts/blacksmith.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Blacksmith Testboxes
2+
3+
Use Testboxes to validate changes in CI-like runners instead of running tests locally.
4+
5+
Always run `blacksmith testbox` commands from the repository root:
6+
7+
```bash
8+
cd "$(git rev-parse --show-toplevel)"
9+
```
10+
11+
## PR checks Testbox
12+
13+
The Linux PR Testbox covers the normal Linux PR checks: format, lint, typecheck, exports, unit test shards, webapp e2e, Linux CLI e2e, and SDK compatibility checks.
14+
15+
Warm it up:
16+
17+
```bash
18+
blacksmith testbox warmup pr-testbox.yml --idle-timeout 60
19+
```
20+
21+
Run the PR checks against your current working tree:
22+
23+
```bash
24+
blacksmith testbox run --id <linux-testbox-id> "scripts/test-pr-check.sh"
25+
```
26+
27+
## Windows PR checks Testbox
28+
29+
The Windows PR Testbox covers the Windows CLI v3 e2e matrix row.
30+
31+
Warm it up:
32+
33+
```bash
34+
blacksmith testbox warmup pr-testbox-windows.yml --idle-timeout 60
35+
```
36+
37+
Run the Windows checks against your current working tree:
38+
39+
```bash
40+
blacksmith testbox run --id <windows-testbox-id> "pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/test-pr-check-windows.ps1"
41+
```
42+
43+
## Running both
44+
45+
```bash
46+
linux_id=<linux-testbox-id>
47+
windows_id=<windows-testbox-id>
48+
49+
blacksmith testbox run --id "$linux_id" "scripts/test-pr-check.sh"
50+
blacksmith testbox run --id "$windows_id" "pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/test-pr-check-windows.ps1"
51+
```
52+
53+
## Notes
54+
55+
- The workflow files must be merged before GitHub can dispatch them via `workflow_dispatch`.
56+
- `blacksmith testbox run` syncs your local tracked and unignored files before running the command.
57+
- If you change dependency manifests, the scripts run `pnpm install` again inside the Testbox.
58+
- The Linux Testbox intentionally does not cover the Windows CLI row; use the Windows Testbox for that.
59+
- Stop Testboxes when you are finished:
60+
61+
```bash
62+
blacksmith testbox stop --id <testbox-id>
63+
```

scripts/test-pr-check-windows.ps1

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
Set-Location (git rev-parse --show-toplevel)
4+
5+
function Start-Section {
6+
param([Parameter(Mandatory = $true)][string]$Title)
7+
8+
Write-Host ""
9+
Write-Host "::group::$Title"
10+
}
11+
12+
function Stop-Section {
13+
Write-Host "::endgroup::"
14+
}
15+
16+
function Invoke-Native {
17+
param(
18+
[Parameter(Mandatory = $true)][string]$Command,
19+
[Parameter(ValueFromRemainingArguments = $true)][string[]]$Arguments
20+
)
21+
22+
& $Command @Arguments
23+
if ($LASTEXITCODE -ne 0) {
24+
throw "Command failed with exit code ${LASTEXITCODE}: $Command $($Arguments -join ' ')"
25+
}
26+
}
27+
28+
function Invoke-Section {
29+
param(
30+
[Parameter(Mandatory = $true)][string]$Title,
31+
[Parameter(Mandatory = $true)][scriptblock]$ScriptBlock
32+
)
33+
34+
Start-Section $Title
35+
try {
36+
& $ScriptBlock
37+
} finally {
38+
Stop-Section
39+
}
40+
}
41+
42+
Invoke-Section "Install CLI dependencies" {
43+
Invoke-Native pnpm install --frozen-lockfile --filter trigger.dev...
44+
}
45+
46+
Invoke-Section "Generate Prisma client" {
47+
Invoke-Native pnpm run generate
48+
}
49+
50+
Invoke-Section "Build CLI monorepo dependencies" {
51+
Invoke-Native pnpm run build --filter trigger.dev^...
52+
}
53+
54+
Invoke-Section "Build worker template files" {
55+
Invoke-Native pnpm --filter trigger.dev run --if-present build:workers
56+
}
57+
58+
Invoke-Section "Enable corepack" {
59+
Invoke-Native corepack enable
60+
}
61+
62+
Invoke-Section "CLI v3 E2E tests (npm)" {
63+
$env:LOG = "debug"
64+
$env:PM = "npm"
65+
Invoke-Native pnpm --filter trigger.dev run test:e2e
66+
}
67+
68+
Invoke-Section "CLI v3 E2E tests (pnpm)" {
69+
$env:LOG = "debug"
70+
$env:PM = "pnpm"
71+
Invoke-Native pnpm --filter trigger.dev run test:e2e
72+
}
73+
74+
Write-Host "Windows PR checks completed."

0 commit comments

Comments
 (0)