Documentation
CI/CD Service

Deployment and Testing with Foundry

Learn how to deploy and test your Foundry project's contracts with BuildBear's CI/CD service.

Install the BuildBear Foundry Fork

Using Foundry with BuildBear's CI/CD service requires installing our fork of Foundry, which includes essential updates for:

  • Generating enhanced artifacts for test simulation
  • Enabling automatic contract verification
  • Improved integration with BuildBear's infrastructure

Install our Foundry fork instead of the standard version:

curl -L https://github.com/BuildBearLabs/foundry/releases/latest/download/foundry_nightly_linux_amd64.tar.gz | tar xzf - -C ~/.foundry/bin/

Cheatcode Support: BuildBear currently supports 45 Foundry cheat codes. You can see the entire list here.

Setup GitHub Actions

BuildBear's CI/CD system uses GitHub Actions. We encourage you to check out the official GitHub Actions documentation for more information. For the purposes of this quickstart, you'll only need to create a .github/workflows directory at the top-level of your repository. Workflows are YAML files that we'll put in this folder.

Workflow File

To get started with Foundry you can use this workflow:

name: Deploy to BuildBear Sandbox
 
on: [push]
 
jobs:
  test:
    runs-on: ubuntu-latest
 
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          submodules: recursive
 
      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
 
      # Cache Foundry repository
      - name: Cache Foundry repository
        uses: actions/cache@v3
        with:
          path: foundry
          key: ${{ runner.os }}-foundry-${{ hashFiles('**/foundry/.gitmodules') }}
          restore-keys: |
            ${{ runner.os }}-foundry-
 
      # Cache build artifacts
      - name: Cache build artifacts
        uses: actions/cache@v3
        with:
          path: $HOME/.config/.foundry/bin
          key: ${{ runner.os }}-forge-${{ hashFiles('foundry/Cargo.toml') }}
          restore-keys: |
            ${{ runner.os }}-forge-
            
      - name: Clone Foundry repository
        run: |
          if [ ! -d "foundry" ]; then
            git clone https://github.com/BuildBearLabs/foundry.git
          fi
        shell: bash
 
      - name: Build Foundry from source
        run: |
          cd foundry
          cargo build
          mkdir -p $HOME/.config/.foundry/bin
          cp target/debug/forge $HOME/.config/.foundry/bin/
          echo "PATH=$HOME/.config/.foundry/bin:$PATH" >> $GITHUB_ENV
        shell: bash
 
      - name: Show Forge version
        run: forge --version
 
      - name: Run Forge Tests # Optional
        run: forge test -vvv
 
      - name: Run BB Action CI
        uses: BuildBearLabs/[email protected]
        with:
          network: |
            [
              {
                "chainId": 1,
                "blockNumber": 12000000 # Optional
              },
              {
                "chainId": 10
              }
            ]
          deploy-command: "make deploy"
          buildbear-api-key: "${{ secrets.BUILDBEAR_TOKEN }}"

A few things to notice about this portion of the workflow:

  • At the time of writing, v1.0.0 is the current version of the action, please check the BB CI Action GitHub repo for the latest version.
  • network is a list that can take multiple chain objects and their specified IDs, as well as an optional blockNumber.
  • For the deploy-command you can use either a script or a Foundry command directly.