-
Notifications
You must be signed in to change notification settings - Fork 230
148 lines (133 loc) · 5.04 KB
/
pr-benchdiff.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
139
140
141
142
143
144
145
146
147
148
name: Benchdiff
on:
issue_comment:
types: [created]
pull_request:
types: [opened]
paths-ignore:
- '**.md'
jobs:
# https://github.community/t/cancelling-rest-of-job-if-condition-is-met/18181
trigger:
name: Pull request comment trigger
outputs:
triggered: ${{ steps.output.outputs.triggered }}
pr_number: ${{ steps.output.outputs.pr_number }}
runs-on: self-hosted
steps:
- name: Check pull request comment
if: ${{ github.event_name == 'issue_comment' }}
uses: khan/pull-request-comment-trigger@master
id: check-comment
with:
trigger: '/benchdiff'
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: Set output
id: output
run: |
echo '::set-output name=triggered::${{ github.event_name == 'pull_request' || steps.check-comment.outputs.triggered }}'
echo '::set-output name=pr_number::${{ github.event.pull_request.number || github.event.issue.number }}'
benchdiff:
name: Performance regression check
needs: [trigger]
if: needs.trigger.outputs.triggered == 'true'
runs-on: self-hosted
timeout-minutes: 30
env:
# In markdown URL syntax
RUNS_URL: '[${{ github.workflow }} #${{ github.run_number }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})'
steps:
- name: Report job start
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: '${{ needs.trigger.outputs.pr_number }}'
body: |
## Benchdiff
Runs: ${{ env.RUNS_URL }}
Job is started.
- name: Checkout
uses: actions/checkout@v2
- name: Checkout pull request HEAD
id: head
run: |
# Fetch github default branch as baseline
git fetch origin ${{ github.event.repository.default_branch }}:BENCHDIFF_BASE
git checkout BENCHDIFF_BASE
echo "::set-output name=base::$(git rev-parse HEAD)"
# Checkout HEAD of pull request and set its sha to step output
git fetch origin pull/${{ needs.trigger.outputs.pr_number }}/head:BENCHDIFF_HEAD
git checkout BENCHDIFF_HEAD
echo "::set-output name=head::$(git rev-parse HEAD)"
set -x
# Set modified packages to step output
# git diff: get difference between HEAD and baseline
# grep: filter non-go files
# xargs -r: --no-run-if-empty, ignore empty line
# xargs dirname: keep only the directory name (go packages)
# xargs ls: filter non-exist files
# sort | uniq: dedup
pkgs=$(git diff --name-only BENCHDIFF_BASE | grep '.go$' | xargs -r dirname | xargs -r ls -d 2>/dev/null | sort | uniq)
if [ ! -z "${pkgs}" ]; then
# awk: Add "./" prefix to let `go test` known they are relative paths
# tr: join paths to one line, otherwise benchdiff cannot recognize it
pkgs=$(echo "${pkgs}" | awk '{print "./" $0}' | tr '\n' ' ')
fi
echo "::set-output name=pkgs::${pkgs}"
- name: Setup go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Benchdiff
uses: WillAbides/[email protected]
id: diff
if: steps.head.outputs.pkgs != ''
with:
benchdiff_version: 0.7.1
status_sha: ${{ steps.head.outputs.head }}
status_name: Benchdiff result
status_on_degraded: neutral
benchdiff_args: |
--cpu=4
--packages="${{ steps.head.outputs.pkgs }}"
--count=10
--warmup-count=1
--benchtime=1s
--benchmem
--tolerance=50
--base-ref=${{ steps.head.outputs.base }}
--debug
- name: Report benchdiff result via comment
uses: peter-evans/create-or-update-comment@v1
if: steps.head.outputs.pkgs != ''
with:
issue-number: '${{ needs.trigger.outputs.pr_number }}'
body: |
## Benchdiff
Command: `${{ steps.diff.outputs.bench_command }}`
HEAD: ${{ steps.diff.outputs.head_sha }}
Base: ${{ steps.diff.outputs.base_sha }}
Runs: ${{ env.RUNS_URL }}
Degraded: ${{ steps.diff.outputs.degraded_result }}
<details>
<summary>Results</summary>
${{ steps.diff.outputs.benchstat_output }}
</details>
- name: On skipped
uses: peter-evans/create-or-update-comment@v1
if: steps.head.outputs.pkgs == ''
with:
issue-number: '${{ needs.trigger.outputs.pr_number }}'
body: |
## Benchdiff
Runs: ${{ env.RUNS_URL }}
There is no package to bench.
- name: On failure
uses: peter-evans/create-or-update-comment@v1
if: ${{ failure() }}
with:
issue-number: '${{ needs.trigger.outputs.pr_number }}'
body: |
## Benchdiff
Runs: ${{ env.RUNS_URL }}
Job is failed.