Skip to content

Commit c62208a

Browse files
committed
Attempt rerunning and image solutions
1 parent 7544cb6 commit c62208a

File tree

3 files changed

+63
-81
lines changed

3 files changed

+63
-81
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ default:
2929
- .local/bin
3030
- .local/include
3131
- .local/share
32-
- .snakemake/log
32+
- .snakemake/
3333
- results
3434
- config
3535
- .env
3636
- summary.txt
37+
- warmup/
3738
reports:
3839
dotenv: .env
3940
when: always

benchmarks/lowq2_reconstruction/PRfunctions.py

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import xml.etree.ElementTree as ET
88
from pathlib import Path
99
from datetime import datetime, timezone
10+
import subprocess
11+
import tempfile
12+
import json
13+
import os
1014

1115
# =============================================================================
1216
# Utility Functions
@@ -172,19 +176,15 @@ def find_line_number_of_change(original_content, old_value):
172176
# =============================================================================
173177

174178
def process_image_list(image_list):
175-
"""Process a list of images - should be URLs from gh CLI upload"""
179+
"""Process a list of images - can be URLs or local file paths"""
176180
if not image_list:
177181
return []
178182

179183
processed_images = []
180184
for img in image_list:
181-
# Accept URLs as-is (these should be GitHub user-attachments URLs from gh CLI)
182-
if img.startswith(('http://', 'https://')):
183-
processed_images.append(img)
184-
else:
185-
# For local paths, warn the user
186-
print(f"⚠️ Local file path provided: {img}")
187-
print(f" Images must be uploaded via gh CLI first to get GitHub CDN URLs")
185+
# Accept both URLs and local file paths
186+
# Local paths will be handled by gh CLI when creating the comment
187+
processed_images.append(img)
188188

189189
return processed_images
190190

