-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
111 lines (108 loc) · 4.41 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: "Deploy EVM smart contract"
description: "Deploy and verify a smart contract on any EVM chain"
author: "Yacine Badiss"
branding:
icon: arrow-up-circle
color: blue
inputs:
contract-name:
description: "Name of the contract to deploy. Must be the name of the main sol file."
required: true
parent-dir:
description: "Parent directory of `src` and `out`."
required: true
default: "."
chain-id:
description: "ID of the chain to deploy to. If in doubt see https://chainlist.org/."
required: true
rpc-url:
description: "URL of the RPC to use to deploy the contract."
required: true
deployer-pk:
description: "Private key to use for deployment."
required: true
constructor-args:
description: "Arguments to pass to the contract's constructor."
required: false
default: ""
verify:
description: "Whether we must verify the contract or not on etherscan. If set to `true`, `etherscan-url` and `etherscan-api-key` are required."
required: false
default: "false"
etherscan-url:
description: "URL of the etherscan endpoint to use for verification and reporting."
required: false
default: ""
etherscan-api-key:
description: "API key used for verification."
required: false
default: ""
outputs:
contract-address:
description: "Address the contract was deployed to"
value: ${{ steps.summary.outputs.deployedTo }}
transaction-hash:
description: "Hash of the deployment transaction"
value: ${{ steps.summary.outputs.transactionHash }}
runs:
using: "composite"
steps:
- name: Check values
run: |
if [[ "${{ inputs.verify }}" == "true" ]]; then
if [[ "${{ inputs.etherscan-url }}" == "" || "${{ inputs.etherscan-api-key }}" == "" ]]; then
echo "Missing `etherscan-url` and `etherscan-api-key` required for verification."
exit 1
fi
fi
shell: bash
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Build contract
run: |
cd ${{ inputs.parent-dir }}
forge build
shell: bash
- name: Deploy contract
id: deploy
env:
ETHERSCAN_URL: ${{ inputs.etherscan-url }}
ETHERSCAN_API_KEY: ${{ inputs.etherscan-api-key }}
run: |
cd ${{ inputs.parent-dir }}
createArguments="src/${{ inputs.contract-name }}.sol:${{ inputs.contract-name }} --retries 10 --json --rpc-url=${{ inputs.rpc-url }} --private-key=${{ inputs.deployer-pk }}"
if [[ "${{ inputs.verify }}" == "true" ]]; then
createArguments="${createArguments} --verify"
fi
if [[ "${{ inputs.constructor-args }}" != "" ]]; then
createArguments="${createArguments} --constructor-args ${{ inputs.constructor-args }}"
fi
createOutput=$(eval "forge create ${createArguments}")
echo "forge create output:\n\n${createOutput}"
deploymentOutput=`echo "${createOutput}" | head -1`
echo "deploymentOutput=${deploymentOutput}" >> $GITHUB_OUTPUT
shell: bash
- name: Upload ABI artifact
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.contract-name }}.abi.json
path: ${{ inputs.parent-dir }}/out/${{ inputs.contract-name }}.sol/${{ inputs.contract-name }}.json
- name: Log summary of deployment
id: summary
run: |
echo "# Contract ${{ inputs.contract-name }} deployed :rocket:" >> $GITHUB_STEP_SUMMARY
deployer="${{ fromJson(steps.deploy.outputs.deploymentOutput).deployer }}"
echo "deployer=${deployer}" >> $GITHUB_OUTPUT
deployedTo="${{ fromJson(steps.deploy.outputs.deploymentOutput).deployedTo }}"
echo "deployedTo=${deployedTo}" >> $GITHUB_OUTPUT
transactionHash="${{ fromJson(steps.deploy.outputs.deploymentOutput).transactionHash }}"
echo "transactionHash=${transactionHash}" >> $GITHUB_OUTPUT
if [[ "${{ inputs.etherscan-url }}" != "" ]]; then
deployer="[${deployer}](${{ inputs.etherscan-url }}/address/${deployer})"
deployedTo="[${deployedTo}](${{ inputs.etherscan-url }}/address/${deployedTo})"
transactionHash="[${transactionHash}](${{ inputs.etherscan-url }}/tx/${transactionHash})"
fi
echo "- Deployer: ${deployer}" >> $GITHUB_STEP_SUMMARY
echo "- Deployed to: ${deployedTo}" >> $GITHUB_STEP_SUMMARY
echo "- Transaction hash: ${transactionHash}" >> $GITHUB_STEP_SUMMARY
shell: bash