-
Notifications
You must be signed in to change notification settings - Fork 123
107 lines (85 loc) · 3.02 KB
/
Copy pathgas-report.yml
File metadata and controls
107 lines (85 loc) · 3.02 KB
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
name: Gas Optimization Report
on:
pull_request:
branches: [main]
jobs:
gas-report:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build contracts
run: |
cd stellar-lend
./scripts/build.sh
- name: Get base branch baseline
run: |
git fetch origin main:main
npm run gas:baseline main > /tmp/baseline.json || echo '{}' > /tmp/baseline.json
- name: Generate current gas report
run: npm run gas:report > /tmp/current.json
- name: Compare gas costs
run: npm run gas:compare /tmp/baseline.json /tmp/current.json > /tmp/comparison.md
- name: Check for regressions
id: check-regression
run: |
npm run gas:check /tmp/comparison.json > /tmp/check_result.json
FAILED=$(jq '.regressions > 0' /tmp/check_result.json)
echo "FAILED=$FAILED" >> $GITHUB_OUTPUT
- name: Post report to PR
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const comparison = fs.readFileSync('/tmp/comparison.md', 'utf8');
const checkResult = JSON.parse(fs.readFileSync('/tmp/check_result.json', 'utf8'));
let status = '✅ No gas regressions detected';
if (checkResult.regressions > 0) {
status = `⚠️ ${checkResult.regressions} gas regression(s) detected`;
}
const body = `## Gas Optimization Report
${status}
${comparison}
### Summary
- **Functions analyzed**: ${checkResult.total}
- **Improvements**: ${checkResult.improvements}
- **Regressions**: ${checkResult.regressions}
- **Average change**: ${checkResult.average_change > 0 ? '+' : ''}${checkResult.average_change.toFixed(2)}%
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
- name: Fail if regressions exceed threshold
if: steps.check-regression.outputs.FAILED == 'true'
run: exit 1