Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Improve deploy.sh #171

Merged
merged 21 commits into from
Mar 16, 2023
Merged
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@ set -e
[[ "$(cast chain --rpc-url="$ETH_RPC_URL")" == "goerli" ]] || { echo "Please set a Goerli ETH_RPC_URL"; exit 1; }
[[ "$ETHERSCAN_API_KEY" ]] || { echo "Please set ETHERSCAN_API_KEY"; exit 1; }

make && \
dapp create DssSpell | \
xargs ./scripts/verify.py DssSpell
SOURCE="src/test/config.sol"
KEY_SPELL="deployed_spell"
KEY_TIMESTAMP="deployed_spell_created"
KEY_BLOCK="deployed_spell_block"

# Colors
YELLOW="\033[0;33m"
PURPLE="\033[0;35m"
NC="\033[0m"

make && spell_address=$(dapp create DssSpell)
olivdb marked this conversation as resolved.
Show resolved Hide resolved

./scripts/verify.py DssSpell "$spell_address"

# edit config.sol to add the deployed spell address
sed -Ei "s/($KEY_SPELL: *address\()(0x[[:xdigit:]]{40}|0x0|0)\)/\1$spell_address)/" "$SOURCE"

# get tx hash from contract address, created using an internal transaction
TXHASH=$(curl "https://api-goerli.etherscan.io/api?module=account&action=txlistinternal&address=$spell_address&startblock=0&endblock=99999999&sort=asc&apikey=$ETHERSCAN_API_KEY" | jq -r ".result[0].hash")

# get deployed contract timestamp and block number info
timestamp=$(cast block "$(cast tx "${TXHASH}"|grep blockNumber|awk '{print $2}')"|grep timestamp|awk '{print $2}')
block=$(cast tx "${TXHASH}"|grep blockNumber|awk '{print $2}')

# edit config.sol to add the deployed spell timestamp and block number
sed -i "s/\($KEY_TIMESTAMP *: *\)[0-9]\+/\1$timestamp/" "$SOURCE"
sed -i "s/\($KEY_BLOCK *: *\)[0-9]\+/\1$block/" "$SOURCE"

echo -e "${YELLOW}Network: $(cast chain)${NC}"
echo -e "${YELLOW}config.sol updated with ${PURPLE}deployed spell:${NC} $spell_address, ${PURPLE}timestamp:${NC} $timestamp and ${PURPLE}block:${NC} $block ${NC}"

make test block="$block" || { echo -e "${PURPLE}Please ensure config.sol was edited correctly${NC}"; exit 1; }

# commit edit change to config.sol
(set -x; git add src/test/config.sol)
(set -x; git commit -m "add deployed spell info")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should auto-commit this. First, I think this approach could be fragile (like one may have other staged changes for addition). Second, there is something that is a bit too sneaky about auto-commits without human review. Minimally, if we wanted to do this, I would say we should let this code run for a while and see if it encounters any failures under normal operation. But honestly, I think we may just want humans to be able to diff to review, add, and commit this manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this pattern is part of the spell crafting/reviewing automation endeavour, inspired by dapp init pattern.
In this specific case though, it could be a bit tricky as there are many moving pieces but one approach could be ensuring the changes have been actually edited in config.sol directly or better, running tests and if they pass commit.

Copy link
Contributor Author

@naszam naszam Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests check at deployed block in 8581a61

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of the auto-commit either. If this is part of an automation workflow, it may be better to have the auto-commit done in an external script that calls deploy.sh imo.

Copy link
Contributor Author

@naszam naszam Mar 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in chat I'm testing some improvements to beef the script up with more checks before committing the changes as make test is a bit fragile an could return a zero status even if tests doesn't pass, but not opposed to handle the commit in an external script, I only think would be best for a CLI tool where the approach is more modular.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if a56a15a and b68131f give more assurance, the extra check was inspired by the dapp upgrade one (see here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussing with @olivdb in chat, I've addressed the request of adding a way to stash and then reload local staging area in 2114dc1 (note that the stash would happen before the script makes edits and then it's reloaded before commiting in case the dev exit the commit edit prompt)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after some testing and further discussions, using trap we ensure we always exit with restoring the staging area.