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 14, 2025
1 parent 66254f8 commit 8a1ea65
Show file tree
Hide file tree
Showing 2 changed files with 299 additions and 0 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/check-foundry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
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-release-suffix:
type: string
description: 'zksolc artifact suffix to test'
required: false
default: ""
zksolc-version:
type: string
description: 'zksolc version to test'
required: false
default: ""
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: Check input parameters
if: ${{ inputs.zksolc-release-suffix != '' && inputs.zksolc-version != '' }}
run: |
echo "Both zksolc-release-suffix and zksolc-version are set. Please, choose only one of them."
exit 1
- 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 solc version
if: inputs.solidity-version != ''
working-directory: foundry-test-project
run: |
echo "solc_version = \"${{ inputs.solidity-version }}\"" >> foundry.toml
cat foundry.toml
- name: Download zksolc compiler
if: inputs.zksolc-release-suffix != ''
uses: actions/download-artifact@v4
with:
name: release-${{ inputs.zksolc-release-suffix }}
path: foundry-test-project/zksolc

- name: Update compiler config
working-directory: foundry-test-project
if: inputs.zksolc-release-suffix != ''
run: |
ZKSOLC_PATH=$(readlink -f ./zksolc/${{ inputs.zksolc-release-suffix }}/zksolc-${{ inputs.zksolc-release-suffix }})
chmod a+x "${ZKSOLC_PATH}"
${ZKSOLC_PATH} --version
echo "[profile.default.zksync]" >> foundry.toml
echo "zksolc = \"${ZKSOLC_PATH}\"" >> foundry.toml
cat foundry.toml
- name: Patch zksolc version
if: inputs.zksolc-version != ''
working-directory: foundry-test-project
run: |
echo "[profile.default.zksync]" >> foundry.toml
echo "zksolc = \"${{ inputs.zksolc-version }}\"" >> foundry.toml
cat foundry.toml
- name: Run test foundry project
working-directory: foundry-test-project
run: forge test --zksync --zk-suppressed-errors assemblycreate
174 changes: 174 additions & 0 deletions .github/workflows/check-hardhat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
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: false
default: ''
zksolc-version:
type: string
description: 'zksolc version to test'
required: false
default: ''
# 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-release-suffix:
type: string
description: 'zkvyper artifact suffix to test'
required: false
default: ''
zkvyper-version:
type: string
description: 'zkvyper version to test'
required: false
default: ''

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: Check input parameters
if: ${{ inputs.zksolc-release-suffix != '' && inputs.zksolc-version != '' }}
run: |
echo "Both zksolc-release-suffix and zksolc-version are set. Please, choose only one of them."
exit 1
- 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
if: inputs.zksolc-release-suffix != ''
uses: actions/download-artifact@v4
with:
name: release-${{ inputs.zksolc-release-suffix }}
path: templates/hardhat/solidity/zksolc

- name: Update compiler path
if: inputs.zksolc-release-suffix != ''
run: |
ZKSOLC_PATH=$(readlink -f ./zksolc/${{ inputs.zksolc-release-suffix }}/zksolc-${{ inputs.zksolc-release-suffix }})
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: Update compiler config
if: inputs.zksolc-version == ''
run: |
sed -i 's/version: "latest"/version: "${{ inputs.zksolc-version }}"/' 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: Check input parameters
if: ${{ inputs.zkvyper-release-suffix != '' && inputs.zkvyper-version != '' }}
run: |
echo "Both zkvyper-release-suffix and zkvyper-version are set. Please, choose only one of them."
exit 1
- 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
- name: Download zkvyper compiler
if: inputs.zkvyper-release-suffix != ''
uses: actions/download-artifact@v4
with:
name: release-${{ inputs.zkvyper-release-suffix }}
path: templates/hardhat/vyper/zkvyper

- name: Update compiler path
if: inputs.zkvyper-release-suffix != ''
run: |
ZKVYPER_PATH=$(readlink -f ./zkvyper/${{ inputs.zkvyper-release-suffix }}/zkvyper-${{ inputs.zkvyper-release-suffix }})
chmod a+x "${ZKVYPER_PATH}"
${ZKVYPER_PATH} --version
sed -i '/zkvyper: {/,/settings: {/ { /version:/d }' hardhat.config.ts
sed -i "/settings: {/a\ compilerPath: \"${ZKVYPER_PATH}\"," hardhat.config.ts
cat hardhat.config.ts
- name: Update compiler config
if: inputs.zkvyper-version != ''
run: |
sed -i 's/version: "latest"/version: "${{ inputs.zkvyper-version }}"/' hardhat.config.ts
cat hardhat.config.ts
- name: Install dependencies
run: yarn install

- name: Run tests
run: yarn test

0 comments on commit 8a1ea65

Please sign in to comment.