-
Notifications
You must be signed in to change notification settings - Fork 773
153 lines (130 loc) · 5.27 KB
/
ci-perf.yml
File metadata and controls
153 lines (130 loc) · 5.27 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
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
149
150
151
152
153
name: CI - Perf
# EXPERIMENTAL: This workflow is running with --tolerate-failure flag for phpbench
# This is to gather data for a future historical interleaving of performance benchmarks.
on:
# Run once per day no matter what
schedule:
- cron: '0 0 * * *'
# Run on push to main, so we get a data point every merge
push:
branches:
- main
# Allow manual triggering with rebaseline option
workflow_dispatch:
inputs:
baseline:
description: 'Baseline mode. latest: compare against latest benchmarks; rebaseline: store new baseline.'
type: choice
default: 'latest'
options:
- 'latest'
- 'rebaseline'
pull:
description: 'Pull request number to benchmark (optional)'
required: false
jobs:
pr-benchmarks:
name: PR Benchmarks
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pull }}
runs-on: ubuntu-latest
env:
BENCHMARK_SHA: ${{ github.sha }}
permissions:
contents: read
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- name: Checkout PR head
run: |
set -euo pipefail
PR=${{ github.event.inputs.pull }}
# Validate that PR is numeric to avoid injection or unexpected ref resolution
if ! printf '%s\n' "$PR" | grep -Eq '^[0-9]+$'; then
echo "Invalid pull request number: '$PR'. Expected a numeric value." >&2
exit 1
fi
# fetch the pull request head (works for forks)
git fetch origin "pull/${PR}/head:pr-${PR}" || git fetch origin "+refs/pull/${PR}/head:pr-${PR}"
git checkout "pr-${PR}"
echo "Checked out PR #${PR}"
echo "BENCHMARK_SHA=$(git rev-parse --verify HEAD)" >> "$GITHUB_ENV"
- uses: ./.github/actions/setup-action
with:
extensions: xdebug
- name: Fetch Benchmarks
run: |
git fetch origin benchmarks
mkdir -p .phpbench
git checkout origin/benchmarks -- .phpbench || echo "No previous benchmarks found"
- name: Run Benchmarks
run: |
# Baseline does not exist or rebaseline requested. Generate it.
if [ -z "$(ls -A .phpbench)" ] || [ "${{ github.event.inputs.baseline || 'latest' }}" = "rebaseline" ]; then
vendor/bin/phpbench run --report=aggregate --progress=plain --store --tag=${BENCHMARK_SHA}
# Baseline exists. Compare against it.
else
vendor/bin/phpbench run --report=aggregate --progress=plain --store --tag=${BENCHMARK_SHA} --ref=latest --tolerate-failure
fi
# Generate report for human consumption
vendor/bin/phpbench report --report=aggregate --ref=latest |
tail -n+2 | head -n-2 | tr '+' '|' > report.md
cat report.md > "$GITHUB_STEP_SUMMARY"
historical-benchmarks:
name: Historical Benchmarks
if: >-
github.event_name != 'workflow_dispatch' ||
!github.event.inputs.pull
runs-on: ubuntu-latest
env:
BENCHMARK_SHA: ${{ github.sha }}
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
persist-credentials: true
- uses: ./.github/actions/setup-action
with:
extensions: xdebug
- name: Fetch Benchmarks
run: |
git fetch origin benchmarks
mkdir -p .phpbench
git checkout origin/benchmarks -- .phpbench || echo "No previous benchmarks found"
- name: Run Benchmarks
run: |
# Baseline does not exist or rebaseline requested. Generate it.
if [ -z "$(ls -A .phpbench)" ] || [ "${{ github.event.inputs.baseline || 'latest' }}" = "rebaseline" ]; then
vendor/bin/phpbench run --report=aggregate --progress=plain --store --tag=${BENCHMARK_SHA}
# Baseline exists. Compare against it.
else
vendor/bin/phpbench run --report=aggregate --progress=plain --store --tag=${BENCHMARK_SHA} --ref=latest --tolerate-failure
fi
# Generate report for human consumption
vendor/bin/phpbench report --report=aggregate --ref=latest |
tail -n+2 | head -n-2 | tr '+' '|' > report.md
cat report.md
- name: Commit Results
# only on: main push, schedule, workflow_dispatch+rebaseline
if: >-
(github.ref == 'refs/heads/main' && github.event_name == 'push') ||
(github.event_name == 'schedule') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.baseline == 'rebaseline')
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout benchmarks
mv -f report.md latest.md
git add .phpbench latest.md
git commit -m "Store benchmark results [skip ci]" || echo "No changes to commit"
git push origin benchmarks
- name: Restore workspace
if: always()
run: |
set -euo pipefail
echo "Restoring workspace to original commit: ${GITHUB_SHA}"
git fetch origin || true
git checkout --detach "${GITHUB_SHA}"
git reset --hard "${GITHUB_SHA}"