Skip to content

Commit

Permalink
Add CI step to install foundry
Browse files Browse the repository at this point in the history
  • Loading branch information
r0qs committed Jan 23, 2023
1 parent f862526 commit eda4a30
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
48 changes: 39 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ defaults:
sudo apt install python3-pip --assume-yes --no-install-recommends
python3 -m pip install requests --user
- steps_install_foundry: &steps_install_foundry
steps:
- run:
name: Install foundry
command: |
# Note: Currently Foundry only has nightly builds and there is no release checksum
wget https://github.com/foundry-rs/foundry/releases/download/nightly/foundry_nightly_linux_amd64.tar.gz --output-document /tmp/foundry.tar.gz
sudo tar --extract --gzip --file /tmp/foundry.tar.gz --directory /usr/local/bin
# --------------------------------------------------------------------------
# Base Image Templates

Expand Down Expand Up @@ -1215,15 +1224,14 @@ jobs:
type: boolean
default: false
docker:
- image: <<parameters.image>>
resource_class: <<parameters.resource_class>>
- image: << parameters.image >>
resource_class: << parameters.resource_class >>
# NOTE: Each external test runs up to 6 independent settings presets. If parallelism is higher than
# actual preset count, some runs will exit immediately. If it's lower, some runs will get more than one preset.
parallelism: 6
environment:
TERM: xterm
COMPILE_ONLY: <<parameters.compile_only>>
<<: *steps_install_python_dependencies
COMPILE_ONLY: << parameters.compile_only >>
steps:
- checkout
- attach_workspace:
Expand All @@ -1234,6 +1242,15 @@ jobs:
# lsof is used by Colony in its stop-blockchain-client.sh script
sudo apt update
sudo apt-get --quiet --assume-yes --no-install-recommends install lsof
- when:
condition: true
<<: *steps_install_python_dependencies
- when:
condition:
matches:
pattern: /^.+rust.+$/
value: << parameters.image >>
<<: *steps_install_foundry
- when:
condition: << parameters.python2 >>
steps:
Expand All @@ -1249,17 +1266,30 @@ jobs:
equal: [<< parameters.binary_type >>, "solcjs"]
steps:
- run:
name: External <<parameters.project>> tests (solcjs)
name: External << parameters.project >> tests (solcjs)
command: |
test/externalTests/<< parameters.project >>.sh solcjs /tmp/workspace/soljson.js
- when:
condition:
and:
- equal: [<< parameters.binary_type >>, "native"]
- equal: [<< parameters.project >>, "prb-math"]
steps:
- run:
name: External << parameters.project >> tests (native)
command: |
test/externalTests/<<parameters.project>>.py solcjs /tmp/workspace/soljson.js
test/externalTests/<< parameters.project >>.py --solc-binary-type native --solc-binary-path /tmp/workspace/solc/solc
# TODO: remove after address comment: https://github.com/ethereum/solidity/pull/13873#discussion_r1081687334
- when:
condition:
equal: [<< parameters.binary_type >>, "native"]
and:
- equal: [<< parameters.binary_type >>, "native"]
- not equal: [<< parameters.project >>, "prb-math"]
steps:
- run:
name: External <<parameters.project>> tests (native)
name: External << parameters.project >> tests (native)
command: |
test/externalTests/<<parameters.project>>.py --solc-binary-type native --solc-binary-path /tmp/workspace/solc/solc
test/externalTests/<< parameters.project >>.sh native /tmp/workspace/solc/solc
- store_artifacts:
path: reports/externalTests/
# persist_to_workspace fails if the directory does not exist and the test script will create
Expand Down
26 changes: 2 additions & 24 deletions test/externalTests/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,15 @@ def __init__(self, config: TestConfig, setup_fn=None, compile_fn=None, test_fn=N
# Note: the test_dir will be set on setup_environment
self.test_dir: Path = None

def setup_environment(self, test_dir: Path, from_src: bool = False):
def setup_environment(self, test_dir: Path):
"""Configure the project build environment"""

self.test_dir = test_dir
os.chdir(test_dir)

print("Configuring Foundry building environment...")
if which("forge") is None:
if not which("cargo"):
raise RuntimeError("Cargo not found.")
foundry_dir = test_dir / "foundry"
foundry_bin_dir = foundry_dir / "bin"
foundry_bin_dir.mkdir(parents=True, exist_ok=True)
self.env.update({"FOUNDRY_DIR": foundry_dir.resolve()})
if from_src:
ExternalTest.download_project(foundry_dir, self.foundry_repo, "branch", "master")
os.chdir(foundry_dir)
run_cmd(f"cargo install --path {foundry_dir.resolve()}/cli --profile local --bins --locked --force")
else :
# Create the man directory required for the foundryup script
foundry_man_dir = foundry_dir / "share/man/man1"
foundry_man_dir.mkdir(parents=True, exist_ok=True)
req = requests.get(self.foundryup_url, stream=True, verify=True, timeout=10)
foundryup_bin = test_dir / "foundryup"
with open(foundryup_bin, 'wb') as f:
for chunk in req.iter_content(chunk_size=512):
f.write(chunk)
run_cmd(f"chmod +x {foundryup_bin.resolve()}")
run_cmd(f"{foundryup_bin.resolve()}", self.env)
if not any(path == foundry_bin_dir for path in self.env["PATH"].split(os.pathsep)):
self.env["PATH"] += os.pathsep + str(foundry_bin_dir.resolve())
raise RuntimeError("Forge not found.")
if self.setup_fn:
self.setup_fn(self.test_dir, self.env)

Expand Down

0 comments on commit eda4a30

Please sign in to comment.