Commit ·
2d50f81
1
Parent(s): 51a6208
Only check git committed datasets
Browse files- make_artifacts.jl +29 -6
make_artifacts.jl
CHANGED
|
@@ -25,7 +25,7 @@ Create a artifact tarball for a folder.
|
|
| 25 |
- `folder`: subfolders in `datasets/` folder, e.g. `"Si2"`
|
| 26 |
- `local_url`: use local file path for the url, for testing only
|
| 27 |
"""
|
| 28 |
-
function create_artifact(folder::AbstractString; local_url::Bool
|
| 29 |
fullpath = joinpath(datasets_dir, folder)
|
| 30 |
isdir(fullpath) || return
|
| 31 |
|
|
@@ -98,7 +98,7 @@ end
|
|
| 98 |
"""
|
| 99 |
Get the git hash of the latest commit of a file.
|
| 100 |
"""
|
| 101 |
-
function git_hash(path::AbstractString; branch::AbstractString
|
| 102 |
return read(`git log -n 1 --pretty=format:"%H" $branch -- "$path"`, String)
|
| 103 |
end
|
| 104 |
|
|
@@ -111,6 +111,16 @@ function git_date(githash::AbstractString)
|
|
| 111 |
return unix2datetime(parse(Float64, g))
|
| 112 |
end
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
"""
|
| 115 |
Get list of artifact tarballs in the deploy branch.
|
| 116 |
"""
|
|
@@ -120,9 +130,16 @@ function list_previous_artifacts()
|
|
| 120 |
# you need to run at least once
|
| 121 |
# `git checkout artifacts`
|
| 122 |
# to create the artifacts branch
|
| 123 |
-
files =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
filter!(f -> endswith(f, ".tar.gz"), files)
|
| 125 |
-
return Dict(f => git_hash(f; branch
|
| 126 |
end
|
| 127 |
|
| 128 |
"""
|
|
@@ -133,7 +150,13 @@ function list_new_folders()
|
|
| 133 |
prev_artifacts = list_previous_artifacts()
|
| 134 |
|
| 135 |
new_folders = String[]
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
startswith(data, "_") && continue
|
| 138 |
startswith(data, ".") && continue
|
| 139 |
isdir(joinpath(datasets_dir, data)) || continue
|
|
@@ -161,7 +184,7 @@ function clean_artifacts_dir()
|
|
| 161 |
println("Aborting...")
|
| 162 |
return false
|
| 163 |
end
|
| 164 |
-
rm(artifacts_dir; force
|
| 165 |
mkpath(artifacts_dir)
|
| 166 |
println("Cleaned `$(artifacts_dir)` folder.")
|
| 167 |
return true
|
|
|
|
| 25 |
- `folder`: subfolders in `datasets/` folder, e.g. `"Si2"`
|
| 26 |
- `local_url`: use local file path for the url, for testing only
|
| 27 |
"""
|
| 28 |
+
function create_artifact(folder::AbstractString; local_url::Bool=false)
|
| 29 |
fullpath = joinpath(datasets_dir, folder)
|
| 30 |
isdir(fullpath) || return
|
| 31 |
|
|
|
|
| 98 |
"""
|
| 99 |
Get the git hash of the latest commit of a file.
|
| 100 |
"""
|
| 101 |
+
function git_hash(path::AbstractString; branch::AbstractString="HEAD")
|
| 102 |
return read(`git log -n 1 --pretty=format:"%H" $branch -- "$path"`, String)
|
| 103 |
end
|
| 104 |
|
|
|
|
| 111 |
return unix2datetime(parse(Float64, g))
|
| 112 |
end
|
| 113 |
|
| 114 |
+
"""
|
| 115 |
+
Get the list of files in a git tree.
|
| 116 |
+
"""
|
| 117 |
+
function git_lstree(path::AbstractString; args::AbstractVector{<:AbstractString}=String[], branch::AbstractString="HEAD")
|
| 118 |
+
cmd = `git ls-tree $args --name-only $branch -- "$path"`
|
| 119 |
+
output = chomp(read(cmd, String))
|
| 120 |
+
isempty(output) && return String[]
|
| 121 |
+
return split(output, '\n')
|
| 122 |
+
end
|
| 123 |
+
|
| 124 |
"""
|
| 125 |
Get list of artifact tarballs in the deploy branch.
|
| 126 |
"""
|
|
|
|
| 130 |
# you need to run at least once
|
| 131 |
# `git checkout artifacts`
|
| 132 |
# to create the artifacts branch
|
| 133 |
+
files = try
|
| 134 |
+
git_lstree("."; args=["-r"], branch=deploy_branch)
|
| 135 |
+
catch e
|
| 136 |
+
@warn "Failed to list previous artifacts, perhaps you need to run \
|
| 137 |
+
`git checkout artifacts` at least once to create the branch?"
|
| 138 |
+
throw(e)
|
| 139 |
+
String[]
|
| 140 |
+
end
|
| 141 |
filter!(f -> endswith(f, ".tar.gz"), files)
|
| 142 |
+
return Dict(f => git_hash(f; branch=deploy_branch) for f in files)
|
| 143 |
end
|
| 144 |
|
| 145 |
"""
|
|
|
|
| 150 |
prev_artifacts = list_previous_artifacts()
|
| 151 |
|
| 152 |
new_folders = String[]
|
| 153 |
+
# This include all the folders in `datasets/`
|
| 154 |
+
# dirs = readdir(datasets_dir)
|
| 155 |
+
# This only include the folders that have been git committed to the main branch
|
| 156 |
+
# Note it needs exactly the `datasets/` as path: not abosulute path, with
|
| 157 |
+
# trailing slash to list subfolders.
|
| 158 |
+
dirs = map(basename, git_lstree(basename(datasets_dir) * "/"; branch="main"))
|
| 159 |
+
for data in dirs
|
| 160 |
startswith(data, "_") && continue
|
| 161 |
startswith(data, ".") && continue
|
| 162 |
isdir(joinpath(datasets_dir, data)) || continue
|
|
|
|
| 184 |
println("Aborting...")
|
| 185 |
return false
|
| 186 |
end
|
| 187 |
+
rm(artifacts_dir; force=true, recursive=true)
|
| 188 |
mkpath(artifacts_dir)
|
| 189 |
println("Cleaned `$(artifacts_dir)` folder.")
|
| 190 |
return true
|