Skip to content

Commit

Permalink
Cache foundry build for contracts (#338)
Browse files Browse the repository at this point in the history
Significantly speeds up builds by:
* for each contracts package, caches its build based on the files and foundry config

For better visibility, breaks out each contracts package into its own CI task

For protocol-deployments, fork-tests have just become the standard tests

We can see the speed up in-upstream prs:

https://github.com/ourzora/zora-protocol/actions/runs/6817103631?pr=262

<img width="700" alt="Screenshot 2023-11-09 at 12 36 14 PM" src="https://github.com/ourzora/zora-protocol/assets/891755/18f8e2eb-604f-40d8-937c-73964c5ec5a1">
  • Loading branch information
oveddan authored Nov 9, 2023
1 parent 3d2d1ae commit 64930db
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 153 deletions.
29 changes: 29 additions & 0 deletions .github/actions/cache_foundry_build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Cache foundry build'
description: 'Caches foundry build by path'

inputs:
package_folder: # id of input
description: 'contracts package folder'
required: true
foundry_profile:
description: 'foundry profile for caching'

runs:
using: "composite"

steps:
- name: Cache contracts build
uses: actions/cache@v3
with:
# npm cache files are stored in out and cache
path: |
${{ inputs.package_folder }}/cache
${{ inputs.package_folder }}/out
# cache key is based on foundry config, contracts source tests, and scripts
key: ${{ inputs.package_folder }}${{ inputs.foundry_profile}}-${{ hashFiles(format('{0}/foundry.toml', inputs.package_folder)) }}-${{ hashFiles(format('{0}/src/**/*.sol', inputs.package_folder)) }}-${{ hashFiles(format('{0}/test/**/*.sol', inputs.package_folder)) }}-${{ hashFiles(format('{0}/script/**/*.sol', inputs.package_folder)) }}
# the following backups cache keys are searched, in case an exact match is not found
# see https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key
restore-keys: |
${{ inputs.package_folder }}${{ inputs.foundry_profile}}-${{ hashFiles(format('{0}/foundry.toml', inputs.package_folder)) }}-${{ hashFiles(format('{0}/src/**/*.sol', inputs.package_folder)) }}-${{ hashFiles(format('{0}/test/**/*.sol', inputs.package_folder)) }}-
${{ inputs.package_folder }}${{ inputs.foundry_profile}}-${{ hashFiles(format('{0}/foundry.toml', inputs.package_folder)) }}-${{ hashFiles(format('{0}/src/**/*.sol', inputs.package_folder)) }}-
${{ inputs.package_folder }}${{ inputs.foundry_profile}}-${{ hashFiles(format('{0}/foundry.toml', inputs.package_folder)) }}-
21 changes: 21 additions & 0 deletions .github/workflows/1155.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "1155"
on:
workflow_call:

jobs:
build:
uses: ./.github/workflows/build.yml
with:
package_folder: packages/1155-contracts

test:
needs: build
uses: ./.github/workflows/test.yml
with:
package_folder: packages/1155-contracts

coverage:
uses: ./.github/workflows/coverage.yml
with:
package: "1155-contracts"
files_to_ignore: '"*DeploymentConfig*" "*Redeem*" "*deployment*" "*packages*"'
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
workflow_call:
inputs:
package_folder:
required: true
type: string

jobs:
check:
strategy:
fail-fast: true

name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install node deps and founry
uses: ./.github/actions/setup_deps

- name: Cache build
uses: ./.github/actions/cache_foundry_build
with:
package_folder: ${{ inputs.package_folder }}

- name: Build contracts
run: |
cd ${{ inputs.package_folder}} && forge build
17 changes: 17 additions & 0 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "Contracts"

on: "push"

jobs:
contracts-1155:
name: 1155
uses: ./.github/workflows/1155.yml

contracts-protocol-rewards:
name: Protocol Rewards
uses: ./.github/workflows/protocol-rewards.yml

contracts-protocol-deployments:
name: Protocol Deployments
uses: ./.github/workflows/protocol-deployments.yml
secrets: inherit
8 changes: 7 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: true

name: Check solidity test coverage
name: Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -29,6 +29,12 @@ jobs:
- name: Install node deps and founry
uses: ./.github/actions/setup_deps

- name: Cache build
uses: ./.github/actions/cache_foundry_build
with:
package_folder: packages/${{ inputs.package }}
foundry_profile: coverage

- name: Run Forge coverage
run: cd $package_folder && forge coverage --report lcov

Expand Down
150 changes: 0 additions & 150 deletions .github/workflows/foundry.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/protocol-deployments.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "1155"
on:
workflow_call:

jobs:
build:
uses: ./.github/workflows/build.yml
with:
package_folder: packages/protocol-deployments

test:
needs: build
uses: ./.github/workflows/test.yml
with:
package_folder: packages/protocol-deployments
secrets: inherit
21 changes: 21 additions & 0 deletions .github/workflows/protocol-rewards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Protocol Rewards"
on:
workflow_call:

jobs:
build:
uses: ./.github/workflows/build.yml
with:
package_folder: packages/protocol-rewards

test:
needs: build
uses: ./.github/workflows/test.yml
with:
package_folder: packages/protocol-rewards

coverage:
uses: ./.github/workflows/coverage.yml
with:
package: "protocol-rewards"
files_to_ignore: '"*lib*"'
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
workflow_call:
inputs:
package_folder:
required: true
type: string

jobs:
check:
strategy:
fail-fast: true

name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install node deps and founry
uses: ./.github/actions/setup_deps

- name: Load foundry cache
uses: ./.github/actions/cache_foundry_build
with:
package_folder: ${{ inputs.package_folder }}

- name: Test
run: |
cd ${{ inputs.package_folder}} && yarn test
env:
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}
3 changes: 1 addition & 2 deletions packages/protocol-deployments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"type": "module",
"scripts": {
"dev": "FOUNDRY_PROFILE=dev forge test --watch -vvv",
"test:fork": "FORK_TEST_CHAINS=mainnet,goerli,optimism,optimism_goerli,zora,zora_goerli,base_goerli,base,zora_sepolia forge test -vvv",
"test": "forge test -vvv",
"test": "FORK_TEST_CHAINS=mainnet,goerli,optimism,optimism_goerli,zora,zora_goerli,base_goerli,base,zora_sepolia forge test -vvv",
"build": "yarn wagmi && yarn bundle-configs && tsup",
"bundle-configs": "node script/bundle-chainConfigs.mjs && yarn prettier",
"prettier": "prettier --write 'package/**/*.ts' 'script/**/*.ts' 'wagmi.config.ts'",
Expand Down

0 comments on commit 64930db

Please sign in to comment.