Skip to content

Commit 2e9c7b3

Browse files
committed
feat: add pre-commit hook to auto generated addresses.json for new deployments
1 parent 9895e71 commit 2e9c7b3

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"verify:arbitrum": "hardhat --network arbitrum etherscan-verify",
1717
"gen:addresses": "ts-node ./script/genAddressesJson.ts"
1818
},
19+
"husky": {
20+
"hooks": {
21+
"pre-commit": "./script/preCommitGenAddresses.sh"
22+
}
23+
},
1924
"devDependencies": {
2025
"@ethersproject/units": "^5.7.0",
2126
"@nomicfoundation/hardhat-foundry": "^1.0.0",
@@ -34,7 +39,7 @@
3439
"hardhat-deploy": "^0.11.22",
3540
"hardhat-deploy-ethers": "0.3.0-beta.13",
3641
"hardhat-tracer": "^1.0.0-alpha.6",
37-
"husky": "^8.0.0",
42+
"husky": "^8.0.3",
3843
"prettier": "^2.4.1",
3944
"prettier-plugin-solidity": "^1.0.0-beta.18",
4045
"ts-node": "^10.8.0",

script/preCommitGenAddresses.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
# Check if any files in 'deployments' folder are staged for commit
4+
if git diff --cached --name-only | grep -q 'deployments/'
5+
then
6+
echo "Changes detected in 'deployments' folder. Running 'yarn gen:addresses'..."
7+
yarn gen:addresses
8+
9+
# Check if the script was successful
10+
if [ $? -ne 0 ]; then
11+
echo "Script failed. Aborting commit."
12+
exit 1
13+
fi
14+
15+
echo "Adding updated address.json to the commit..."
16+
git add addresses.json
17+
18+
echo "Continuing with commit..."
19+
fi

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4639,7 +4639,7 @@ https-proxy-agent@^5.0.0:
46394639
agent-base "6"
46404640
debug "4"
46414641

4642-
husky@^8.0.0:
4642+
husky@^8.0.3:
46434643
version "8.0.3"
46444644
resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.3.tgz#4936d7212e46d1dea28fef29bb3a108872cd9184"
46454645
integrity sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==

0 commit comments

Comments
 (0)