Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 75 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,115 @@ env:
FOUNDRY_PROFILE: ci

jobs:
check:
build-and-test:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
solc-version: [0.8.19, 0.8.31] # Add more versions if needed
shard-group: [1,2] # Split tests into parallel shards

name: Foundry project
runs-on: ubuntu-latest
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1
# 1. Harden the runner
- name: Harden the runner
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
# 2. Checkout repo
- uses: actions/checkout@v4
with:
submodules: recursive

# 3. Install Foundry
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@82dee4ba654bd2146511f85f0d013af94670c4de # v1.4.0
uses: foundry-rs/foundry-toolchain@v1
with:
version: stable
cache: true

- name: Install Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
# 4. Setup Go
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
cache-dependency-path: |
go.sum
scripts/go-ffi/go.sum

# 5. Install just
- name: Install just
run: curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin

- name: Show Forge version
run: forge --version
# 6. Show Forge version
- run: forge --version

# 7. Install project dependencies
- name: Install dependencies
run: make deps

# 8. Cache Forge build artifacts
- name: Cache Forge build
uses: actions/cache@v3
with:
path: |
lib
out
cache
key: forge-build-${{ runner.os }}-${{ matrix.solc-version }}-${{ hashFiles('src/**/*.sol') }}

# 9. Set Solidity compiler version
- name: Set Solidity version
run: forge config --solc-version ${{ matrix.solc-version }}

# 10. Run lint / format check
- name: Run Forge fmt check
run: just lint-check
id: fmt

- name: Run Forge build
# 11. Build contracts (incremental if cache hits)
- name: Build contracts
run: just forge-build
id: build

# 12. Validate semver-lock
- name: Validate semver-lock
id: semver-lock
run: |
just semver-lock-no-build
git diff --exit-code snapshots/semver-lock.json

- name: Run Forge tests
run: just test
id: test
# 13. Detect changed contracts
- name: Detect changed contracts
id: changed
run: |
git fetch origin ${{ github.base_ref }}
CHANGED_CONTRACTS=$(git diff --name-only origin/${{ github.base_ref }} | grep '\.sol$' || true)
echo "CHANGED_CONTRACTS=$CHANGED_CONTRACTS" >> $GITHUB_ENV

# 14. Run affected tests (sharded)
- name: Run affected tests
if: env.CHANGED_CONTRACTS != ''
run: |
TOTAL_SHARDS=2
SHARD=${{ matrix.shard-group }}
echo "Running affected tests for shard $SHARD/$TOTAL_SHARDS..."
for contract in $CHANGED_CONTRACTS; do
TEST_NAME=$(basename $contract .sol)
echo "Running tests for $TEST_NAME..."
forge test \
--match-contract $TEST_NAME \
--fork-url ${{ secrets.ALCHEMY_URL }} \
--gas-report \
--ci \
--parallel 4 \
--shard $SHARD/$TOTAL_SHARDS
done

# 15. Fallback: Run all tests if no contracts changed
- name: Run all tests (fallback)
if: env.CHANGED_CONTRACTS == ''
run: forge test \
--fork-url ${{ secrets.ALCHEMY_URL }} \
--gas-report \
--ci \
--parallel 4 \
--shard ${{ matrix.shard-group }}/2