Skip to content

Commit 3cc02af

Browse files
committed
test bb ci
1 parent 76c79a4 commit 3cc02af

File tree

1 file changed

+211
-0
lines changed

1 file changed

+211
-0
lines changed

.github/workflows/bb-flow.yml

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
name: "Test a Forge project"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
cache-path:
7+
default: |
8+
cache
9+
node_modules
10+
out
11+
out-optimized
12+
required: false
13+
type: "string"
14+
15+
foundry-fuzz-runs:
16+
default: 1000
17+
required: false
18+
type: "number"
19+
20+
foundry-invariant-depth:
21+
default: 20
22+
required: false
23+
type: "number"
24+
25+
foundry-invariant-runs:
26+
default: 20
27+
required: false
28+
type: "number"
29+
30+
foundry-profile:
31+
default: "default"
32+
required: false
33+
type: "string"
34+
35+
foundry-version:
36+
default: "v1.3.6"
37+
required: false
38+
type: "string"
39+
40+
fuzz-seed:
41+
default: false
42+
required: false
43+
type: "boolean"
44+
45+
match-path:
46+
default: "tests/{integration,utils}/**/*.sol"
47+
required: false
48+
type: "string"
49+
50+
name:
51+
default: "Forge tests"
52+
required: false
53+
type: "string"
54+
55+
retry-attempts:
56+
default: 1
57+
description: "Number of attempts to retry if the test fails"
58+
required: false
59+
type: "number"
60+
61+
working-directory:
62+
default: "flow"
63+
required: false
64+
type: "string"
65+
66+
secrets:
67+
MAINNET_RPC_URL:
68+
required: false
69+
ROUTEMESH_API_KEY:
70+
required: false
71+
72+
workflow_dispatch:
73+
inputs:
74+
match-path:
75+
default: "tests/{integration,utils}/**/*.sol"
76+
description: "Path pattern for tests to run"
77+
required: false
78+
type: "string"
79+
80+
working-directory:
81+
default: "flow"
82+
description: "Working directory (e.g., flow, lockup, airdrops)"
83+
required: false
84+
type: "string"
85+
86+
push:
87+
branches:
88+
- "main"
89+
- "staging"
90+
- "bb-staging-demo"
91+
92+
jobs:
93+
forge-test:
94+
name: ${{ inputs.name }}
95+
defaults:
96+
run:
97+
working-directory: ${{ inputs.working-directory }}
98+
env:
99+
FOUNDRY_INVARIANT_DEPTH: ${{ inputs.foundry-invariant-depth }}
100+
FOUNDRY_INVARIANT_RUNS: ${{ inputs.foundry-invariant-runs }}
101+
FOUNDRY_FUZZ_RUNS: ${{ inputs.foundry-fuzz-runs }}
102+
FOUNDRY_PROFILE: ${{ inputs.foundry-profile }}
103+
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
104+
ROUTEMESH_API_KEY: ${{ secrets.ROUTEMESH_API_KEY }}
105+
runs-on: "ubuntu-latest"
106+
steps:
107+
- name: "Check out the repo"
108+
uses: "actions/checkout@v4"
109+
110+
- name: Install Rust
111+
uses: actions-rs/toolchain@v1
112+
with:
113+
toolchain: stable
114+
override: true
115+
116+
- name: Clone Foundry repository
117+
run: |
118+
if [ ! -d "foundry" ]; then
119+
git clone https://github.com/BuildBearLabs/foundry.git -b feat/single_json_output
120+
fi
121+
shell: bash
122+
123+
- name: Set Foundry commit hash
124+
id: foundry_hash
125+
run: echo "hash=$(git -C foundry rev-parse HEAD)" >> $GITHUB_OUTPUT
126+
127+
- name: Restore Foundry build cache
128+
uses: actions/cache@v3
129+
id: cache-foundry
130+
with:
131+
path: |
132+
foundry/target
133+
$HOME/.config/.foundry/bin
134+
key: ${{ runner.os }}-foundry-build-${{ steps.foundry_hash.outputs.hash }}
135+
136+
- name: Build Foundry from source or copy from target
137+
run: |
138+
FOUNDRY_BIN="$HOME/.config/.foundry/bin/forge"
139+
TARGET_FORGE="foundry/target/debug/forge"
140+
141+
mkdir -p "$(dirname "$FOUNDRY_BIN")"
142+
143+
if [ -f "$FOUNDRY_BIN" ]; then
144+
echo "✅ Forge binary found in bin path, skipping build."
145+
elif [ -f "$TARGET_FORGE" ]; then
146+
echo "✅ Forge binary found in target/debug, copying to bin."
147+
cp "$TARGET_FORGE" "$FOUNDRY_BIN"
148+
else
149+
echo "❌ Forge binary not found, building from source..."
150+
cd foundry
151+
cargo build
152+
cp target/debug/forge "$FOUNDRY_BIN"
153+
fi
154+
155+
echo "$(dirname "$FOUNDRY_BIN")" >> $GITHUB_PATH
156+
157+
- name: Save Foundry build cache
158+
if: steps.cache-foundry.outputs.cache-hit != 'true'
159+
uses: actions/cache/save@v3
160+
with:
161+
path: |
162+
foundry/target
163+
$HOME/.config/.foundry/bin
164+
key: ${{ runner.os }}-foundry-build-${{ steps.foundry_hash.outputs.hash }}
165+
166+
- name: Show Forge version
167+
run: forge --version
168+
169+
- name: "Install Bun"
170+
uses: "oven-sh/setup-bun@v2"
171+
with:
172+
bun-version: "latest"
173+
174+
- name: "Install the Node.js dependencies"
175+
run: "bun install --frozen-lockfile"
176+
177+
- name: "Build contracts with the specified profiles"
178+
run: |
179+
echo "Building with profile: test-optimized"
180+
FOUNDRY_PROFILE=test-optimized forge build
181+
182+
- name: "Run the tests"
183+
run: |
184+
for attempt in $(seq 1 ${{ inputs.retry-attempts }}); do
185+
if forge test --match-path "${{ inputs.match-path }}"; then
186+
break
187+
elif [ $attempt -eq ${{ inputs.retry-attempts }} ]; then
188+
exit 1
189+
else
190+
echo "♻️ Attempt $attempt: tests failed, retrying in 60 seconds..."
191+
sleep 60
192+
fi
193+
done
194+
continue-on-error: true
195+
196+
- name: "Debug API Key"
197+
run: |
198+
echo "API Key length: ${#BUILDBEAR_API_KEY}"
199+
echo "API Key (masked): ${BUILDBEAR_API_KEY:0:8}..."
200+
env:
201+
BUILDBEAR_API_KEY: ${{ secrets.BUILDBEAR_API_KEY }}
202+
203+
- name: "Run BB Action CI"
204+
uses: BuildBearLabs/buildbear_x_action@feat/test-simulation-workflow
205+
with:
206+
buildbear-api-key: ${{ secrets.BUILDBEAR_API_KEY }}
207+
208+
- name: "Add summary"
209+
run: | # shell
210+
echo "## Result for ${{ inputs.name }}" >> $GITHUB_STEP_SUMMARY
211+
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)