-
Notifications
You must be signed in to change notification settings - Fork 30
101 lines (91 loc) · 3.15 KB
/
contract_diff.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
name: contract_diff
on:
workflow_dispatch:
inputs:
ref:
description: 'Branch, tag or commit SHA1 to fetch contract from'
type: string
default: master
chain:
description: 'Chain name, where contracts are located'
type: choice
options:
- mainnet
- polygon
- optimism
- bsc
- arbitrum
- gnosis-chain
default: polygon
target_contract_address:
description: 'Target contract address'
type: string
required: true
source:
description: 'Type of source contract'
type: choice
options:
- deployed_contract
- source_code
default: deployed_contract
source_contract_address:
description: 'Source contract address'
type: string
required: false
etherscan_api_key:
description: 'Etherscan API key'
type: string
required: false
env:
FOUNDRY_PROFILE: ci
jobs:
diff:
name: Contract Diff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
if: inputs.source == 'source_code'
with:
submodules: recursive
ref: ${{ inputs.ref }}
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
id: init
- name: Fetch target contract source code from Etherscan
run: |
mkdir -p tmp/
cast etherscan-source -c ${{ inputs.chain }} ${{ inputs.target_contract_address }} --etherscan-api-key ${{ inputs.etherscan_api_key }} -d tmp/target
- name: Fetch source contract from local sources
if: inputs.source == 'source_code'
run: |
mkdir -p tmp/source/Local
find . -path "./tmp" -prune -o -name "*.sol" -type f -exec cp --parents {} tmp/source/Local \;
- name: Fetch source contract source code from Etherscan
if: inputs.source == 'deployed_contract'
run: |
mkdir -p tmp/
cast etherscan-source -c ${{ inputs.chain }} ${{ inputs.source_contract_address }} --etherscan-api-key ${{ inputs.etherscan_api_key }} -d tmp/source
- name: Eval diff between two deployed verified contracts
if: inputs.source == 'deployed_contract'
run: |
tree ./tmp
git diff --no-index -- tmp/source/* tmp/target/* > diff.txt || true
cat diff.txt
- name: Eval diff between local source code and deployed verified contract
if: inputs.source == 'source_code'
run: |
tree ./tmp
git diff --no-index --diff-filter=ACM -- tmp/source/* tmp/target/* > diff.txt || true
cat diff.txt
- uses: actions/upload-artifact@v3
with:
name: contract.diff
path: diff.txt
- name: Publish diff
run: |
DIFF=$(jq --null-input --arg diff "$(cat diff.txt)" '{"diff": $diff}')
RESPONSE=$(curl -X PUT https://diffy.org/api/diff/ -H "content-type: application/json" -d "$DIFF")
ID=$(echo $RESPONSE | grep -o '"id":"[^,}]*"' | sed 's/.*://' | sed 's/"//g')
echo "https://diffy.org/diff/$ID"