Skip to content

Commit 30661a2

Browse files
authored
[CI] Fix benchmark CI upload with conditional PR testing (#3093)
1 parent 2bd0642 commit 30661a2

File tree

2 files changed

+101
-24
lines changed

2 files changed

+101
-24
lines changed

.github/workflows/benchmarks.yml

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ permissions:
1212
id-token: write
1313
deployments: write
1414
contents: write
15+
pull-requests: write
1516

1617
concurrency:
1718
# Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
@@ -58,7 +59,10 @@ jobs:
5859
apt-get upgrade -y
5960
apt-get -y install libglu1-mesa libgl1-mesa-glx libosmesa6 gcc curl g++ unzip wget libglfw3-dev libgles2-mesa-dev libglew-dev sudo git cmake libz-dev libpython3.10-dev
6061
- name: Setup git
61-
run: git config --global --add safe.directory /__w/rl/rl
62+
run: |
63+
git config --global --add safe.directory /__w/rl/rl
64+
git config --global user.name "github-action-benchmark"
65+
git config --global user.email "github@users.noreply.github.com"
6266
- name: setup Path
6367
run: |
6468
echo /usr/local/bin >> $GITHUB_PATH
@@ -93,19 +97,85 @@ jobs:
9397
export COMPOSITE_LP_AGGREGATE=0
9498
export TD_GET_DEFAULTS_TO_NONE=1
9599
python3 -m pytest -vvv --rank 0 --benchmark-json output.json --ignore test_collectors_benchmark.py
96-
- name: Store benchmark results
100+
101+
# Upload benchmark results for main branch, manual dispatch, or PRs with 'benchmarks/upload' label
102+
- name: Upload benchmark results
103+
uses: actions/upload-artifact@v4
104+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'benchmarks/upload')) }}
105+
with:
106+
name: ${{ matrix.device }}-benchmark-results
107+
path: benchmarks/output.json
108+
109+
# Upload benchmark results to gh-pages branch (only for main, manual dispatch, or PRs with 'benchmarks/upload' label)
110+
benchmark-upload:
111+
name: Upload benchmark results
112+
runs-on: ubuntu-latest
113+
needs: benchmark
114+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'benchmarks/upload')) }}
115+
steps:
116+
- name: Show upload trigger reason
117+
run: |
118+
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
119+
echo "Uploading benchmarks because this is the main branch"
120+
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
121+
echo "Uploading benchmarks because of manual workflow dispatch"
122+
elif [ "${{ github.event_name }}" == "pull_request" ]; then
123+
echo "Uploading benchmarks because PR has 'benchmarks/upload' label"
124+
fi
125+
- name: Checkout
126+
uses: actions/checkout@v4
127+
- name: Download CPU benchmark results
128+
uses: actions/download-artifact@v4
129+
with:
130+
name: CPU-benchmark-results
131+
path: cpu-results
132+
- name: Download GPU benchmark results
133+
uses: actions/download-artifact@v4
134+
with:
135+
name: GPU-benchmark-results
136+
path: gpu-results
137+
- name: Show benchmark results summary
138+
run: |
139+
echo "=== CPU Benchmark Results ==="
140+
if [ -f "cpu-results/output.json" ]; then
141+
echo "CPU results found and will be uploaded"
142+
else
143+
echo "No CPU results found"
144+
fi
145+
146+
echo "=== GPU Benchmark Results ==="
147+
if [ -f "gpu-results/output.json" ]; then
148+
echo "GPU results found and will be uploaded"
149+
else
150+
echo "No GPU results found"
151+
fi
152+
- name: Store CPU benchmark results
153+
uses: benchmark-action/github-action-benchmark@v1
154+
with:
155+
name: CPU Benchmark Results
156+
tool: 'pytest'
157+
output-file-path: cpu-results/output.json
158+
fail-on-alert: true
159+
alert-threshold: '200%'
160+
alert-comment-cc-users: '@vmoens'
161+
# Disable PR comments to avoid permission issues with PR reviews
162+
comment-on-alert: false
163+
github-token: ${{ secrets.GITHUB_TOKEN }}
164+
gh-pages-branch: gh-pages
165+
auto-push: true
166+
- name: Store GPU benchmark results
97167
uses: benchmark-action/github-action-benchmark@v1
98-
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }}
99-
env:
100-
GIT_WORK_TREE: /__w/rl/rl
101168
with:
102-
name: ${{ matrix.device }} Benchmark Results
169+
name: GPU Benchmark Results
103170
tool: 'pytest'
104-
output-file-path: benchmarks/output.json
171+
output-file-path: gpu-results/output.json
105172
fail-on-alert: true
106173
alert-threshold: '200%'
107174
alert-comment-cc-users: '@vmoens'
108-
comment-on-alert: true
175+
# Disable PR comments to avoid permission issues with PR reviews
176+
comment-on-alert: false
109177
github-token: ${{ secrets.GITHUB_TOKEN }}
110178
gh-pages-branch: gh-pages
111179
auto-push: true
180+
# Use regular comments instead of PR reviews to avoid permission issues
181+
comment-style: 'github'

.gitignore

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,27 @@ __pycache__/
77
*.so
88

99
# Distribution / packaging
10+
*.egg
11+
*.egg-info/
1012
.Python
13+
.eggs/
14+
.installed.cfg
15+
MANIFEST
1116
build/
12-
dump/
17+
data/
1318
develop-eggs/
1419
dist/
1520
downloads/
21+
dump/
1622
eggs/
17-
.eggs/
1823
lib/
1924
lib64/
2025
parts/
2126
sdist/
27+
share/python-wheels/
28+
tmp/
2229
var/
2330
wheels/
24-
share/python-wheels/
25-
*.egg-info/
26-
.installed.cfg
27-
*.egg
28-
MANIFEST
2931

3032
# PyInstaller
3133
# Usually these files are written by a python script from a template
@@ -38,20 +40,25 @@ pip-log.txt
3840
pip-delete-this-directory.txt
3941

4042
# Unit test / coverage reports
41-
htmlcov/
42-
.tox/
43-
.nox/
44-
.coverage
45-
.coverage.*
46-
.cache
47-
.neptune
48-
nosetests.xml
49-
coverage.xml
5043
*.cover
5144
*.py,cover
45+
.benchmarks/
46+
.cache
47+
.coverage
48+
.coverage.*
5249
.hypothesis/
50+
.neptune
51+
.neptune
52+
.neptune/
53+
.nox/
5354
.pytest_cache/
55+
.pytest_cache/
56+
.tox/
5457
cover/
58+
coverage.xml
59+
htmlcov/
60+
nosetests.xml
61+
nosetests.xml
5562

5663
# Translations
5764
*.mo

0 commit comments

Comments
 (0)