Skip to content

Commit

Permalink
rework artifacts and add schema
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday committed Dec 2, 2022
1 parent 674663f commit 33f1a9e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Manifest.toml
*.log
*.tar
*.tar.gz
artifacts/
deps/plotly_artifacts*
notebooks/
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["joshday <[email protected]>"]
version = "0.5.2"

[deps]
ArtifactUtils = "8b73e784-e7d8-4ea5-973d-377fed4e3bce"
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Cobweb = "ec354790-cf28-43e8-bb59-b484409b7bad"
DefaultApplication = "3f0dd361-4fe0-5fc6-8523-80b14ec94d85"
Expand All @@ -15,10 +16,10 @@ StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"

[compat]
Cobweb = "0.1, 0.2"
StructTypes = "1"
DefaultApplication = "1"
EasyConfig = "0.1.10"
JSON3 = "1.8"
StructTypes = "1"
julia = "^1.6"

[extras]
Expand Down
1 change: 1 addition & 0 deletions deps/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
PlotlyLight = "ca7969ec-10b3-423e-8d99-40f33abb42bf"
Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
59 changes: 28 additions & 31 deletions deps/artifact_bundle.jl
Original file line number Diff line number Diff line change
@@ -1,56 +1,53 @@
using Pkg
Pkg.activate(@__DIR__)

using Downloads, Tar, ArtifactUtils, Artifacts, Dates, Pkg
using Downloads, Tar, ArtifactUtils, Artifacts, Dates, JSON3

#-----------------------------------------------------------------------------# Start from scratch
for file in readdir(@__DIR__)
if endswith(file, ".tar") || endswith(file, ".gz")
rm(joinpath(@__DIR__, file), force=true)
end
end
rm("plotlylight_artifacts.tar.gz", force=true)
dir = mkpath(joinpath(@__DIR__, "plotly_artifacts"))

#-----------------------------------------------------------------------------# Templates
# Need to install plotly.py in order to get themes because they are generated in python
# run(`conda create -n conda_jl python conda`)
# ENV["CONDA_JL_HOME"] = "/opt/homebrew/Caskroom/miniconda/base/envs/conda_jl"
# Pkg.build("Conda")
# using Conda
# Conda.add("plotly")

dir = "/opt/homebrew/Caskroom/miniconda/base/envs/conda_jl/pkgs"
templates = joinpath(dir, filter(x -> startswith(x, "plotly"), readdir(dir))[1], "site-packages/plotly/package_data/templates")


run(`gzip $(Tar.create(templates, joinpath(@__DIR__, "templates.tar")))`)

run(`conda env remove -n _plotly_artifacts`) # start from scratch
run(`conda create -n _plotly_artifacts -y`) # create env
run(`conda install -y plotly -n _plotly_artifacts`)

# get path of `_plotly_artifacts` env
io = IOBuffer()
# run(pipeline(`conda info --json`, stdout=io))
run(pipeline(`conda list -n _plotly_artifacts --json`; stdout=io))
pkgs = JSON3.read(String(take!(io)))
metadata = only(filter(x -> x.name == "plotly", pkgs))
template_dir = "/opt/homebrew/Caskroom/miniconda/base/pkgs/$(metadata.dist_name)/lib/python3.10/site-packages/plotly/package_data/templates/"
for file in readdir(template_dir)
cp(joinpath(template_dir, file), joinpath(dir, file))
end

#-----------------------------------------------------------------------------# Plotly.js
url = "https://cdn.plot.ly/plotly-2.14.0.min.js"
#-----------------------------------------------------------------------------# plotly.min.js
url = "https://cdn.plot.ly/plotly-2.16.1.min.js"
file = basename(url)
dir = mkpath(joinpath(@__DIR__, "plotlyjs"))
Downloads.download(url, joinpath(dir, file))

run(`gzip $(Tar.create(dir, joinpath(@__DIR__, "plotly.tar")))`)
#-----------------------------------------------------------------------------# schema
schema_url = "https://api.plot.ly/v2/plot-schema?format=json&sha1=%27%27"
Downloads.download(schema_url, joinpath(dir, "schema.json"))

#-----------------------------------------------------------------------------# tar it up
run(`gzip $(Tar.create(dir, joinpath(@__DIR__, "plotly_artifacts.tar")))`)

#-----------------------------------------------------------------------------# upload
try
artifacts_today = "artifacts_$(today())"

run(`gh release create $artifacts_today $(joinpath(@__DIR__, "templates.tar.gz")) $(joinpath(@__DIR__, "plotly.tar.gz")) --title $artifacts_today --notes ""`)
run(`gh release create $artifacts_today $(joinpath(@__DIR__, "plotly_artifacts.tar.gz")) --title $artifacts_today --notes ""`)

@info "Sleeping so artifacts are ready on GitHub..."
sleep(10)
add_artifact!(
"Artifacts.toml",
"plotly.min.js",
"https://github.com/joshday/PlotlyLight.jl/releases/download/$artifacts_today/plotly.tar.gz",
force=true,
)
add_artifact!(
"Artifacts.toml",
"plotly_templates",
"https://github.com/joshday/PlotlyLight.jl/releases/download/$artifacts_today/templates.tar.gz",
"plotlylight",
"https://github.com/joshday/PlotlyLight.jl/releases/download/$artifacts_today/plotly_artifacts.tar.gz",
force=true,
)
catch ex
Expand Down
5 changes: 3 additions & 2 deletions src/PlotlyLight.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ using Artifacts

export Plot, Config, collectrows

const cdn_url = "https://cdn.plot.ly/plotly-2.14.0.min.js"
const plotlyjs = joinpath(artifact"plotly.min.js", basename(cdn_url))
const cdn_url = "https://cdn.plot.ly/plotly-2.16.1.min.js"
const plotlyjs = joinpath(artifact"plotlylight", basename(cdn_url))
const schema = open(io -> JSON3.read(io), joinpath(artifact"plotlylight", "schema.json"))
const templates_dir = artifact"plotly_templates"
const templates = map(x -> replace(x, ".json" => ""), readdir(templates_dir))

Expand Down

0 comments on commit 33f1a9e

Please sign in to comment.