Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
Add release script for artifact.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHatherly committed May 16, 2021
1 parent 4601024 commit 3c832a8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Artifacts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
git-tree-sha1 = "a74800f299f6bdade309e459b999442f303aa64d"

[[assets.download]]
sha256 = "7ccfd273ff2ac996059d9019ff317202bdc69aef394fe450be557df9aae81733"
sha256 = "aa8d3e891da5c0757620f0bad9f9cd78e2e843bbc31773b5759e4f54e4f92b2b"
url = "https://github.com/JuliaPlots/AbstractPlotting.jl/releases/download/assets-0.1.0/assets-0.1.0.tar.gz"
74 changes: 52 additions & 22 deletions artifacts.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,63 @@
# Artifact generator for the assets directory.
#
# Requires:
#
# - A github token stored in `ENV["GITHUB_AUTH"]` with access to `repo` read/write.
# - Extra packages: `ghr_jll` for release uploading.
#
# Usage:
#
# - Update files in `/assets` directory.
# - Bump the `version` variable below.
# - Run `rebuild_artifacts()` to create new tarball and update Artifacts.toml.
# - Commit the changes.
# - Run `release_artifacts()` to create a new release and upload the new tarball.
#

using Pkg.Artifacts
using URIs
using ghr_jll
using LibGit2

version = v"0.1.0"
host = "https://github.com/JuliaPlots/AbstractPlotting.jl/releases/download"
user = "JuliaPlots"
repo = "AbstractPlotting.jl"
host = "https://github.com/$user/$repo/releases/download"

build_path = joinpath(@__DIR__, "build")
assets_path = joinpath(@__DIR__, "assets")
artifact_toml = joinpath(@__DIR__, "Artifacts.toml")

function rebuild_artifacts()
ispath(build_path) && rm(build_path, force=true, recursive=true)
mkpath(build_path)

product_hash = create_artifact() do artifact_dir
cp(assets_path, artifact_dir; force = true)
end

ispath(build_path) && rm(build_path, force=true, recursive=true)
mkpath(build_path)
archive_filename = "assets-$version.tar.gz"
download_hash = archive_artifact(product_hash, joinpath(build_path, archive_filename))

product_hash = create_artifact() do artifact_dir
cp(joinpath(@__DIR__, "assets"), artifact_dir; force = true)
bind_artifact!(
artifact_toml,
"assets",
product_hash,
force = true,
download_info = Tuple[
(
"$host/assets-$version/$archive_filename",
download_hash,
),
],
)
end

archive_filename = "assets-$version.tar.gz"
artifact_toml = joinpath(@__DIR__, "Artifacts.toml")
download_hash = archive_artifact(product_hash, joinpath(build_path, archive_filename))

bind_artifact!(
artifact_toml,
"assets",
product_hash,
force = true,
download_info = Tuple[
(
"$host/assets-$(escapeuri(string(version)))/$archive_filename",
download_hash,
),
],
)
function release_artifacts()
name = "Release assets $(version)"
commit = string(LibGit2.GitHash(LibGit2.GitCommit(LibGit2.GitRepo(@__DIR__), "HEAD")))
token = ENV["GITHUB_AUTH"]
tag = "assets-$version"
ghr() do bin
run(`$bin -u $user -r $repo -n $name -c $commit -t $token $tag $build_path`)
end
end

0 comments on commit 3c832a8

Please sign in to comment.