Skip to content

Commit 8f348ba

Browse files
AnHeuermannclaude
andauthored
Log BaseModelica.jl SHA (#16)
* Add Git SHA of BaseModelica.jl to HTML report and summary.json. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent cbf2a59 commit 8f348ba

9 files changed

Lines changed: 85 additions & 15 deletions

File tree

.github/workflows/CI.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ jobs:
9191
main(
9292
library = "Modelica",
9393
version = "4.1.0",
94-
filter = "Modelica.Electrical.Analog.Examples.ChuaCircuit",
95-
results_root = "results/main/Modelica/4.1.0/"
94+
filter = "Modelica.Electrical.Analog.Examples.ChuaCircuit"
9695
)
9796
'
9897

.github/workflows/msl-test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ jobs:
120120
main(
121121
library = ENV["LIB_NAME"],
122122
version = ENV["LIB_VERSION"],
123-
results_root = "results/$(ENV["BM_VERSION"])/$(ENV["LIB_NAME"])/$(ENV["LIB_VERSION"])",
124123
ref_root = "MAP-LIB_ReferenceResults",
125124
)
126125
'

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
99
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
1010
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1111
OMJulia = "0f4fe800-344e-11e9-2949-fb537ad918e1"
12+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1213
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1314
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1415
ZMQ = "c2297ded-f4af-51ae-bb23-16f91089e4e1"

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ main(
2424
version = "<Modelica library version>",
2525
filter = "<Modelica class filter>",
2626
omc_exe = "path/to/omc",
27-
results_root = "results",
2827
ref_root = "path/to/ReferenceResults"
2928
)
3029
```
@@ -50,7 +49,6 @@ main(
5049
version = "4.1.0",
5150
filter = "Modelica.Electrical.Analog.Examples.ChuaCircuit",
5251
omc_exe = "omc",
53-
results_root = "results/main/Modelica/4.1.0/",
5452
ref_root = "MAP-LIB_ReferenceResults"
5553
)
5654
```

src/BaseModelicaLibraryTesting.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module BaseModelicaLibraryTesting
22

3+
import Pkg
34
import OMJulia
45
import OMJulia: sendExpression
56
import BaseModelica

src/pipeline.jl

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1+
# ── BaseModelica.jl version helpers ────────────────────────────────────────────
2+
3+
"""
4+
_bm_sha() → String
5+
6+
Return the first 7 characters of the git commit SHA for the installed
7+
BaseModelica.jl package by resolving the package's tree SHA against the
8+
cached git clone in the Julia depot. Falls back to the tree SHA when the
9+
clone cannot be found, and returns `""` for registry installs (no git
10+
metadata available) or when the SHA cannot be determined.
11+
"""
12+
function _bm_sha()::String
13+
try
14+
for (_, info) in Pkg.dependencies()
15+
info.name == "BaseModelica" || continue
16+
tree_sha = info.tree_hash
17+
tree_sha === nothing && return ""
18+
19+
# Resolve the tree SHA to a commit SHA via the cached git clone.
20+
git_source = info.git_source
21+
if git_source !== nothing
22+
for depot in Base.DEPOT_PATH
23+
clones_dir = joinpath(depot, "clones")
24+
@show clones_dir
25+
isdir(clones_dir) || continue
26+
for clone in readdir(clones_dir; join=true)
27+
isdir(clone) || continue
28+
try
29+
remote = strip(readchomp(`git -C $clone remote get-url origin`))
30+
(remote == git_source || remote * ".git" == git_source ||
31+
git_source * ".git" == remote) || continue
32+
fmt = "%H %T"
33+
log = readchomp(`git -C $clone log --all --format=$fmt`)
34+
for line in split(log, '\n')
35+
parts = split(strip(line))
36+
length(parts) == 2 && parts[2] == tree_sha || continue
37+
sha = parts[1]
38+
return sha[1:min(7, length(sha))]
39+
end
40+
catch
41+
end
42+
end
43+
end
44+
end
45+
46+
# Fall back to the tree SHA when no clone is found.
47+
return tree_sha[1:min(7, length(tree_sha))]
48+
end
49+
catch
50+
end
51+
return ""
52+
end
53+
154
# ── Per-model orchestrator ─────────────────────────────────────────────────────
255

356
"""
@@ -69,8 +122,17 @@ function main(;
69122
)
70123
t0 = time()
71124

125+
# Set up working directory
126+
bm_version = get(ENV, "BM_VERSION", string(pkgversion(BaseModelica)))
127+
bm_sha = _bm_sha()
128+
@info "Testing BaseModelica.jl version $(bm_version) ($(bm_sha))"
129+
72130
if isempty(results_root)
73-
results_root = joinpath(library, version)
131+
if bm_version == "main"
132+
results_root = joinpath("results", bm_sha, library, version)
133+
else
134+
results_root = joinpath("results", bm_version, library, version)
135+
end
74136
end
75137
results_root = abspath(results_root)
76138
mkpath(joinpath(results_root, "files"))
@@ -142,8 +204,6 @@ function main(;
142204
end
143205

144206
cpu_info = Sys.cpu_info()
145-
bm_ver_env = get(ENV, "BM_VERSION", "")
146-
bm_version = isempty(bm_ver_env) ? string(pkgversion(BaseModelica)) : bm_ver_env
147207
info = RunInfo(
148208
library,
149209
version,
@@ -154,6 +214,7 @@ function main(;
154214
ref_root,
155215
omc_version,
156216
bm_version,
217+
bm_sha,
157218
isempty(cpu_info) ? "unknown" : strip(cpu_info[1].model),
158219
length(cpu_info),
159220
Sys.total_memory() / 1024^3,

src/report.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ function generate_report(results::Vector{ModelResult}, results_root::String,
7878
$(_cmp_cell(r, results_root))
7979
</tr>""" for r in results], "\n")
8080

