Debian Codegraph @

packages/launchpad-helper.rb

raw symbols SCIP
1 # Copyright(C) 2014-2020 Sutou Kouhei <[email protected]>
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17 require "pathname"
18
19 module LaunchpadHelper
20 private
21 def enable_ubuntu?
22 true
23 end
24
25 def ubuntu_targets
26 return [] unless enable_ubuntu?
27
28 targets = (ENV["UBUNTU_TARGETS"] || "").split(",")
29 return targets.each_slice(2).to_a unless targets.empty?
30
31 ubuntu_targets_default
32 end
33
34 def ubuntu_targets_default
35 [
36 ["jammy", "22.04"],
37 ["noble", "24.04"],
38 ["resolute", "26.04"],
39 ]
40 end
41
42 def ubuntu_dir
43 "ubuntu"
44 end
45
46 def dput_configuration_name
47 env_value("DPUT_CONFIGURATION_NAME")
48 end
49
50 def dput_incoming
51 env_value("DPUT_INCOMING")
52 end
53
54 def ubuntu_pgp_sign_key
55 env_value("LAUNCHPAD_UPLOADER_PGP_KEY")
56 end
57
58 def ensure_dput_configuration
59 dput_cf_path = Pathname.new("~/.dput.cf").expand_path
60 if dput_cf_path.exist?
61 dput_cf_content = dput_cf_path.read
62 else
63 dput_cf_content = ""
64 end
65 dput_cf_content.each_line do |line|
66 return if line.chomp == "[#{dput_configuration_name}]"
67 end
68
69 dput_cf_path.open("w") do |dput_cf|
70 dput_cf.puts(dput_cf_content)
71 dput_cf.puts(<<-CONFIGURATION)
72 [#{dput_configuration_name}]
73 fqdn = ppa.launchpad.net
74 method = ftp
75 incoming = #{dput_incoming}
76 login = anonymous
77 allow_unsigned_uploads = 0
78 CONFIGURATION
79 end
80 end
81
82 def detect_current_deb_version
83 /\((.+)\)/ =~ File.read("debian/changelog").lines.first
84 $1
85 end
86
87 def ubuntu_upload(code_name, version)
88 ensure_dput_configuration
89
90 absoulte_deb_archive_name = File.expand_path(deb_archive_name)
91 tmp_dir = "#{ubuntu_dir}/tmp"
92 rm_rf(tmp_dir)
93 mkdir_p(tmp_dir)
94 apt_prepare_debian_dir(tmp_dir, "ubuntu-#{code_name}")
95 cd(tmp_dir) do
96 deb_archive_base_name = File.basename(absoulte_deb_archive_name, ".tar.gz")
97 sh("tar", "xf", absoulte_deb_archive_name)
98 cp(absoulte_deb_archive_name,
99 "#{@package}_#{@deb_upstream_version}.orig.tar.gz")
100 cd(deb_archive_base_name) do
101 cp_r("../debian.ubuntu-#{code_name}", "debian")
102 minor_version = ENV["UBUNTU_MINOR_VERSION"] || "1"
103 version_suffix = "ubuntu#{version}.#{minor_version}"
104 deb_version = "#{detect_current_deb_version}.#{version_suffix}"
105 env = {
106 "DEBFULLNAME" => packager_name,
107 "DEBEMAIL" => packager_email,
108 }
109 sh(env,
110 "dch",
111 "--distribution", code_name,
112 "--newversion", deb_version,
113 "Build for #{code_name}.")
114 sh("debuild",
115 "--set-envvar=LINTIAN_PROFILE=ubuntu",
116 # Workaround for Launchpad. Launchpad doesn't accept
117 # .buildinfo yet.
118 # See also: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=853795
119 "--buildinfo-option=-O",
120 "-d",
121 "-S",
122 "-sa",
123 "-k#{ubuntu_pgp_sign_key}")
124 sh("dput",
125 dput_configuration_name,
126 "../#{@package}_#{deb_version}_source.changes")
127 end
128 end
129 end
130
131 def define_ubuntu_tasks
132 namespace :ubuntu do
133 upload_task_names = []
134 namespace :upload do
135 ubuntu_targets.each do |code_name, version|
136 upload_task_names << "ubuntu:upload:#{code_name}"
137 desc "Upload Ubuntu package for #{code_name}"
138 task code_name => deb_archive_name do
139 ubuntu_upload(code_name, version)
140 end
141 end
142 end
143
144 desc "Upload Ubuntu packages"
145 task :upload => upload_task_names
146 end
147
148 desc "Release Ubuntu packages"
149 task :ubuntu => ["ubuntu:upload"]
150 end
151 end