@@ -250,35 +250,61 @@ def create_pr_suggestion(repo_owner, repo_name, pr_number, calibration_file, xml
250250
comment_body += f"![After Image {i}]({img_url})\n\n"
251251

252252
if existing_comment_id:
253-
# Update existing comment
253+
# Update existing comment using gh CLI
254254
print(f"Updating existing comment {existing_comment_id}...")
255-
update_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues/comments/{existing_comment_id}"
256-
update_data = {'body': comment_body}
257-
response = requests.patch(update_url, headers=headers, json=update_data)
258255

259-
if response.status_code == 200:
256+
# Write comment body to temp file
257+
with tempfile.NamedTemporaryFile(mode='w', suffix='.md', delete=False) as f:
258+
f.write(comment_body)
259+
temp_file = f.name
260+
261+
try:
262+
# gh api to update comment
263+
result = subprocess.run(
264+
['gh', 'api',
265+
f'/repos/{repo_owner}/{repo_name}/issues/comments/{existing_comment_id}',
266+
'-X', 'PATCH',
267+
'-F', f'body=@{temp_file}'],
268+
capture_output=True,
269+
text=True,
270+
check=True
271+
)
260272
print("✅ Existing PR comment updated successfully")
261-
return response.json()
262-
else:
263-
print(f"❌ Failed to update existing comment: {response.status_code}")
264-
print(f" Response: {response.text}")
273+
return json.loads(result.stdout)
274+
except subprocess.CalledProcessError as e:
275+
print(f"❌ Failed to update existing comment: {e}")
276+
print(f" Error: {e.stderr}")
265277
return None
278+
finally:
279+
os.unlink(temp_file)
266280
else:
267-
# Create new regular PR comment
281+
# Create new regular PR comment using gh CLI
268282
print("Creating new PR comment...")
269-
comment_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues/{pr_number}/comments"
270283

271-
comment_data = {'body': comment_body}
284+
# Write comment body to temp file
285+
with tempfile.NamedTemporaryFile(mode='w', suffix='.md', delete=False) as f:
286+
f.write(comment_body)
287+
temp_file = f.name
272288

273-
response = requests.post(comment_url, headers=headers, json=comment_data)
274-
275-
if response.status_code == 201:
289+
try:
290+
# gh pr comment will automatically upload local image files
291+
result = subprocess.run(
292+
['gh', 'pr', 'comment', str(pr_number),
293+
'--repo', f'{repo_owner}/{repo_name}',
294+
'--body-file', temp_file],
295+
capture_output=True,
296+
text=True,
297+
check=True
298+
)
276299
print("✅ New PR comment created successfully")
277-
return response.json()
278-
else:
279-
print(f"❌ Failed to create PR comment: {response.status_code}")
280-
print(f" Response: {response.text}")
300+
# gh pr comment returns URL, parse to get comment data
301+
return {'html_url': result.stdout.strip()}
302+
except subprocess.CalledProcessError as e:
303+
print(f"❌ Failed to create PR comment: {e}")
304+
print(f" Error: {e.stderr}")
281305
return None
306+
finally:
307+
os.unlink(temp_file)
282308

283309
def find_existing_bot_comment(repo_owner, repo_name, pr_number, bot_comment_base, xml_file, line_number, github_token):
284310
"""Find existing bot comment on the specific line"""

benchmarks/lowq2_reconstruction/config.yml

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -102,59 +102,14 @@ upload_onnx:lowq2_reconstruction:
102102
- printenv
103103
- echo "Updating PR with lowq2 reconstruction results"
104104
- echo "ONNX file will be available at $ONNX_UPLOAD_URL"
105-
- echo "Uploading images to GitHub CDN"
106105
- |
107-
# Function to upload image to GitHub's attachment CDN
108-
upload_image() {
109-
local img_path="$1"
110-
111-
if [ ! -f "$img_path" ]; then
112-
echo "⚠️ Image not found: $img_path"
113-
return
114-
fi
115-
116-
# Upload using GitHub's attachment API endpoint
117-
# This is what the web UI uses when you drag-and-drop images
118-
response=$(curl -s -X POST \
119-
-H "Authorization: Bearer $GITHUB_REPO_POST_COMMENT_BENCHMARKS" \
120-
-H "Content-Type: $(file -b --mime-type "$img_path")" \
121-
-H "Accept: application/vnd.github+json" \
122-
--data-binary "@$img_path" \
123-
"https://uploads.github.com/repos/eic/detector_benchmarks/assets?name=$(basename "$img_path")")
124-
125-
# Extract URL from response
126-
img_url=$(echo "$response" | grep -oP '"url":\s*"\K[^"]+' | head -1)
127-
128-
if [ -n "$img_url" ]; then
129-
echo "✅ Uploaded: $img_url"
130-
echo "$img_url"
131-
else
132-
echo "⚠️ Upload failed for $img_path"
133-
echo ""
134-
fi
135-
}
136-
137-
BEFORE_IMAGE="results/lowq2_reconstruction/test_local/test_energy_theta_phi_resolution_local.png"
138-
AFTER_IMAGE="results/lowq2_reconstruction/retrained_local/retrained_energy_theta_phi_resolution_local.png"
139-
140-
BEFORE_URL=$(upload_image "$BEFORE_IMAGE")
141-
AFTER_URL=$(upload_image "$AFTER_IMAGE")
142-
143-
# Build image arguments
144-
IMAGE_ARGS=""
145-
if [ -n "$BEFORE_URL" ]; then
146-
IMAGE_ARGS="$IMAGE_ARGS --beforeImages $BEFORE_URL"
147-
fi
148-
if [ -n "$AFTER_URL" ]; then
149-
IMAGE_ARGS="$IMAGE_ARGS --afterImages $AFTER_URL"
150-
fi
151-
152106
python benchmarks/lowq2_reconstruction/makePRSuggestion.py \
153-
--pr 213 \
154-
--newURL $ONNX_DOWNLOAD_URL \
155-
--githubToken $GITHUB_REPO_POST_COMMENT_BENCHMARKS \
156-
--calibrationFile calibrations/onnx/Low-Q2_Steering_Reconstruction.onnx \
157-
--xml benchmarks/lowq2_reconstruction/calibrations.xml \
158-
--repository eic/detector_benchmarks \
159-
$IMAGE_ARGS
107+
--pr 213 \
108+
--newURL "$ONNX_DOWNLOAD_URL" \
109+
--githubToken "$GITHUB_REPO_POST_COMMENT_BENCHMARKS" \
110+
--calibrationFile calibrations/onnx/Low-Q2_Steering_Reconstruction.onnx \
111+
--xml benchmarks/lowq2_reconstruction/calibrations.xml \
112+
--repository eic/detector_benchmarks \
113+
--beforeImages results/lowq2_reconstruction/test_local/test_energy_theta_phi_resolution_local.png \
114+
--afterImages results/lowq2_reconstruction/retrained_local/retrained_energy_theta_phi_resolution_local.png
160115
- echo "Updating GitHub status for lowq2 reconstruction"

0 commit comments

Comments
 (0)