Skip to content

Commit

Permalink
Fix deployment script in GitHub Action
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed Oct 26, 2022
1 parent 2f9485c commit 9ff9c27
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ jobs:
forge test -vvv --gas-report
id: test

- name: Deploy Görli Testnet
- name: Deploy Constant Library
run: |
forge create --contracts contracts/VoterClassFactory.sol --rpc-url ${DEVNET_RPC_URL} --private-key ${ETH_DEV_PRIVATE} --etherscan-api-key ${ETHERSCAN_API_KEY} --verify VoterClassFactory
forge create --contracts contracts/GovernanceBuilder.sol --rpc-url ${DEVNET_RPC_URL} --private-key ${ETH_DEV_PRIVATE} --etherscan-api-key ${ETHERSCAN_API_KEY} --verify GovernanceBuilder
forge create --json --contracts contracts/Constant.sol --rpc-url ${DEVNET_RPC_URL} --private-key ${ETH_DEV_PRIVATE} Constant | tee Constant.sol.json
if: ${{ github.event_name == 'release' && github.event.action == 'created' }}

- name: Deploy to Görli Testnet
run: |
export DEPLOYED_LIBRARY=$(bin/library.py Constant.sol.json)
echo "Using library ${DEPLOYED_LIBRARY}"
forge create --libraries ${DEPLOYED_LIBRARY} --contracts contracts/VoterClassFactory.sol --rpc-url ${DEVNET_RPC_URL} --private-key ${ETH_DEV_PRIVATE} --etherscan-api-key ${ETHERSCAN_API_KEY} --verify VoterClassFactory
forge create --libraries ${DEPLOYED_LIBRARY} --contracts contracts/GovernanceBuilder.sol --rpc-url ${DEVNET_RPC_URL} --private-key ${ETH_DEV_PRIVATE} --etherscan-api-key ${ETHERSCAN_API_KEY} --verify GovernanceBuilder
if: ${{ github.event_name == 'release' && github.event.action == 'created' }}
39 changes: 39 additions & 0 deletions bin/library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
""" parse foundry deployment into library path statement """
import sys
import json
import os

def usage(name: str):
""" print the usage """
print('%s deployment.json ...' % name)

def parse_deployment(path: str, file: str) -> str:
""" parse a deployment file into a library path """
basename = os.path.basename(file)
(basefile, _) = os.path.splitext(basename)
(basecontract, _) = os.path.splitext(basefile)
with open(file, 'r') as json_stream:
jsondata = json_stream.read().rstrip().lstrip()
js = json.loads(jsondata)
if 'deployedTo' in js:
deployed_to = js['deployedTo']
return path + basefile + ':' + basecontract + ':' + deployed_to
else:
raise Exception('Invalid deployment json');

if __name__ == '__main__':
if len(sys.argv) > 1:
library_path = []
contract_path = 'contracts/'
parse_contract_path = False
for file in sys.argv[1:]:
if file == '-c':
parse_contract_path = True
elif parse_contract_path:
contract_path = file
else:
library_path.append(parse_deployment(contract_path, file))
print(','.join(library_path))
else:
usage(sys.argv[0])

0 comments on commit 9ff9c27

Please sign in to comment.