@@ -116,6 +116,18 @@ jobs:
116116 run : |
117117 echo "🚀 Starting benchmark execution..."
118118
119+ BENCH_FILENAME=$(basename "$SCRIPT_PATH")
120+ BENCH_ID="${BENCH_FILENAME%.jl}"
121+ OUTPUT_DIR="docs/src/assets/benchmarks/$BENCH_ID"
122+ mkdir -p "$OUTPUT_DIR"
123+ export BENCHMARK_OUTPUT_DIR="$OUTPUT_DIR"
124+ export BENCHMARK_ID="$BENCH_ID"
125+ echo "BENCHMARK_OUTPUT_DIR=$OUTPUT_DIR" >> $GITHUB_ENV
126+ echo "BENCHMARK_ID=$BENCH_ID" >> $GITHUB_ENV
127+
128+ echo "🏷️ Benchmark ID: $BENCH_ID"
129+ echo "📁 Output directory (pre-created): $OUTPUT_DIR"
130+
119131 julia --color=yes -e '
120132 using Pkg
121133
@@ -134,17 +146,34 @@ jobs:
134146
135147 println("🔄 Loading CTBenchmarks package...")
136148 using CTBenchmarks
137-
149+
138150 include(ENV["SCRIPT_PATH"])
139- out = main()
140- println("📄 Output file: ", out)
141- open(ENV["BENCHMARK_OUTPUT_FILE"], "w") do f
142- write(f, string(out))
151+ if !isdefined(Main, :run)
152+ error("Benchmark script must define a run() function that returns benchmark results")
153+ end
154+
155+ println("▶️ Running benchmark script...")
156+ results = run()
157+
158+ bench_id = ENV["BENCHMARK_ID"]
159+ outpath = ENV["BENCHMARK_OUTPUT_DIR"]
160+ figures_dir = joinpath(outpath, "figures")
161+
162+ println("📊 Generating solution plots...")
163+ CTBenchmarks.plot_solutions(results, figures_dir)
164+
165+ json_path = joinpath(outpath, string(bench_id, ".json"))
166+ println("💾 Saving results to ", json_path)
167+ CTBenchmarks.save_json(results, json_path)
168+ println("📄 JSON file created: ", json_path)
169+ open(ENV["GITHUB_ENV"], "a") do io
170+ println(io, "BENCHMARK_JSON=$json_path")
143171 end
144- println("💾 Output path saved to ", ENV["BENCHMARK_OUTPUT_FILE"])
145172 '
146173
147174 echo "✅ Benchmark execution completed"
175+ echo "$OUTPUT_DIR" > "$BENCHMARK_OUTPUT_FILE"
176+ echo "💾 Output path saved to $BENCHMARK_OUTPUT_FILE"
148177 echo "benchmark_success=true" >> $GITHUB_OUTPUT
149178
150179 # ---------------------------
@@ -202,7 +231,8 @@ jobs:
202231 OUTPUT_DIR=$(cat "$BENCHMARK_OUTPUT_FILE")
203232 echo "✅ Benchmark output directory found: $OUTPUT_DIR"
204233
205- DATA_JSON_PATH="$OUTPUT_DIR/data.json"
234+ BENCH_ID="${BENCHMARK_ID:-$(basename "$OUTPUT_DIR") }"
235+ DATA_JSON_PATH="$OUTPUT_DIR/$BENCH_ID.json"
206236 echo "📄 Resolved JSON path: $DATA_JSON_PATH"
207237
208238 if [ -f "$DATA_JSON_PATH" ]; then
@@ -276,10 +306,11 @@ jobs:
276306 DIR_NAME=$(basename "$OUTPUT_DIR")
277307
278308 ARTIFACTS=(
279- "$OUTPUT_DIR/data .json"
309+ "$OUTPUT_DIR/$DIR_NAME .json"
280310 "$OUTPUT_DIR/Project.toml"
281311 "$OUTPUT_DIR/Manifest.toml"
282312 "$OUTPUT_DIR/$DIR_NAME.jl"
313+ "$OUTPUT_DIR/figures"
283314 )
284315
285316 # Add only benchmark artifacts
@@ -294,7 +325,7 @@ jobs:
294325
295326 echo "📝 Committing $STAGED file(s) to branch $BRANCH_NAME..."
296327 git commit -m "📊 Add benchmark results (${DIR_NAME})" \
297- -m "Results saved to ${OUTPUT_DIR}/data .json" \
328+ -m "Results saved to ${OUTPUT_DIR}/${DIR_NAME} .json" \
298329 -m "Includes environment TOMLs and benchmark script" \
299330 >/dev/null 2>&1 || {
300331 echo "❌ Commit failed"
@@ -333,9 +364,10 @@ jobs:
333364 exit 1
334365 fi
335366
367+ DIR_NAME=$(basename "$OUTPUT_DIR")
336368 echo "📊 Benchmark workflow summary:"
337369 echo "✅ Benchmark execution: SUCCESS"
338- echo "📁 Results saved to: $OUTPUT_DIR/data .json"
370+ echo "📁 Results saved to: $OUTPUT_DIR/$DIR_NAME .json"
339371 echo "🌳 Results committed to: ${{ github.head_ref || github.ref_name }} branch"
340372 echo "📘 Ready for documentation generation"
341373 echo "🎉 Reusable benchmark workflow completed successfully!"
0 commit comments