-
Notifications
You must be signed in to change notification settings - Fork 2
138 lines (118 loc) · 4.89 KB
/
solidity-test.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Task - Test Solidity
on:
workflow_call:
push:
paths:
- 'solidity/**'
pull_request:
paths:
- 'solidity/**'
env:
FOUNDRY_PROFILE: ci
jobs:
check:
env:
working-directory: ./solidity
name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Cache gas report
uses: actions/cache@v3
with:
path: ${{ env.working-directory }}/previous_gas_report.txt
key: ${{ runner.os }}-gas-report-${{ github.sha }}
restore-keys: |
${{ runner.os }}-gas-report-
- name: Run Forge build
working-directory: ${{ env.working-directory }}
run: forge build --sizes
- name: Run Forge tests
working-directory: ${{ env.working-directory }}
run: forge test -vvv
- name: Initialize dummy previous gas report if not exists
working-directory: ${{ env.working-directory }}
run: |
if [ ! -f previous_gas_report.txt ]; then
echo "Initializing dummy previous_gas_report.txt with high values"
echo "SpotMedian,100000000000000000" > previous_gas_report.txt
echo "TWAP,100000000000000000" >> previous_gas_report.txt
echo "RealizedVolatility,100000000000000000" >> previous_gas_report.txt
echo "Options,100000000000000000" >> previous_gas_report.txt
echo "Perp,100000000000000000" >> previous_gas_report.txt
fi
- name: Run gas report
working-directory: ${{ env.working-directory }}
run: |
echo "Running Forge test..."
forge test --match-contract PragmaDecoderGasTest -vvv > full_output.txt
echo "Forge test completed. Contents of full_output.txt:"
cat full_output.txt
echo "Extracting gas report..."
grep "Gas used for" full_output.txt | sed -E 's/Gas used for ([A-Za-z]+) update: ([0-9]+)/\1,\2/' > current_gas_report.txt
echo "Extraction completed. Contents of current_gas_report.txt:"
cat current_gas_report.txt
- name: Compare gas results
id: compare-gas
working-directory: ${{ env.working-directory }}
run: |
echo "Starting gas comparison"
gas_summary="## Gas Report Summary\n\n"
if [ -f previous_gas_report.txt ]; then
echo "File exists, can process comparison"
while IFS=',' read -r current_test current_gas; do
previous_gas=$(grep "^$current_test," previous_gas_report.txt | cut -d',' -f2)
echo "Processing test: $current_test with current gas: $current_gas and previous gas: $previous_gas"
gas_summary+="### ${current_test}\n"
gas_summary+="- **Gas used**: ${current_gas}\n"
if [ -n "$previous_gas" ]; then
diff=$((current_gas - previous_gas))
percent=$((diff * 100 / previous_gas))
if [ $diff -gt 0 ]; then
gas_summary+="- **Change**: :red_circle: +${diff} (${percent}% increase)\n"
elif [ $diff -lt 0 ]; then
gas_summary+="- **Change**: :green_circle: ${diff} (${percent}% decrease)\n"
else
gas_summary+="- **Change**: :white_circle: No change\n"
fi
else
gas_summary+="- **Change**: N/A (New test)\n"
fi
gas_summary+="\n"
done < current_gas_report.txt
else
echo "No previous gas report found. This will be the baseline for future comparisons."
while IFS=',' read -r current_test current_gas; do
gas_summary+="### ${current_test}\n"
gas_summary+="- **Gas used**: ${current_gas}\n"
gas_summary+="- **Change**: N/A (First run)\n\n"
done < current_gas_report.txt
fi
echo "gas_summary<<EOF" >> $GITHUB_OUTPUT
echo "$gas_summary" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
cp current_gas_report.txt previous_gas_report.txt
- name: Comment PR
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
SUMMARY: ${{ steps.compare-gas.outputs.gas_summary }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const summary = process.env.SUMMARY.replace(/\\n/g, '\n');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary
})
- name: Upload gas report
uses: actions/upload-artifact@v3
with:
name: gas-report
path: ${{ env.working-directory }}/previous_gas_report.txt