From df4c9b4ae96afa7d8e7e44dbefc9e5035c3666db Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 30 Jun 2023 11:02:20 +0200 Subject: [PATCH] Check the latest version from the LATEST text file --- Rakefile | 5 +++-- lib/up2date.rb | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 7676d38..dacfa36 100644 --- a/Rakefile +++ b/Rakefile @@ -147,11 +147,12 @@ AUTO_UPDATABLE = { 'php82' => SlackBuilder::GitHub.new('php', 'php-src', php_transform), 'rdiff-backup' => SlackBuilder::GitHub.new('rdiff-backup', 'rdiff-backup'), 'librsync' => SlackBuilder::GitHub.new('librsync', 'librsync'), - 'jitsi-meet-desktop' => SlackBuilder::GitHub.new('jitsi', 'jitsi-meet-electron') + 'jitsi-meet-desktop' => SlackBuilder::GitHub.new('jitsi', 'jitsi-meet-electron'), + 'dmd' => SlackBuilder::LatestText.new('https://downloads.dlang.org/releases/LATEST') }.freeze task :up2date do AUTO_UPDATABLE.each do |key, value| - latest_version = SlackBuilder.check_for_latest key, value + SlackBuilder.check_for_latest key, value end end diff --git a/lib/up2date.rb b/lib/up2date.rb index f68a1fc..3387941 100644 --- a/lib/up2date.rb +++ b/lib/up2date.rb @@ -20,6 +20,7 @@ module SlackBuilder end end + # Reads the list fo tags from the GitHub API. class GitHub < Repository GITHUB_QUERY = <<~GQL query ($name: String!, $owner: String!) { @@ -66,6 +67,7 @@ module SlackBuilder end end + # Request the latest version from the packagist API. class Packagist < Repository def initialize(vendor, name) super() @@ -74,7 +76,6 @@ module SlackBuilder @name = name end - # Request the latest version from the packagist API. def latest full_name = [@vendor, @name].join '/' uri = URI "https://repo.packagist.org/p2/#{full_name}.json" @@ -85,6 +86,22 @@ module SlackBuilder end end + # Reads a remote LATEST file. + class LatestText < Repository + def initialize(latest_url) + super() + + @latest_url = URI latest_url + end + + def latest + response = Net::HTTP.get @latest_url, { + 'content-type' => 'text/plain' + } + response.strip + end + end + module_function # Checks if there is a new version for the package and returns the latest