@@ -12,7 +12,7 @@ are found.
12
12
"""
13
13
function sorted_dataset_folder (; dir = pwd ())
14
14
matching_paths = filter (ispath, readdir (dir; join = true ))
15
- isempty (matching_paths) && return " "
15
+ isempty (matching_paths) && return String[]
16
16
# sort by timestamp
17
17
sorted_paths =
18
18
sort (matching_paths; by = f -> Dates. unix2datetime (stat (f). mtime))
@@ -40,85 +40,80 @@ function ref_counters_per_path(paths)
40
40
end
41
41
42
42
"""
43
- latest_comparable_paths(n::Integer)
43
+ paths = latest_comparable_paths(;
44
+ n = 5,
45
+ root_path = "/central/scratch/esm/slurm-buildkite/climaatmos-main",
46
+ ref_counter_PR = read_ref_counter(joinpath(@__DIR__, "ref_counter.jl"))
47
+ )
44
48
45
49
Returns a vector of strings, containing the `n`
46
- latest comparable paths based on
47
- `reproducibility_tests/ref_counter.jl`.
48
- """
49
- function latest_comparable_paths (n = 5 )
50
- if get (ENV , " BUILDKITE_PIPELINE_SLUG" , nothing ) != " climaatmos-ci"
51
- @warn " Not using climaatmos-ci pipeline slug, assuming no comparable references"
52
- @info " Please review output results before merging."
53
- return String[]
54
- end
50
+ latest comparable paths. The assumed folder structure
51
+ is:
52
+
53
+ ```
54
+ root_path/some_folder_1/ref_counter.jl
55
+ root_path/some_folder_2/ref_counter.jl
56
+ root_path/some_folder_3/ref_counter.jl
57
+ ```
55
58
56
- # Note: cluster_data_prefix is also defined in move_output.jl
57
- cluster_data_prefix = " /central/scratch/esm/slurm-buildkite/climaatmos-main"
59
+ If a subfolder does not contain a `ref_counter.jl` file
60
+ then it is filtered out as not-comparable. The `ref_counter.jl`
61
+ files are assumed to start with a single integer,
62
+ which is read. If that integer matches `ref_counter_PR`,
63
+ then that path is considered comparable.
64
+
65
+ `paths[1]` is the most recent comparable path, and
66
+ `paths[end]` is the oldest comparable path.
67
+ """
68
+ function latest_comparable_paths (;
69
+ n = 5 ,
70
+ root_path = " /central/scratch/esm/slurm-buildkite/climaatmos-main" ,
71
+ ref_counter_PR = read_ref_counter (joinpath (@__DIR__ , " ref_counter.jl" )),
72
+ )
73
+ @info " ---Finding the latest comparable paths"
74
+ # Note: root_path is also defined in move_output.jl
58
75
# Get (sorted) array of paths, `pop!(sorted_paths)`
59
76
# is the most recent merged folder.
60
- sorted_paths = sorted_dataset_folder (; dir = cluster_data_prefix )
77
+ sorted_paths = sorted_dataset_folder (; dir = root_path )
61
78
if isempty (sorted_paths)
62
- @warn " No paths on main found, assuming no comparable references"
63
- @info " Please review output results before merging."
79
+ @warn " No paths found in $root_path "
64
80
return String[]
65
81
end
66
82
# Find oldest path in main with the same reference
67
83
# counter as the one in the PR. If none exists,
68
84
# then assume no comparable references.
69
85
70
- ref_counter_file_PR = joinpath (@__DIR__ , " ref_counter.jl" )
71
- @assert isfile (ref_counter_file_PR)
72
- ref_counter_PR = read_ref_counter (ref_counter_file_PR)
73
-
74
- ref_counters_main = ref_counters_per_path (sorted_paths)
75
- i_comparable_references = findall (ref_counters_main) do ref_counter_main
76
- ref_counter_main == ref_counter_PR
77
- end
78
- if isnothing (i_comparable_references)
79
- @warn " `ref_counter.jl` not found on main, assuming no comparable references"
80
- @info " Please review output results before merging."
86
+ # Short circuit if we don't find anything:
87
+ found_ref_counters =
88
+ filter (p -> isfile (joinpath (p, " ref_counter.jl" )), sorted_paths)
89
+ if isempty (found_ref_counters)
90
+ @warn " No reference counters found in paths: $sorted_paths "
81
91
return String[]
82
92
end
83
- @info " Found $(length (i_comparable_references)) comparable references:$i_comparable_references "
84
- # Largest ref-counter reference path:
85
- paths = map (i -> sorted_paths[i], i_comparable_references)
86
- @info " $(length (paths)) paths found:"
87
- for p in paths
88
- @info " $p , $(Dates. unix2datetime (stat (p). mtime)) "
93
+
94
+ # Find comparable paths
95
+ comparable_paths = String[]
96
+ @info " Reference counters found:"
97
+ for (i, path) in enumerate (sorted_paths)
98
+ ref_counter_file = joinpath (path, " ref_counter.jl" )
99
+ ! isfile (ref_counter_file) && continue
100
+ rc = read_ref_counter (ref_counter_file)
101
+ comparable = ref_counter_PR == rc
102
+ suffix = comparable ? " , comparable" : " "
103
+ @info " $path : $rc$suffix "
104
+ comparable && push! (comparable_paths, path)
89
105
end
90
- ref_counter_files_main = map (p -> joinpath (p, " ref_counter.jl" ), paths)
91
- @info " $(length (ref_counter_files_main)) reference counter paths on central"
92
- filter! (isfile, ref_counter_files_main)
93
- @info " $(length (ref_counter_files_main)) reference counter paths on central after filtering isfile"
94
-
95
- # for p in paths
96
- # @info "Files in $p:" # for debugging
97
- # for file_on_main in readdir(p)
98
- # @info " File:`$file_on_main`"
99
- # end
100
- # end
101
- @assert all (isfile, ref_counter_files_main)
102
- ref_counters_main = map (read_ref_counter, ref_counter_files_main)
103
- if all (rc -> ref_counter_PR == rc + 1 , ref_counters_main) # new reference
104
- @warn " `ref_counter.jl` incremented, assuming no comparable references"
105
- @info " Ref counters main: $ref_counters_main ."
106
- @info " Please review output results before merging."
106
+
107
+ if isempty (comparable_paths)
108
+ @warn " No comparable paths found in any of the paths:$sorted_paths "
107
109
return String[]
108
- elseif all (rc -> ref_counter_PR == rc, ref_counters_main) # unchanged reference
109
- @info " Ref counters main: $ref_counters_main ."
110
- @info " Comparing results against main path:$paths "
111
- else
112
- error (
113
- " Unexpected reference. Please open an issue pointing to this build." ,
114
- )
115
110
end
116
111
117
- paths = reverse (paths)[ 1 : min (n, length (paths))]
118
- @info " Limiting comparable paths to $n : "
119
- for p in paths
120
- @info " $p , $(Dates . unix2datetime ( stat (p) . mtime)) "
112
+ comparable_paths = reverse (comparable_paths) # sort so that
113
+
114
+ if length (comparable_paths) > n # limit to n comparable paths
115
+ comparable_paths = comparable_paths[ 1 : min (n, length (comparable_paths))]
121
116
end
122
- # Get the top 10 most recent paths to compare against:
123
- return paths
117
+
118
+ return comparable_paths
124
119
end
0 commit comments