qiaojunfeng commited on
Commit
250618e
·
1 Parent(s): 0a32404

Clean up make_artifacts.jl

Browse files
Files changed (4) hide show
  1. .gitignore +3 -0
  2. docs/CONTRIBUTING.md +14 -0
  3. docs/GitHub_actions.md +0 -30
  4. make_artifacts.jl +42 -25
.gitignore CHANGED
@@ -26,3 +26,6 @@ Manifest.toml
26
  # Do not commit large (and redundant) tar.gz files, instead, I upload them
27
  # to the `artifacts` branch
28
  artifacts/*.tar.gz
 
 
 
 
26
  # Do not commit large (and redundant) tar.gz files, instead, I upload them
27
  # to the `artifacts` branch
28
  artifacts/*.tar.gz
29
+
30
+ # vscode
31
+ .vscode
docs/CONTRIBUTING.md CHANGED
@@ -54,3 +54,17 @@ We actively welcome your pull requests:
54
  we can merge your PR without ugly :worried: merge commits.
55
  Otherwise, we will rebase explicitly your branch when merging.
56
  6. Create that pull request!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  we can merge your PR without ugly :worried: merge commits.
55
  Otherwise, we will rebase explicitly your branch when merging.
56
  6. Create that pull request!
57
+
58
+ ## Release process
59
+
60
+ ```shell
61
+ # make tarballs
62
+ ./make_artifacts.jl
63
+
64
+ # upload tarballs to huggingface `artifacts` branch, see the output of `make_artifacts.jl`
65
+ huggingface-cli upload # ...
66
+
67
+ # auto bump the version & create git tag with release-it
68
+ # https://github.com/release-it/release-it
69
+ release-it --no-push
70
+ ```
docs/GitHub_actions.md DELETED
@@ -1,30 +0,0 @@
1
- # Notes on GitHub Actions
2
-
3
- ## Release process
4
-
5
- The current process of bumping version is:
6
-
7
- - create a branch, since the `main` branch is protected.
8
- The branch name can be `bumpversion`.
9
- - use `bump2version (major|minor|patch)` to update
10
- `.bumpversion.cfg` and `Project.toml`, and it will create a git commit
11
- - create a PR
12
- - the release workflow will run, it will
13
- - build the artifact tarballs
14
- - commit `Artifacts.toml`
15
- - create a draft release, with tarballs attached
16
- - check if the version in `Project.toml` is consistent with that suggested
17
- by the `release-drafter` workflow, and if not, add a comment to the PR
18
- - once the PR is merged, publish the draft release, and it will create
19
- a git tag pointing to main (thus including the just merged PR)
20
-
21
- In the end, we have:
22
-
23
- - a new version git tagged
24
- - an `Artifacts.toml` with updated tarball SHA
25
- - a GitHub release with tarballs attached
26
- - the version in `Project.toml` is consistent with the git tag
27
-
28
- ## Debugging
29
-
30
- - to debug github workflows, set `ACTIONS_STEP_DEBUG` to `true` in secrets
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
make_artifacts.jl CHANGED
@@ -11,14 +11,15 @@
11
  using Tar, Inflate, SHA, TOML
12
  using Dates: unix2datetime
13
 
 
 
 
 
14
  """
15
  folder: e.g. `"Si2"`
16
  local_url: use local file path for the url, for testing only
17
  """
18
  function create_artifact(folder::AbstractString; local_url::Bool=false)
19
- artifacts_dir = joinpath(@__DIR__, "artifacts")
20
- datasets_dir = joinpath(@__DIR__, "datasets")
21
-
22
  fullpath = joinpath(datasets_dir, folder)
23
  isdir(fullpath) || return
24
 
@@ -71,12 +72,20 @@ function create_artifact(folder::AbstractString; local_url::Bool=false)
71
  end
72
 
73
  artifact_name = folder
74
- return artifact_name => Dict(
75
  "git-tree-sha1" => Tar.tree_hash(IOBuffer(inflate_gzip(outpath))),
76
  "lazy" => true,
77
  "download" =>
78
  [Dict("url" => url, "sha256" => bytes2hex(open(sha256, outpath)))],
79
  )
 
 
 
 
 
 
 
 
80
  end
81
 
82
  function git_hash(path::AbstractString; branch::AbstractString="HEAD")
@@ -90,15 +99,12 @@ function git_date(githash::AbstractString)
90
  end
91
 
92
  function list_previous_artifacts()
93
- branch = "artifacts"
94
- files = split(read(`git ls-tree -r --name-only $branch`, String))
95
  filter!(f -> endswith(f, ".tar.gz"), files)
96
- return Dict(f => git_hash(f; branch) for f in files)
97
  end
98
 
99
  function list_new_folders()
100
- datasets_dir = joinpath(@__DIR__, "datasets")
101
-
102
  prev_artifacts = list_previous_artifacts()
103
 
104
  new_folders = String[]
@@ -122,14 +128,26 @@ end
122
 
123
  function upload_artifacts(names::AbstractVector)
124
  paths = map(names) do name
125
- joinpath(@__DIR__, "artifacts", "$(name).tar.gz")
126
  end
127
- paths
 
128
  end
129
 
130
- function (@main)(args)
131
- new_folders = list_new_folders()
 
 
 
 
 
 
 
 
 
 
132
 
 
133
  toml_path = joinpath(@__DIR__, "Artifacts.toml")
134
  if isfile(toml_path)
135
  artifacts = TOML.parsefile(toml_path)
@@ -137,21 +155,20 @@ function (@main)(args)
137
  artifacts = Dict{String, Any}()
138
  end
139
 
140
- for folder in new_folders
141
- artifact = create_artifact(folder)
142
 
143
- # print the result as toml
144
- buf = IOBuffer()
145
- TOML.print(buf, Dict(artifact))
146
- s = String(take!(buf))
147
- @info "New artifact:\n$s"
148
 
149
- push!(artifacts, artifact)
150
- break
151
- end
 
 
152
 
153
- open(toml_path, "w") do io
154
- TOML.print(io, artifacts)
 
155
  end
156
 
157
  upload_artifacts(new_folders)
 
11
  using Tar, Inflate, SHA, TOML
12
  using Dates: unix2datetime
13
 
14
+ const artifacts_dir = joinpath(@__DIR__, "artifacts")
15
+ const datasets_dir = joinpath(@__DIR__, "datasets")
16
+ const deploy_branch = "artifacts"
17
+
18
  """
19
  folder: e.g. `"Si2"`
20
  local_url: use local file path for the url, for testing only
21
  """
22
  function create_artifact(folder::AbstractString; local_url::Bool=false)
 
 
 
23
  fullpath = joinpath(datasets_dir, folder)
24
  isdir(fullpath) || return
25
 
 
72
  end
73
 
74
  artifact_name = folder
75
+ res = artifact_name => Dict(
76
  "git-tree-sha1" => Tar.tree_hash(IOBuffer(inflate_gzip(outpath))),
77
  "lazy" => true,
78
  "download" =>
79
  [Dict("url" => url, "sha256" => bytes2hex(open(sha256, outpath)))],
80
  )
81
+
82
+ # print the result as toml
83
+ buf = IOBuffer()
84
+ TOML.print(buf, Dict(res))
85
+ s = String(take!(buf))
86
+ @info "New artifact:\n$s"
87
+
88
+ return res
89
  end
90
 
91
  function git_hash(path::AbstractString; branch::AbstractString="HEAD")
 
99
  end
100
 
101
  function list_previous_artifacts()
102
+ files = split(read(`git ls-tree -r --name-only $deploy_branch`, String))
 
103
  filter!(f -> endswith(f, ".tar.gz"), files)
104
+ return Dict(f => git_hash(f; deploy_branch) for f in files)
105
  end
106
 
107
  function list_new_folders()
 
 
108
  prev_artifacts = list_previous_artifacts()
109
 
110
  new_folders = String[]
 
128
 
129
  function upload_artifacts(names::AbstractVector)
130
  paths = map(names) do name
131
+ joinpath(artifacts_dir, "$(name).tar.gz")
132
  end
133
+ println("huggingface-cli upload --repo-type dataset --revision $deploy_branch atomology/WannierDatasets \\")
134
+ println(join(paths, " \\\n"))
135
  end
136
 
137
+ function clean_artifacts_dir()
138
+ print("I will clean the `$(artifacts_dir)` folder [y/N]: ")
139
+ n = readline()
140
+ if lowercase(n) != "y"
141
+ println("Aborting...")
142
+ return false
143
+ end
144
+ rm(artifacts_dir; force=true, recurive=true)
145
+ mkpath(artifacts_dir)
146
+ println("Cleaned `$(artifacts_dir)` folder.")
147
+ return true
148
+ end
149
 
150
+ function (@main)(args)
151
  toml_path = joinpath(@__DIR__, "Artifacts.toml")
152
  if isfile(toml_path)
153
  artifacts = TOML.parsefile(toml_path)
 
155
  artifacts = Dict{String, Any}()
156
  end
157
 
158
+ new_folders = list_new_folders()
 
159
 
160
+ if length(args) > 0 && args[1] != "dryrun"
161
+ clean_artifacts_dir() || return
 
 
 
162
 
163
+ for folder in new_folders
164
+ artifact = create_artifact(folder)
165
+ push!(artifacts, artifact)
166
+ # break
167
+ end
168
 
169
+ open(toml_path, "w") do io
170
+ TOML.print(io, artifacts)
171
+ end
172
  end
173
 
174
  upload_artifacts(new_folders)