-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
126 lines (111 loc) · 4.39 KB
/
action.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
name: 'Go Benchmark Action'
description: 'Run Go benchmarks and optionally publish results to GitHub Pages'
inputs:
benchmarks-pr:
description: 'Comma-separated list of benchmarks to run on PRs (e.g., BenchmarkOne, BenchmarkTwo). Set to "from-pr" to extract from PR description.'
required: false
default: 'from-pr'
benchmarks-merge:
description: 'Comma-separated list of benchmarks to run on merges (e.g., BenchmarkOne, BenchmarkTwo).'
required: false
default: ''
trigger-branches:
# if this input did not exist, every commit to every branch (including PRs) will trigger the action for merges,
# this is because both PRs and pushes to branches trigger the 'push' event
description: 'Comma-separated list of branches for which merges will trigger this action.'
required: true
use-gh-pages:
description: 'Flag to enable publishing results to GitHub Pages (true or false)'
required: false
default: false
github-token:
description: 'GitHub token for authentication (GITHUB_TOKEN or a personal access token). Required if use-gh-pages is true.'
required: false
gh-pages-branch:
description: 'The GitHub Pages branch to push results to (defaults to gh-pages). Required if use-gh-pages is true.'
required: false
default: 'gh-pages'
alert-comment-cc-users:
description: 'Comma-separated list of users to cc on alert comments (e.g., @user1, @user2).'
required: false
default: ''
runs:
using: 'composite'
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Setup Go Environment
uses: actions/setup-go@v4
with:
go-version: 'stable'
- name: Analyze GitHub Event
id: analyze-event
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "IS_MERGE=false" >> $GITHUB_ENV
echo "IS_PR=true" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "push" ]]; then
TRIGGER_BRANCHES="${{ inputs.trigger-branches }}"
if [[ "$TRIGGER_BRANCHES" == *"${{ github.ref_name }}"* ]]; then
echo "IS_MERGE=true" >> $GITHUB_ENV
echo "IS_PR=false" >> $GITHUB_ENV
else
echo "IS_MERGE=false" >> $GITHUB_ENV
echo "IS_PR=false" >> $GITHUB_ENV
fi
else
echo "IS_MERGE=false" >> $GITHUB_ENV
echo "IS_PR=false" >> $GITHUB_ENV
fi
shell: bash
- name: Determine Benchmarks to Run
id: set-benchmarks
run: |
if [[ "${{ inputs.benchmarks-pr }}" == "from-pr" && ${{ env.IS_PR }} == "true" ]]; then
BENCHMARKS=$(echo '${{ github.event.pull_request.body }}' | sed -n -e 's/^.*BENCHMARKS: //p')
else
BENCHMARKS=${{ inputs.benchmarks-merge }}
fi
echo "BENCHMARKS=$BENCHMARKS" >> $GITHUB_ENV
shell: bash
- name: Run Specified Go Benchmarks
# must use a context in an if conditional statement to access the value of an variable
if: ${{ env.IS_PR == 'true' || env.IS_MERGE == 'true' }}
run: go test ./... -bench "$BENCHMARKS" -run=^$ | tee output.txt
shell: bash
- name: Download Previous Benchmark Data
if: ${{ env.IS_PR == 'true' || env.IS_MERGE == 'true' }}
uses: actions/cache@v2
with:
path: ./cache
key: ${{ runner.os }}-benchmark
- name: Run github-action-benchmark for PRs
if: ${{ env.IS_PR == 'true' }}
uses: benchmark-action/github-action-benchmark@v1
with:
tool: 'go'
output-file-path: output.txt
external-data-json-path: './cache/benchmark-data.json'
fail-on-alert: true
auto-push: false
comment-on-alert: true
summary-always: true
github-token: ${{ inputs.github-token }}
- name: Run github-action-benchmark for Merges
if: ${{ env.IS_MERGE == 'true' }}
uses: benchmark-action/github-action-benchmark@v1
with:
tool: 'go'
output-file-path: output.txt
fail-on-alert: false
comment-on-alert: true
auto-push: ${{ inputs.use-gh-pages == 'true' }}
github-token: ${{ inputs.github-token }}
alert-comment-cc-users: ${{ inputs.alert-comment-cc-users }}
- name: Upload Updated Benchmark Data
if: ${{ env.IS_MERGE == 'true' }}
uses: actions/cache@v2
with:
path: ./cache
key: ${{ runner.os }}-benchmark
restore-keys: ${{ runner.os }}-benchmark