Created
July 11, 2016 15:01
-
-
Save taku0/1c35ef1683bafc65ec63379dc331e6a8 to your computer and use it in GitHub Desktop.
Experimental semi-auto updater for firefox-bin package in nixpkgs
This file contains hidden or 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
$nixpkgs_dir = File.expand_path("~/src/nixpkgs") | |
def git(*arguments) | |
options = if arguments.last.kind_of? Hash | |
options = arguments.pop | |
else | |
{} | |
end | |
nixpkgs_dir = if options.include?(:nixpkgs_dir) | |
options[:nixpkgs_dir] | |
else | |
$nixpkgs_dir | |
end | |
puts((["git", "-C", nixpkgs_dir] + arguments).join(" ")) | |
output = IO.popen(["git", "-C", nixpkgs_dir] + arguments) do |io| | |
io.read | |
end | |
if not $?.success? | |
fail | |
end | |
output | |
end | |
def create_new_branch_at_new_worktree(new_branch_name, worktree_path) | |
if git("branch").include?(new_branch_name) | |
if File.exist?(worktree_path) | |
puts("worktree already exists") | |
false | |
else | |
puts("checking out a branch #{new_branch_name} at #{worktree_path}") | |
git("worktree", "add", "-f", worktree_path, new_branch_name) | |
true | |
end | |
else | |
puts("fetching upstream...") | |
git("fetch", "upstream") | |
puts("creating new branch #{new_branch_name} at #{worktree_path}") | |
git("worktree", "add", "-f", "-b", new_branch_name, worktree_path, | |
"upstream/master") | |
true | |
end | |
end |
This file contains hidden or 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
require('open-uri') | |
require_relative('git') | |
$user = "taku0" | |
def read_current_version_in_nixpkgs(sources_relative_path) | |
if git("show", "master:" + sources_relative_path) =~ /version = "([0-9.]*)";/ | |
$1 | |
else | |
nil | |
end | |
end | |
def get_last_version_at_mozilla(uri) | |
available_versions = open(uri) do |io| | |
io.read.scan(%r|>([0-9.]*)/</a>|).map do |match| | |
match[0].split(".").map(&:to_i) | |
end.sort | |
end | |
if not available_versions.empty? | |
available_versions[-1].join(".") | |
else | |
nil | |
end | |
end | |
def update_if_needed(package_name, package_relative_path, base_uri) | |
sources_relative_path = File.join(package_relative_path, "sources.nix") | |
old_version = read_current_version_in_nixpkgs(sources_relative_path) | |
new_version = get_last_version_at_mozilla(base_uri) | |
puts("old version: #{old_version}") | |
puts("new version: #{new_version}") | |
if old_version.nil? || new_version.nil? || old_version == new_version | |
return | |
end | |
puts("new version found.") | |
new_branch_name = "#{package_name}-#{new_version}" | |
worktree_path = File.expand_path("~/tmp/#{new_branch_name}") | |
if not create_new_branch_at_new_worktree(new_branch_name, worktree_path) | |
puts("delete it to retry") | |
return | |
end | |
Dir.chdir(File.join(worktree_path, package_relative_path)) | |
puts("getting archives") | |
IO.popen(["ruby", "generate_sources.rb", new_version]) do |io| | |
IO.write("sources.nix", io.read) | |
end | |
git("add", File.join(package_relative_path, "sources.nix"), | |
:nixpkgs_dir => worktree_path) | |
git("commit", "-m", "#{package_name}: #{old_version} -> #{new_version}", | |
:nixpkgs_dir => worktree_path) | |
git("push", "origin", "HEAD", :nixpkgs_dir => worktree_path) | |
system("hub", "compare", "master...#{$user}:#{new_branch_name}") | |
puts("building") | |
Dir.chdir(worktree_path) | |
system("nix-env", "-i", "-f", worktree_path, package_name) | |
# system("nix-shell", "-p", "nox", "--run", 'nox-review revs HEAD HEAD^') | |
puts("done") | |
end | |
puts(Time.now) | |
update_if_needed( | |
"firefox-bin", | |
"pkgs/applications/networking/browsers/firefox-bin", | |
"http://archive.mozilla.org/pub/firefox/releases/" | |
) | |
update_if_needed( | |
"thunderbird-bin", | |
"pkgs/applications/networking/mailreaders/thunderbird-bin", | |
"http://archive.mozilla.org/pub/thunderbird/releases/" | |
) | |
puts() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment