Skip to content

Commit 243d52b

Browse files
authored
chore: add testbox workflows and scripts (#4071)
Needed to trigger Blacksmith Testbox workflows.
1 parent 0119cf8 commit 243d52b

5 files changed

Lines changed: 493 additions & 0 deletions

File tree

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

.github/workflows/pr-testbox.yml

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