qiaojunfeng commited on
Commit
89221eb
·
1 Parent(s): 30820eb

Get old Artifacts.toml from deploy branch

Browse files
Files changed (2) hide show
  1. make_artifacts.jl +36 -9
  2. release.sh +1 -1
make_artifacts.jl CHANGED
@@ -19,8 +19,11 @@ const datasets_dir = joinpath(@__DIR__, "datasets")
19
  const deploy_branch = "artifacts"
20
 
21
  """
22
- folder: e.g. `"Si2"`
23
- local_url: use local file path for the url, for testing only
 
 
 
24
  """
25
  function create_artifact(folder::AbstractString; local_url::Bool = false)
26
  fullpath = joinpath(datasets_dir, folder)
@@ -92,16 +95,25 @@ function create_artifact(folder::AbstractString; local_url::Bool = false)
92
  return res
93
  end
94
 
 
 
 
95
  function git_hash(path::AbstractString; branch::AbstractString = "HEAD")
96
  return read(`git log -n 1 --pretty=format:"%H" $branch -- "$path"`, String)
97
  end
98
 
 
 
 
99
  function git_date(githash::AbstractString)
100
  # get the date of the commit, unix timestamp
101
  g = strip(read(`git show -s --format=%ct $githash`, String))
102
  return unix2datetime(parse(Float64, g))
103
  end
104
 
 
 
 
105
  function list_previous_artifacts()
106
  # if this command fails with the error
107
  # `fatal: Not a valid object name artifacts`
@@ -113,6 +125,10 @@ function list_previous_artifacts()
113
  return Dict(f => git_hash(f; branch = deploy_branch) for f in files)
114
  end
115
 
 
 
 
 
116
  function list_new_folders()
117
  prev_artifacts = list_previous_artifacts()
118
 
@@ -135,6 +151,9 @@ function list_new_folders()
135
  return new_folders
136
  end
137
 
 
 
 
138
  function clean_artifacts_dir()
139
  print("I will clean the `$(artifacts_dir)` folder [y/N]: ")
140
  n = readline()
@@ -148,13 +167,20 @@ function clean_artifacts_dir()
148
  return true
149
  end
150
 
151
- function (@main)(args)
152
- toml_path = joinpath(@__DIR__, "Artifacts.toml")
153
- if isfile(toml_path)
154
- artifacts = TOML.parsefile(toml_path)
155
- else
156
- artifacts = Dict{String,Any}()
 
 
 
157
  end
 
 
 
 
158
 
159
  new_folders = list_new_folders()
160
  if isempty(new_folders)
@@ -167,11 +193,12 @@ function (@main)(args)
167
 
168
  for folder in new_folders
169
  artifact = create_artifact(folder)
 
170
  push!(artifacts, artifact)
171
  # break
172
  end
173
 
174
- open(toml_path, "w") do io
175
  TOML.print(io, artifacts)
176
  end
177
  end
 
19
  const deploy_branch = "artifacts"
20
 
21
  """
22
+ Create a artifact tarball for a folder.
23
+
24
+ # Arguments
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)
 
95
  return res
96
  end
97
 
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
 
105
+ """
106
+ Get the date of a git commit.
107
+ """
108
  function git_date(githash::AbstractString)
109
  # get the date of the commit, unix timestamp
110
  g = strip(read(`git show -s --format=%ct $githash`, String))
111
  return unix2datetime(parse(Float64, g))
112
  end
113
 
114
+ """
115
+ Get list of artifact tarballs in the deploy branch.
116
+ """
117
  function list_previous_artifacts()
118
  # if this command fails with the error
119
  # `fatal: Not a valid object name artifacts`
 
125
  return Dict(f => git_hash(f; branch = deploy_branch) for f in files)
126
  end
127
 
128
+ """
129
+ Get folder names in `datasets/` that are newer than the corresponding
130
+ tarball.
131
+ """
132
  function list_new_folders()
133
  prev_artifacts = list_previous_artifacts()
134
 
 
151
  return new_folders
152
  end
153
 
154
+ """
155
+ Remove the `artifacts_dir` folder and create a new one.
156
+ """
157
  function clean_artifacts_dir()
158
  print("I will clean the `$(artifacts_dir)` folder [y/N]: ")
159
  n = readline()
 
167
  return true
168
  end
169
 
170
+ """
171
+ Get previous Artifacts.toml from deploy branch.
172
+ """
173
+ function read_artifact_toml()
174
+ return try
175
+ content = read(`git show $deploy_branch:Artifacts.toml`)
176
+ return TOML.parse(String(content))
177
+ catch e
178
+ return Dict{String,Any}()
179
  end
180
+ end
181
+
182
+ function (@main)(args)
183
+ artifacts = read_artifact_toml()
184
 
185
  new_folders = list_new_folders()
186
  if isempty(new_folders)
 
193
 
194
  for folder in new_folders
195
  artifact = create_artifact(folder)
196
+ # existing entries will be replaced
197
  push!(artifacts, artifact)
198
  # break
199
  end
200
 
201
+ open("Artifacts.toml", "w") do io
202
  TOML.print(io, artifacts)
203
  end
204
  end
release.sh CHANGED
@@ -80,4 +80,4 @@ git fetch origin $DEPLOY_BRANCH:$DEPLOY_BRANCH
80
  echo "\n\n\n" # Add some newlines for readability
81
  echo "Upload complete. Checking results at"
82
  echo "https://huggingface.co/datasets/atomology/WannierDatasets/tree/$DEPLOY_BRANCH"
83
- echo "https://huggingface.co/datasets/atomology/WannierDatasets/main/Artifacts.toml"
 
80
  echo "\n\n\n" # Add some newlines for readability
81
  echo "Upload complete. Checking results at"
82
  echo "https://huggingface.co/datasets/atomology/WannierDatasets/tree/$DEPLOY_BRANCH"
83
+ echo "https://huggingface.co/datasets/atomology/WannierDatasets/blob/$DEPLOY_BRANCH/Artifacts.toml"