81-
filter_row = isempty(info.filter) ? "" : "<br>Filter: $(info.filter)"
82-
ref_row = isempty(info.ref_root) ? "" : "<br>Reference results: $(info.ref_root)"
83-
ram_str = @sprintf("%.1f", info.ram_gb)
84-
time_str = _format_duration(info.total_time_s)
81+
bm_sha_link = isempty(info.bm_sha) ? "" :
82+
""" (<a href="https://github.com/SciML/BaseModelica.jl/commit/$(info.bm_sha)">$(info.bm_sha)</a>)"""
83+
basemodelica_jl_version = info.bm_version * bm_sha_link
84+
var_filter = isempty(info.filter) ? "None" : "<code>$(info.filter)</code>"
85+
ref_results = isempty(info.ref_root) ? "None" : "$(info.ref_root)"
86+
ram_str = @sprintf("%.1f", info.ram_gb)
87+
time_str = _format_duration(info.total_time_s)
8588

8689
html = """<!DOCTYPE html>
8790
<html lang="en">
@@ -106,7 +109,9 @@ function generate_report(results::Vector{ModelResult}, results_root::String,
106109
<p>Generated: $(now())<br>
107110
OpenModelica: $(info.omc_version)<br>
108111
OMC options: <code>$(info.omc_options)</code><br>
109-
BaseModelica.jl: $(info.bm_version)$(filter_row)$(ref_row)</p>
112+
BaseModelica.jl: $(basemodelica_jl_version)<br>
113+
Filter: $(var_filter)<br>
114+
Reference results: $(ref_results)</p>
110115
<p>CPU: $(info.cpu_model) ($(info.cpu_threads) threads)<br>
111116
RAM: $(ram_str) GiB<br>
112117
Total run time: $(time_str)</p>

src/summary.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function write_summary(
2828
print(io, " \"ref_root\": \"$(_esc_json(info.ref_root))\",\n")
2929
print(io, " \"omc_version\": \"$(_esc_json(info.omc_version))\",\n")
3030
print(io, " \"bm_version\": \"$(_esc_json(info.bm_version))\",\n")
31+
print(io, " \"bm_sha\": \"$(_esc_json(info.bm_sha))\",\n")
3132
print(io, " \"cpu_model\": \"$(_esc_json(info.cpu_model))\",\n")
3233
print(io, " \"cpu_threads\": $(info.cpu_threads),\n")
3334
print(io, " \"ram_gb\": $(@sprintf "%.2f" info.ram_gb),\n")
@@ -67,7 +68,8 @@ Parsed contents of a single `summary.json` file.
6768
- `results_root` — absolute path where results were written
6869
- `ref_root` — absolute path to reference results, or `""` when unused
6970
- `omc_version` — OMC version string
70-
- `bm_version` — BaseModelica.jl version string (e.g. `"1.6.0"`)
71+
- `bm_version` — BaseModelica.jl version string (e.g. `"1.6.0"` or `"main"`)
72+
- `bm_sha` — git tree-SHA of the installed BaseModelica.jl, or `""`
7173
- `cpu_model` — CPU model name
7274
- `cpu_threads` — number of logical CPU threads
7375
- `ram_gb` — total system RAM in GiB
@@ -85,6 +87,7 @@ struct RunSummary
8587
ref_root :: String
8688
omc_version :: String
8789
bm_version :: String
90+
bm_sha :: String
8891
cpu_model :: String
8992
cpu_threads :: Int
9093
ram_gb :: Float64
@@ -142,6 +145,7 @@ function load_summary(results_root::String)::Union{RunSummary,Nothing}
142145
_str("ref_root"),
143146
_str("omc_version"),
144147
_str("bm_version"),
148+
_str("bm_sha"),
145149
_str("cpu_model"),
146150
_int("cpu_threads"),
147151
_float("ram_gb"),

src/types.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ Metadata about a single test run, collected by `main()` and written into both
5050
- `results_root` — absolute path where results are written
5151
- `ref_root` — absolute path to reference results, or `""` when unused
5252
- `omc_version` — version string returned by `getVersion()`, e.g. `"v1.23.0"`
53-
- `bm_version` — BaseModelica.jl version string, e.g. `"1.6.0"`
53+
- `bm_version` — BaseModelica.jl version string, e.g. `"1.6.0"` or `"main"`
54+
- `bm_sha` — git tree-SHA of the installed BaseModelica.jl (first 7 chars), or `""`
5455
- `cpu_model` — CPU model name from `Sys.cpu_info()`
5556
- `cpu_threads` — number of logical CPU threads
5657
- `ram_gb` — total system RAM in GiB
@@ -66,6 +67,7 @@ struct RunInfo
6667
ref_root :: String # "" when no reference root was given
6768
omc_version :: String
6869
bm_version :: String
70+
bm_sha :: String # git tree-SHA (short), "" for registry installs
6971
cpu_model :: String
7072
cpu_threads :: Int
7173
ram_gb :: Float64

0 commit comments

Comments
 (0)