Skip to content

Commit

Permalink
Fixes to capabilities and contracts merges [CCIP-2946] (#14266)
Browse files Browse the repository at this point in the history
Fix merge issues
  • Loading branch information
asoliman92 authored Aug 28, 2024
1 parent 68d13b7 commit c323e0d
Show file tree
Hide file tree
Showing 65 changed files with 2,900 additions and 7,316 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-plums-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

#updated move latest capabilities code from ccip repo to chainlink repo [CCIP-2946]
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,5 @@ override*.toml
.venv/

ocr_soak_report.csv

vendor/*
5 changes: 5 additions & 0 deletions contracts/.changeset/quick-olives-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/contracts': minor
---

#updated move latest ccip contracts code from ccip repo to chainlink repo [CCIP-2946]
37 changes: 37 additions & 0 deletions contracts/.husky/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Husky git hooks
The folder contains [husky](https://github.com/typicode/husky) git hooks that automate pre-commit and pre-push commands.

## Setup

Create an `.env` file in this folder to enable hooks:

```sh
# Can be left blank to compile everything
FOUNDRY_PROFILE=ccip
HUSKY_ENABLE_PUSH_HOOKS=true
HUSKY_ENABLE_COMMIT_HOOKS=true
UPSTREAM_BRANCH=origin/ccip-develop
```

```sh
# Automatically ran after pnpm install
pnpm prepare
```

### Script procedure

The setup is done via the `prepare.sh` script, which installs husky and enables the hooks.

The prepare step is skipped if we are in CI. This is checked via the `CI=true` flag, which is always set to true on GitHub actions.

## Hooks & Scripts

### Pre-commit
Runs [lint-staged](https://github.com/lint-staged/lint-staged), which automatically detects `.sol` file changes and applies `forge fmt` only on the changed files.

Configured in `package.json` in the `lint-staged` field.

### Pre-push
Runs forge build, test, solhint and optionally suggests to generate snapshots and wrappers.

Due to a [git workflow limitation](https://stackoverflow.com/questions/21334493/git-commit-in-pre-push-hook), generating wrappers & snapshots requires resubmitting the push (via `--no-verify` or by skiping the snapshot / wrappers).
14 changes: 14 additions & 0 deletions contracts/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e

source contracts/.husky/.env

# Only run hook on enabled
if ! [[ $HUSKY_ENABLE_COMMIT_HOOKS == "true" && -n $UPSTREAM_BRANCH ]]; then
exit 0
fi

cd contracts

# Run lint steps
pnpm lint-staged -v
47 changes: 47 additions & 0 deletions contracts/.husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -e

source contracts/.husky/.env

# Only run hook on enabled
if ! [[ $HUSKY_ENABLE_PUSH_HOOKS == "true" && -n $UPSTREAM_BRANCH ]]; then
exit 0
fi

# Skip on no changes
current_branch=$(git branch --show-current)
changes_root=$(git diff --name-only $UPSTREAM_BRANCH...$current_branch -- "contracts/")

if ! [[ -n $changes_root ]]; then
echo "Pre-push hook for contracts skipped - no changes detected"
exit 0
fi

cd contracts

FOUNDRY_PROFILE=$FOUNDRY_PROFILE forge build
FOUNDRY_PROFILE=$FOUNDRY_PROFILE forge test
pnpm solhint

# Skip interactive commands if interactive mode (/dev/tty) is unavailable
# https://stackoverflow.com/a/69088164
if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then
read -n1 -p "Re-generate snapshots & wrappers? (Y/n)" snapshot_answer < /dev/tty
echo $snapshot_answer

if [ "$snapshot_answer" != "${snapshot_answer#[Yy]}" ] ;then
# Create gas snapshot & commit gas snapshot
make snapshot
make wrappers

git add ./gas-snapshots
git add ../core/gethwrappers

# Check if commit is successful (non-empty)
if git commit -m "chore: update gas snapshots and wrappers"; then
# The commit is not included - need to push again (https://stackoverflow.com/questions/21334493/git-commit-in-pre-push-hook)
printf "\033[0;31m Snapshot commit created - run git push again \033[1;33m(skip snapshot, or use the --no-verify push option)\n"
exit 1
fi
fi
fi
19 changes: 19 additions & 0 deletions contracts/.husky/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -e

# Detect if in CI to skip hooks
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
if [[ $CI == "true" ]]; then
exit 0
fi

# Skip hooks creation if unconfigured
if ! [ -f .husky/.env ]; then
printf "\033[1;33mNo .env file found in contracts/.husky, skipping hooks setup.\e[0m\n"
exit 0
fi

cd ../
chmod +x ./contracts/.husky/*.sh
pnpm husky ./contracts/.husky
echo "Husky hooks prepared."
20 changes: 20 additions & 0 deletions contracts/.husky/verify-changeset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -e

# Determine the current branch
current_branch=$(git branch --show-current)
upstream_branch="origin/ccip-develop"

# Compare the directory against the upstream branch
changes_root=$(git diff --name-only $upstream_branch...$current_branch -- ".changeset")

if ! [ -n "$changes_root" ]; then
printf "\033[1;33mRoot changeset changes not found, Consider running pnpm changeset in the root directory if there is significant off-chain impact.\e[0m\n"
fi

changes_contracts=$(git diff --name-only $upstream_branch...$current_branch -- "contracts/.changeset")

if ! [ -n "$changes_contracts" ]; then
printf "\033[0;31mContracts changeset changes not found, Make sure to run & commit \033[1;33mpnpm changeset\033[0;31m in the contracts directory.\n"
exit 1
fi
10 changes: 10 additions & 0 deletions contracts/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ wrappers-all: pnpmdep mockery abigen ## Recompiles solidity contracts and their
# go_generate contains a call to compile all contracts before generating wrappers
go generate ../core/gethwrappers/go_generate.go

# Use this to generate compiled JSON artifacts for gauntlet-plus-plus.
# This is currently only used for CCIP.
# example: make artifact-generate contract=LockReleaseTokenPoolAndProxy solcversion=0.8.24 artifactpath=../../gauntlet-plus-plus/packages-ethereum/operations-ccip/src/artifacts/1.5.0/lock-release-token-pool-and-proxy.json
artifact-generate: export FOUNDRY_PROFILE=ccip
.PHONY: artifact-generate
artifact-generate:
chmod +x ./scripts/generate_compiled_json_ccip.sh
./scripts/generate_compiled_json_ccip.sh $(contract) $(solcversion) $(artifactpath)


help:
@echo ""
@echo " .__ .__ .__ .__ __"
Expand Down
Loading

0 comments on commit c323e0d

Please sign in to comment.