-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from LosEagle/config
Add config file support and production build setup
- Loading branch information
Showing
9 changed files
with
88 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ freetube_updater-*.tar | |
|
||
# Temporary files for e.g. tests | ||
/tmp | ||
|
||
config/config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"token": "", | ||
"os": "", | ||
"format": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,38 @@ | ||
defmodule FreeTubeUpdater do | ||
def get_download_link(token, os, format) do | ||
@env Mix.env() | ||
|
||
def env, do: @env | ||
|
||
def get_download_link() do | ||
config_path = | ||
case FreeTubeUpdater.env() do | ||
:dev -> File.cwd!() <> "/config/config.json" | ||
:prod -> File.cwd!() <> "/rel/freetube_updater/config/config.json" | ||
end | ||
|
||
config = FreeTubeUpdater.Config.parse!(config_path) | ||
|
||
nightly_artifact_url = "https://api.github.com/repos/freetubeapp/freetube/actions/artifacts" | ||
|
||
nightly_artifacts = FreeTubeUpdater.GithubApiHandler.send_authenticated_request(nightly_artifact_url, token) | ||
|> FreeTubeUpdater.GithubApiHandler.get_response_body | ||
|> get_in(["artifacts"]) | ||
nightly_artifacts = | ||
FreeTubeUpdater.GithubApiHandler.send_authenticated_request( | ||
nightly_artifact_url, | ||
config["token"] | ||
) | ||
|> FreeTubeUpdater.GithubApiHandler.get_response_body() | ||
|> get_in(["artifacts"]) | ||
|
||
download_link = | ||
nightly_artifacts | ||
|> FreeTubeUpdater.ArtifactParser.get_artifact(config["os"], config["format"]) | ||
|> get_in(["archive_download_url"]) | ||
|> FreeTubeUpdater.GithubApiHandler.send_authenticated_request(config["token"]) | ||
|> FreeTubeUpdater.GithubApiHandler.get_response_headers() | ||
|> Enum.filter(fn {key, _value} -> key === "Location" end) | ||
|> Enum.at(0) | ||
|> Tuple.to_list() | ||
|> Enum.at(1) | ||
|
||
nightly_artifacts | ||
|> FreeTubeUpdater.ArtifactParser.get_artifact(os, format) | ||
|> get_in(["archive_download_url"]) | ||
|> FreeTubeUpdater.GithubApiHandler.send_authenticated_request(token) | ||
|> FreeTubeUpdater.GithubApiHandler.get_response_headers | ||
|> Enum.filter(fn ({ key, _value }) -> key === "Location" end) | ||
|> Enum.at(0) | ||
|> Tuple.to_list | ||
|> Enum.at(1) | ||
{":ok", download_link} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
defmodule FreeTubeUpdater.ArtifactParser do | ||
def get_artifact(artifacts, os, format) do | ||
patterns = %{ | ||
win: %{ | ||
setup: ~r/setup-x64.exe/, | ||
portable: ~r/portable-x64.exe/, | ||
}, | ||
linux: %{ | ||
portable: ~r/linux_portable_x64/, | ||
AppImage: ~r/amd64.AppImage/, | ||
}, | ||
mac: %{ | ||
dmg: ~r/mac.dmg/ | ||
} | ||
} | ||
|
||
Enum.find(artifacts, &(String.match?(&1["name"], get_in(patterns, [String.to_atom(os), String.to_atom(format)])))) | ||
end | ||
end | ||
defmodule FreeTubeUpdater.ArtifactParser do | ||
def get_artifact(artifacts, os, format) do | ||
patterns = %{ | ||
win: %{ | ||
setup: ~r/setup-x64.exe/, | ||
portable: ~r/portable-x64.exe/ | ||
}, | ||
linux: %{ | ||
portable: ~r/linux_portable_x64/, | ||
AppImage: ~r/amd64.AppImage/ | ||
}, | ||
mac: %{ | ||
dmg: ~r/mac.dmg/ | ||
} | ||
} | ||
|
||
Enum.find( | ||
artifacts, | ||
&String.match?(&1["name"], get_in(patterns, [String.to_atom(os), String.to_atom(format)])) | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule FreeTubeUpdater.Config do | ||
def parse!(path) do | ||
File.read!(path) | ||
|> Poison.decode!() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters