View Source OctoFetch (OctoFetch v0.4.0)
This library allows you to download release artifacts from GitHub. By using this library you get the following functionality for your GitHub downloader client:
- Automatic SHA validation for downloaded artifacts (security measure to ensure that users download valid copies of artifacts)
- Automatic archive extraction for
.zip
and.tar.gz
downloads - Dynamic artifact downloading based on user's platform
- Support only specific versions of artifacts from the provided repo
Sample usage
If you want to make a downloader for the Litestream binary for example, you can define a downloader module like so:
defmodule LiteStream.Downloader do
use OctoFetch,
latest_version: "0.3.9",
github_repo: "benbjohnson/litestream",
download_versions: %{
"0.3.9" => [
{:darwin, :amd64, "74599a34dc440c19544f533be2ef14cd4378ec1969b9b4fcfd24158946541869"},
{:linux, :amd64, "806e1cca4a2a105a36f219a4c212a220569d50a8f13f45f38ebe49e6699ab99f"},
{:linux, :arm64, "61acea9d960633f6df514972688c47fa26979fbdb5b4e81ebc42f4904394c5c5"}
],
"0.3.8" => [
{:darwin, :amd64, "d359a4edd1cb98f59a1a7c787bbd0ed30c6cc3126b02deb05a0ca501ff94a46a"},
{:linux, :amd64, "530723d95a51ee180e29b8eba9fee8ddafc80a01cab7965290fb6d6fc31381b3"},
{:linux, :arm64, "1d6fb542c65b7b8bf91c8859d99f2f48b0b3251cc201341281f8f2c686dd81e2"}
]
}
# You must implement this function to generate the names of the downloads based on the
# user's current running environment
@impl true
def download_name(version, :darwin, arch), do: "litestream-v#{version}-darwin-#{arch}.zip"
def download_name(version, :linux, arch), do: "litestream-v#{version}-linux-#{arch}.tar.gz"
end
You would then be able to download the release artifact by doing the following:
Litestream.Downloader.download(".")
If you are on an ARM based Mac, the above snippet won't work since Litestream does not currently build ARM artifacts. But you can always override what OctoFetch dynamically resolves by doing the following:
Litestream.Downloader.download(".", override_architecture: :amd64)
Be sure to look at the OctoFetch.download/3
docs for supported options and
OctoFetch.Downloader
to see what behaviour callbacks you can override.
Summary
Functions
Download the GitHub release artifact and write it to the specified location.
Functions
@spec download( downloader_module :: module(), output_dir :: String.t(), opts :: Keyword.t() ) :: OctoFetch.Downloader.download_result()
Download the GitHub release artifact and write it to the specified location.
The supported opts
arguments are:
override_version
: By default, the latest version (as specified by the downloader module) will be downloaded. But you can also specify any additional versions that are also supported by the:download_versions
map.override_operating_system
: By default, the operating system is dynamically deteremined based on the what the BEAM reports. If you would like to override those results, you can pass:windows
,:darwin
, or:linux
.override_architecture
: By default, the architecture is dynamically deteremined based on the what the BEAM reports. If you would like to override those results, you can pass:amd64
or:arm64
.