Skip to content

Commit

Permalink
feat: add foundry check reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbaliasnikov committed Jan 13, 2025
1 parent 66254f8 commit 1be4957
Show file tree
Hide file tree
Showing 2 changed files with 220 additions and 0 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/check-foundry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Foundry

on:
workflow_call:
inputs:
# Dependency versions
zksync-era-version:
type: string
description: 'Zksync era version'
required: false
era-test-node-version:
type: string
description: 'Era test node version'
required: false
# Solidity compiler parameters
zksolc-version:
type: string
description: 'Zksolc version'
required: false
default: "1.5.7"
solidity-version:
type: string
description: 'Solidity version'
required: false
default: "0.8.28"

jobs:

foundry:
runs-on: matterlabs-ci-runner-high-performance
container:
image: ghcr.io/matter-labs/zksync-llvm-runner:latest
defaults:
run:
shell: bash -ex {0}
steps:

- name: Checkout
uses: actions/checkout@v4
with:
repository: matter-labs/foundry-zksync

- uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Patch dependencies
env:
CARGO_TOML: Cargo.toml
GH_ML_URL: https://github.com
# `www.github.com` is a workaround for Cargo issue with `patch` section from `git` source
# https://github.com/rust-lang/cargo/issues/5478
GH_ML_PATCHED_URL: https://www.github.com
DEPENDENCIES_LIST: "zksync_dal zksync_basic_types zksync_types zksync_state zksync_multivm zksync_web3_decl zksync_utils zksync_contracts"
run: |
if [ ! -z ${{ inputs.zksync-era-version }} ]; then
echo "[patch.\"${GH_ML_URL}/matter-labs/zksync-era.git\"]" >> "${CARGO_TOML}"
for DEP in ${{ env.DEPENDENCIES_LIST }}; do
echo "${DEP} = { git = '${GH_ML_PATCHED_URL}/matter-labs/zksync-era', rev = '${{ inputs.zksync-era-version }}' }" >> "${CARGO_TOML}"
done
fi
if [ ! -z ${{ inputs.era-test-node-version }} ]; then
echo "[patch.\"${GH_ML_URL}/matter-labs/era-test-node.git\"]" >> "${CARGO_TOML}"
echo "era_test_node = { git = '${GH_ML_PATCHED_URL}/matter-labs/era-test-node', rev = '${{ inputs.era-test-node-version }}' }" >> "${CARGO_TOML}"
fi
cat "${CARGO_TOML}"
- name: Build foundry
run: |
export CC=$(which clang)
cargo build --release
${PWD}/target/release/forge --version
echo "${PWD}/target/release" >> "${GITHUB_PATH}"
- name: Create test foundry project
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
forge init --no-git --no-commit foundry-test-project
- name: Patch compilers
working-directory: foundry-test-project
run: |
if [ ! -z ${{ inputs.solidity-version || '0.8.28' }} ]; then
echo "solc_version = \"${{ inputs.solidity-version || '0.8.28' }}\"" >> foundry.toml
fi
if [ ! -z ${{ inputs.zksolc-version || '1.5.9' }} ]; then
echo "[profile.default.zksync]" >> foundry.toml
echo "zksolc = \"${{ inputs.zksolc-version || '1.5.9' }}\"" >> foundry.toml
fi
cat foundry.toml
- name: Run test foundry project
working-directory: foundry-test-project
run: forge test --zksync
127 changes: 127 additions & 0 deletions .github/workflows/check-hardhat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Hardhat

on:
workflow_call:
inputs:
# Custom solidity hardhat parameters
hardhat-zksync-version:
type: string
description: 'Hardhat version'
required: false
zksync-contracts-version:
type: string
description: 'ZKsync contracts version'
required: false
zksync-ethers-version:
type: string
description: 'ZKsync ethers version'
required: false
# Solidity compiler parameters
zksolc-release-suffix:
type: string
description: 'zksolc artifact suffix to test'
required: true
# Custom hardhat vyper parameters
hardhat-zksync-deploy-version:
type: string
description: 'Hardhat zksync deploy version'
required: false
hardhat-zksync-node-version:
type: string
description: 'Hardhat zksync node version'
required: false
hardhat-zksync-vyper-version:
type: string
description: 'Hardhat zksync vyper version'
required: false
# Vyper compiler parameters
zkvyper-version:
type: string
description: 'Zkvyper version'
required: false
default: "latest"

jobs:

# hardhat-solidity and hardhat-vyper jobs are supposed to check hardhat templates
# with the most recent version of Hardhat
# and with the most recent version of compilers

# This should be triggered when any new version of dependency is released
# new compiler is out - trigger it with the new compiler version
# new hardhat plugin version is out - trigger it with the new compiler version
# if CI fails, then the reasons may include:
# 1. new compiler version is not compatible with the code
# 2. new hardhat plugin version is not compatible with the code
# 3. templates and docs must be updated to support new versions of dependencies
hardhat-solidity:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: 'templates/hardhat/solidity'
shell: bash -ex {0}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: matter-labs/zksync-contract-templates

- name: Patch hardhat
run: |
[ ! -z '${{ inputs.hardhat-zksync-version }}' ] && yarn add @matterlabs/hardhat-zksync@${{ inputs.hardhat-zksync-version }} || true
[ ! -z '${{ inputs.zksync-contracts-version }}' ] && yarn add @matterlabs/zksync-contracts@${{ inputs.zksync-contracts-version }} || true
[ ! -z '${{ inputs.zksync-ethers-version }}' ] && yarn add zksync-ethers@${{ inputs.zksync-ethers-version }} || true
- name: Download zksolc compiler
uses: actions/download-artifact@v4
with:
name: release-${{ inputs.zksolc-release-suffix }}
path: templates/hardhat/solidity/zksolc

- name: Update compiler config
run: |
find .
ZKSOLC_PATH=$(readlink -f zksolc)
chmod a+x "${ZKSOLC_PATH}
${ZKSOLC_PATH} --version
sed -i '/zksolc: {/,/settings: {/ { /version:/d }' hardhat.config.ts
sed -i "/settings: {/a\ compilerPath: \"${ZKSOLC_PATH}\"," hardhat.config.ts
cat hardhat.config.ts
- name: Install dependencies
run: yarn install

- name: Run tests
run: yarn test

hardhat-vyper:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: 'templates/hardhat/vyper'
shell: bash -ex {0}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: matter-labs/zksync-contract-templates

- name: Patch hardhat
run: |
[ ! -z '${{ inputs.hardhat-zksync-deploy-version }}' ] && yarn add @matterlabs/hardhat-zksync-deploy@${{ inputs.hardhat-zksync-deploy-version }} || true
[ ! -z '${{ inputs.hardhat-zksync-node-version }}' ] && yarn add @matterlabs/hardhat-zksync-node@${{ inputs.hardhat-zksync-node-version }} || true
[ ! -z '${{ inputs.hardhat-zksync-vyper-version }}' ] && yarn add @matterlabs/hardhat-zksync-vyper@${{ inputs.hardhat-zksync-vyper-version }} || true
# TODO: this step should be removed
# when the process.env.* patch is applied to the templates repo
- name: Update compiler config
run: |
sed -i 's/version: "latest"/version: process.env.ZKVYPER_VERSION || "latest"/' hardhat.config.ts
sed -i 's/version: "0.3.3"/version: process.env.VYPER_VERSION || "0.3.3"/' hardhat.config.ts
cat hardhat.config.ts
- name: Install dependencies
run: yarn install

- name: Run tests
run: yarn test

0 comments on commit 1be4957

Please sign in to comment.