Add task to check sqlean extensions version
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
defmodule Mix.Tasks.Sqlean.CheckVersion do
|
||||
@shortdoc "Checks the the current Sqlean extensions version is the latest"
|
||||
@moduledoc """
|
||||
Checks the the current Sqlean extensions version is the latest.
|
||||
|
||||
Exits with 0 if versions match, 1 if the extensions needs to be updated.
|
||||
"""
|
||||
|
||||
use Mix.Task
|
||||
|
||||
alias Mix.Tasks.Sqlean.Release
|
||||
|
||||
@impl Mix.Task
|
||||
def run(_args) do
|
||||
current_version =
|
||||
Release.fetch_current_version()
|
||||
|
||||
latest_version =
|
||||
Release.fetch_latest_version!()
|
||||
|
||||
if current_version === latest_version do
|
||||
Mix.Shell.IO.info("The sqlean extensions version is up to date (#{current_version})")
|
||||
else
|
||||
Mix.Shell.IO.info(
|
||||
"A new sqlean extensions version is available: #{current_version} ==> #{latest_version}"
|
||||
)
|
||||
|
||||
System.halt(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,36 @@
|
||||
defmodule Mix.Tasks.Sqlean.Release do
|
||||
@latest_version_url "https://raw.githubusercontent.com/nalgeon/sqlean/refs/heads/main/sqlpkg.json"
|
||||
|
||||
def fetch_latest_version! do
|
||||
Application.ensure_all_started(:req)
|
||||
|
||||
@latest_version_url
|
||||
|> Req.get!()
|
||||
|> Map.get(:body)
|
||||
|> JSON.decode!()
|
||||
|> Map.get("version")
|
||||
end
|
||||
|
||||
def fetch_current_version do
|
||||
Application.app_dir(:music_library, [
|
||||
"priv",
|
||||
"sqlite_extensions",
|
||||
"VERSION"
|
||||
])
|
||||
|> File.read!()
|
||||
|> String.trim()
|
||||
end
|
||||
|
||||
def update_config_file!(config_file, current_version, latest_version) do
|
||||
config_contents = File.read!(config_file)
|
||||
|
||||
new_config_contents =
|
||||
String.replace(
|
||||
config_contents,
|
||||
~s(version: "#{current_version}"),
|
||||
"version: \"#{latest_version}\""
|
||||
)
|
||||
|
||||
File.write!(config_file, new_config_contents)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1 @@
|
||||
0.28.0
|
||||
Reference in New Issue
Block a user