-
Notifications
You must be signed in to change notification settings - Fork 50
82 lines (65 loc) · 2.34 KB
/
benchmark.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
# This workflow benchmark the gas usage of Universal Profile for common interactions
# It compare the gas cost of the changes made between:
# - a feature branch (where a PR is opened)
# - a target branch (where the PR will be merged)
name: 🆙 📊 Universal Profile Benchmark
on:
# enable to run workflow manually
workflow_dispatch:
pull_request:
types: [opened]
# compare gas diff only when editing Solidity smart contract code
paths:
- "contracts/**/*.sol"
# do not run on releases (merging to main)
branches-ignore:
- "main"
jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- name: Checkout base branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.sha }}
fetch-depth: 0
- name: Use Node.js '16.15.0'
uses: actions/setup-node@v2
with:
node-version: "16.15.0"
cache: "npm"
- name: 📦 Install dependencies
run: npm ci
- name: 🏗️ Build contract artifacts
run: npx hardhat compile
- name: 🧪 Run Benchmark tests
# Rename the file to be able to generate benchmark JSON report
run: |
npm run test:benchmark
mv gas_benchmark_result.json gas_benchmark_before.json
- name: Checkout current branch
uses: actions/checkout@v3
# Do not run `git clean -ffdx && git reset --hard HEAD` to prevent removing `gas_benchmark_before.json`
with:
clean: false
- name: Use Node.js '16.15.0'
uses: actions/setup-node@v2
with:
node-version: "16.15.0"
cache: "npm"
- name: 📦 Install dependencies
run: npm ci
- name: 🏗️ Build contract artifacts
run: npx hardhat compile
- name: 🧪 Run Benchmark tests
run: |
npm run test:benchmark
mv gas_benchmark_result.json gas_benchmark_after.json
- name: 📊 Generate Benchmark Report
run: npx hardhat gas-benchmark --compare gas_benchmark_after.json --against gas_benchmark_before.json
- name: 💬 Add Gas Report as comment in PR
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body-file: "./gas_benchmark.md"