2021-12-04 23:42:54 +01:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
# [For package maintainers]
|
|
|
|
# Edit the conf/app.src files with the latest commit
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# ./bump-version.rb
|
|
|
|
|
|
|
|
require 'digest'
|
|
|
|
require 'json'
|
|
|
|
require 'open-uri'
|
|
|
|
|
|
|
|
module Yunohost
|
|
|
|
class AppSrcFile
|
|
|
|
def initialize(path = 'conf/app.src')
|
|
|
|
@path = path
|
|
|
|
end
|
|
|
|
|
|
|
|
def update(url, sum)
|
|
|
|
src = File.read(@path)
|
|
|
|
replace_src_setting!(src, 'SOURCE_URL', url)
|
|
|
|
replace_src_setting!(src, 'SOURCE_SUM', sum)
|
|
|
|
replace_src_setting!(src, 'SOURCE_FILENAME', File.basename(URI.parse(url).path))
|
|
|
|
File.write(@path, src)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def replace_src_setting!(str, setting, value)
|
|
|
|
str.gsub!(/^#{setting}=.*$/, "#{setting}=#{value}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ManifestFile
|
|
|
|
def initialize(path = 'manifest.json')
|
|
|
|
@path = path
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_with_version(version)
|
|
|
|
manifest_file = File.read(@path)
|
|
|
|
manifest = JSON.parse(manifest_file)
|
|
|
|
|
|
|
|
if manifest['version'].start_with? version
|
|
|
|
i = manifest['version'].scan(/~ynh(\d)/).flatten.first.to_i + 1
|
|
|
|
manifest['version'] = "#{version}~ynh#{i}"
|
|
|
|
else
|
|
|
|
manifest['version'] = "#{version}~ynh1"
|
|
|
|
end
|
|
|
|
|
|
|
|
manifest_file = JSON.pretty_generate(manifest, indent: ' ') + "\n"
|
|
|
|
File.write(@path, manifest_file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-29 19:43:52 +01:00
|
|
|
github = JSON.parse(URI.parse('https://api.github.com/repos/magicstone-dev/acropolis/branches/main').read)
|
2021-12-04 23:42:54 +01:00
|
|
|
last_commit = github["commit"]["sha"]
|
|
|
|
version = Date.parse(github["commit"]["commit"]["author"]["date"]).to_s.gsub '-', '.'
|
|
|
|
|
2021-12-29 19:43:52 +01:00
|
|
|
url = "https://github.com/magicstone-dev/acropolis/archive/#{last_commit}.tar.gz"
|
2021-12-04 23:42:54 +01:00
|
|
|
|
|
|
|
puts "Downloading last commit at #{url}"
|
|
|
|
release_file = URI.parse(url).read
|
|
|
|
sum = Digest::SHA256.hexdigest(release_file)
|
|
|
|
|
|
|
|
# Update source file
|
|
|
|
Yunohost::AppSrcFile.new().update(url, sum)
|
|
|
|
|
|
|
|
# Update manifest file
|
|
|
|
Yunohost::ManifestFile.new().update_with_version(version)
|
|
|
|
|
2021-12-29 19:43:52 +01:00
|
|
|
puts "Done!"
|