native-packages 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -1
- data/README.md +2 -1
- data/docs/_guides/building-packages.md +5 -0
- data/docs/_guides/getting-started.md +2 -2
- data/docs/_guides/github-actions.md +4 -4
- data/docs/_guides/hosted-repositories.md +170 -0
- data/docs/_guides/native-recipes.md +1 -1
- data/docs/_guides/publishing.md +19 -0
- data/docs/_guides/release-signing.md +3 -3
- data/docs/_guides/windows-signing.md +1 -1
- data/docs/_reference/commands.md +4 -3
- data/docs/_reference/configuration.md +7 -3
- data/docs/_reference/platforms.md +122 -5
- data/docs/_reference/troubleshooting.md +2 -2
- data/docs/index.md +1 -1
- data/docs/releasing.md +2 -2
- data/examples/native-packages-all-formats.yaml +1 -1
- data/examples/native-packages-linux-distribution.yaml +76 -0
- data/examples/native-packages.yaml +1 -1
- data/lib/native_packages/appimage.rb +4 -66
- data/lib/native_packages/apt_repository.rb +190 -0
- data/lib/native_packages/build.rb +39 -2
- data/lib/native_packages/configuration.rb +27 -2
- data/lib/native_packages/dnf_repository.rb +131 -0
- data/lib/native_packages/flatpak.rb +171 -0
- data/lib/native_packages/flatpak_repository.rb +63 -0
- data/lib/native_packages/hosted_repository.rb +73 -0
- data/lib/native_packages/inspection.rb +3 -2
- data/lib/native_packages/macos_signing.rb +20 -2
- data/lib/native_packages/openpgp.rb +114 -0
- data/lib/native_packages/snap.rb +166 -0
- data/lib/native_packages/staging.rb +74 -0
- data/lib/native_packages/support.rb +1 -1
- metadata +11 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# A desktop app distributed on Linux beyond release downloads.
|
|
2
|
+
# Supply dist/linux-amd64 (the program, its desktop entry and its icon) and
|
|
3
|
+
# packaging/org.example.App.metainfo.xml before building.
|
|
4
|
+
schema: 1
|
|
5
|
+
tool:
|
|
6
|
+
version: '0.12.0'
|
|
7
|
+
nfpm: '2.47.0'
|
|
8
|
+
nfpm:
|
|
9
|
+
name: example-app
|
|
10
|
+
description: Example native application
|
|
11
|
+
maintainer: Example Maintainer <maintainer@example.org>
|
|
12
|
+
homepage: https://example.org/example-app
|
|
13
|
+
license: MIT
|
|
14
|
+
contents:
|
|
15
|
+
- src: '@PAYLOAD@/example-app'
|
|
16
|
+
dst: /usr/bin/example-app
|
|
17
|
+
file_info:
|
|
18
|
+
mode: 0755
|
|
19
|
+
- src: '@PAYLOAD@/example-app.desktop'
|
|
20
|
+
dst: /usr/share/applications/example-app.desktop
|
|
21
|
+
- src: '@PAYLOAD@/example-app.svg'
|
|
22
|
+
dst: /usr/share/icons/hicolor/scalable/apps/example-app.svg
|
|
23
|
+
targets:
|
|
24
|
+
linux-amd64:
|
|
25
|
+
platform: linux
|
|
26
|
+
arch: amd64
|
|
27
|
+
libc: glibc
|
|
28
|
+
formats: [deb, rpm, flatpak, snap]
|
|
29
|
+
input:
|
|
30
|
+
kind: directory
|
|
31
|
+
local: dist/linux-amd64
|
|
32
|
+
release:
|
|
33
|
+
repository: example/example-app
|
|
34
|
+
flatpak:
|
|
35
|
+
id: org.example.App
|
|
36
|
+
runtime: org.freedesktop.Platform
|
|
37
|
+
runtime_version: '24.08'
|
|
38
|
+
command: example-app
|
|
39
|
+
metainfo: packaging/org.example.App.metainfo.xml
|
|
40
|
+
runtime_repo: https://dl.flathub.org/repo/flathub.flatpakrepo
|
|
41
|
+
finish_args:
|
|
42
|
+
- --socket=wayland
|
|
43
|
+
- --socket=fallback-x11
|
|
44
|
+
- --share=ipc
|
|
45
|
+
- --device=dri
|
|
46
|
+
# publish --to flatpak writes a signed repository users add with the
|
|
47
|
+
# .flatpakref beside it. Not Flathub.
|
|
48
|
+
repository:
|
|
49
|
+
directory: ../example-site/flatpak
|
|
50
|
+
url: https://example.org/flatpak
|
|
51
|
+
title: Example App
|
|
52
|
+
signing_key: 0123456789ABCDEF0123456789ABCDEF01234567
|
|
53
|
+
# A strictly confined snap sees only its base's libraries and its own files.
|
|
54
|
+
snap:
|
|
55
|
+
base: core24
|
|
56
|
+
grade: stable
|
|
57
|
+
icon: /usr/share/icons/hicolor/scalable/apps/example-app.svg
|
|
58
|
+
apps:
|
|
59
|
+
example-app:
|
|
60
|
+
command: usr/bin/example-app
|
|
61
|
+
desktop: usr/share/applications/example-app.desktop
|
|
62
|
+
plugs: [wayland, x11, opengl, desktop]
|
|
63
|
+
store:
|
|
64
|
+
channels: [stable]
|
|
65
|
+
# publish --to apt,dnf writes signed repositories into a static site checkout,
|
|
66
|
+
# with the key from NATIVE_PACKAGES_GPG_KEY or your GnuPG agent.
|
|
67
|
+
apt:
|
|
68
|
+
directory: ../example-site/apt
|
|
69
|
+
url: https://example.org/apt
|
|
70
|
+
signing_key: 0123456789ABCDEF0123456789ABCDEF01234567
|
|
71
|
+
keep: 3
|
|
72
|
+
dnf:
|
|
73
|
+
directory: ../example-site/rpm
|
|
74
|
+
url: https://example.org/rpm
|
|
75
|
+
signing_key: 0123456789ABCDEF0123456789ABCDEF01234567
|
|
76
|
+
keep: 3
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "digest"
|
|
4
|
+
require_relative "staging"
|
|
4
5
|
|
|
5
6
|
module NativePackages
|
|
6
7
|
# Builds a type 2 AppImage from the same contents nFPM packages: the files
|
|
@@ -9,6 +10,7 @@ module NativePackages
|
|
|
9
10
|
# as the deb and rpm packages do.
|
|
10
11
|
class AppImage
|
|
11
12
|
include Support
|
|
13
|
+
include Staging
|
|
12
14
|
RUNTIME = "20251108"
|
|
13
15
|
RUNTIME_URL = "https://github.com/AppImage/type2-runtime/releases/download/#{RUNTIME}"
|
|
14
16
|
# nFPM architecture => [AppImage architecture, runtime SHA-256].
|
|
@@ -135,7 +137,7 @@ module NativePackages
|
|
|
135
137
|
Dir.mktmpdir("native-packages-appimage-") do |directory|
|
|
136
138
|
appdir = Pathname.new(directory) / "AppDir"
|
|
137
139
|
appdir.mkpath
|
|
138
|
-
stage(package, appdir)
|
|
140
|
+
stage(package, appdir, "appimage")
|
|
139
141
|
entry = integrate(appdir)
|
|
140
142
|
normalize(appdir, epoch)
|
|
141
143
|
image = Pathname.new(directory) / "filesystem.squashfs"
|
|
@@ -185,54 +187,6 @@ module NativePackages
|
|
|
185
187
|
raise Error, "not a type 2 AppImage: #{path}" unless header&.start_with?("\x7fELF".b) && header.byteslice(8, 3) == "AI\x02".b
|
|
186
188
|
end
|
|
187
189
|
|
|
188
|
-
# nFPM overrides replace the contents list when one is supplied.
|
|
189
|
-
def contents(package)
|
|
190
|
-
package.fetch("overrides", {}).fetch("appimage", {}).fetch("contents", package.fetch("contents"))
|
|
191
|
-
.reject { |item| item["packager"] && item["packager"] != "appimage" }
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
def inside(appdir, destination)
|
|
195
|
-
raise Error, "appimage: content destinations must be absolute: #{destination}" unless destination.to_s.start_with?("/")
|
|
196
|
-
appdir / relative_path(destination.to_s.delete_prefix("/"))
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
def stage(package, appdir)
|
|
200
|
-
contents(package).each do |item|
|
|
201
|
-
type = item.fetch("type", "file")
|
|
202
|
-
next if type == "ghost"
|
|
203
|
-
target = inside(appdir, item.fetch("dst"))
|
|
204
|
-
mode = item.dig("file_info", "mode")
|
|
205
|
-
case type
|
|
206
|
-
when "dir"
|
|
207
|
-
target.mkpath
|
|
208
|
-
when "symlink"
|
|
209
|
-
target.dirname.mkpath
|
|
210
|
-
File.symlink(item.fetch("src"), target)
|
|
211
|
-
when "file", "tree", "config", "config|noreplace", "config|missingok"
|
|
212
|
-
source = File.expand_path(item.fetch("src"), root)
|
|
213
|
-
paths = package["disable_globbing"] ? [source].select { |path| File.exist?(path) } : Dir.glob(source).sort
|
|
214
|
-
raise Error, "missing package content: #{source}" if paths.empty?
|
|
215
|
-
# As nFPM does: a glob source, or a destination ending in a slash,
|
|
216
|
-
# makes the destination a directory that takes each match's name.
|
|
217
|
-
pattern = !package["disable_globbing"] && item.fetch("src").match?(/[*?\[{]/)
|
|
218
|
-
single = paths.length == 1 && File.file?(paths.first) && type != "tree" && !pattern && !item.fetch("dst").end_with?("/")
|
|
219
|
-
paths.each do |path|
|
|
220
|
-
if File.directory?(path)
|
|
221
|
-
target.mkpath
|
|
222
|
-
FileUtils.cp_r(Dir.children(path).map { |child| File.join(path, child) }, target)
|
|
223
|
-
else
|
|
224
|
-
file = single ? target : target / File.basename(path)
|
|
225
|
-
file.dirname.mkpath
|
|
226
|
-
FileUtils.cp(path, file)
|
|
227
|
-
file.chmod(mode) if mode
|
|
228
|
-
end
|
|
229
|
-
end
|
|
230
|
-
else
|
|
231
|
-
raise Error, "appimage: unsupported content type #{type}"
|
|
232
|
-
end
|
|
233
|
-
end
|
|
234
|
-
end
|
|
235
|
-
|
|
236
190
|
# AppImage's root needs the desktop entry, its icon and AppRun.
|
|
237
191
|
def integrate(appdir)
|
|
238
192
|
entries = Pathname.glob(appdir / "usr/share/applications/*.desktop")
|
|
@@ -243,7 +197,7 @@ module NativePackages
|
|
|
243
197
|
result[key] ||= value if value && %w[Exec Icon].include?(key)
|
|
244
198
|
end
|
|
245
199
|
command = Shellwords.split(fields.fetch("Exec") { raise Error, "appimage: #{desktop.basename} has no Exec" }).first
|
|
246
|
-
executable = command.start_with?("/") ? inside(appdir, command) : appdir / "usr/bin" / relative_path(command)
|
|
200
|
+
executable = command.start_with?("/") ? inside(appdir, command, "appimage") : appdir / "usr/bin" / relative_path(command)
|
|
247
201
|
raise Error, "appimage: #{desktop.basename} runs #{command}, which the package does not install" unless executable.file? && executable.executable?
|
|
248
202
|
name = fields.fetch("Icon") { raise Error, "appimage: #{desktop.basename} has no Icon" }
|
|
249
203
|
raise Error, "appimage: Icon must be a name, not a path" if name.include?("/")
|
|
@@ -257,21 +211,5 @@ module NativePackages
|
|
|
257
211
|
File.symlink(executable.relative_path_from(appdir).to_s, appdir / "AppRun")
|
|
258
212
|
{ "desktop" => desktop.basename.to_s, "icon" => icon.basename.to_s, "executable" => executable.relative_path_from(appdir).to_s }
|
|
259
213
|
end
|
|
260
|
-
|
|
261
|
-
# The same bytes for the same inputs: fixed modes and times.
|
|
262
|
-
def normalize(appdir, epoch)
|
|
263
|
-
time = Time.at(epoch)
|
|
264
|
-
Pathname.glob(appdir / "**/*", File::FNM_DOTMATCH).each do |path|
|
|
265
|
-
next if path.basename.to_s == "."
|
|
266
|
-
if path.symlink?
|
|
267
|
-
File.lutime(time, time, path)
|
|
268
|
-
else
|
|
269
|
-
path.chmod(path.directory? || path.executable? ? 0o755 : 0o644)
|
|
270
|
-
File.utime(time, time, path)
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
appdir.chmod(0o755)
|
|
274
|
-
File.utime(time, time, appdir)
|
|
275
|
-
end
|
|
276
214
|
end
|
|
277
215
|
end
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "digest"
|
|
4
|
+
require "zlib"
|
|
5
|
+
require "rubygems/package"
|
|
6
|
+
require "stringio"
|
|
7
|
+
require_relative "hosted_repository"
|
|
8
|
+
|
|
9
|
+
module NativePackages
|
|
10
|
+
# A signed APT repository: pool/ holds the .deb files and dists/ the
|
|
11
|
+
# indexes apt reads (Packages, Release, InRelease and Release.gpg), written
|
|
12
|
+
# by this class without Debian's own tools. Beside them go the public key
|
|
13
|
+
# (NAME.gpg) and a deb822 NAME.sources file for users to install.
|
|
14
|
+
class AptRepository < HostedRepository
|
|
15
|
+
KEYS = (HostedRepository::KEYS + %w[suite component]).freeze
|
|
16
|
+
WORD = /\A[a-z0-9][a-z0-9._-]*\z/
|
|
17
|
+
# The order apt-ftparchive writes; other fields follow in their own order.
|
|
18
|
+
FIELDS = %w[Package Version Architecture].freeze
|
|
19
|
+
|
|
20
|
+
def self.validate(data)
|
|
21
|
+
settings = data["apt"]
|
|
22
|
+
return if settings.nil?
|
|
23
|
+
check(settings, "apt", KEYS)
|
|
24
|
+
%w[suite component].each do |key|
|
|
25
|
+
raise Error, "apt.#{key}: use lowercase letters, digits, dots, underscores or hyphens" if settings.key?(key) && !WORD.match?(settings[key].to_s)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def initialize(configuration)
|
|
30
|
+
super(configuration, configuration.data.fetch("apt") { raise Error, "configure apt to publish --to apt" })
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def suite = settings.fetch("suite", "stable")
|
|
34
|
+
def component = settings.fetch("component", "main")
|
|
35
|
+
|
|
36
|
+
# The control paragraph of the .deb at `path`, as text.
|
|
37
|
+
def self.control(path)
|
|
38
|
+
File.open(path, "rb") do |file|
|
|
39
|
+
raise Error, "not a Debian package: #{path}" unless file.read(8) == "!<arch>\n".b
|
|
40
|
+
until file.eof?
|
|
41
|
+
header = file.read(60)
|
|
42
|
+
raise Error, "truncated Debian package: #{path}" unless header&.bytesize == 60
|
|
43
|
+
member = header.byteslice(0, 16).strip.delete_suffix("/")
|
|
44
|
+
size = Integer(header.byteslice(48, 10).strip, 10)
|
|
45
|
+
if member.start_with?("control.tar")
|
|
46
|
+
raise Error, "#{File.basename(path)}: #{member} is not gzip-compressed; build the package with nFPM" unless member == "control.tar.gz"
|
|
47
|
+
Gem::Package::TarReader.new(Zlib::GzipReader.new(StringIO.new(file.read(size)))).each do |entry|
|
|
48
|
+
return entry.read.force_encoding(Encoding::UTF_8) if entry.full_name.delete_prefix("./") == "control"
|
|
49
|
+
end
|
|
50
|
+
raise Error, "#{File.basename(path)} has no control file"
|
|
51
|
+
end
|
|
52
|
+
file.seek(size + (size % 2), IO::SEEK_CUR)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
raise Error, "#{File.basename(path)} has no control.tar member"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# The fields of a control paragraph; continuation lines stay with theirs.
|
|
59
|
+
def self.fields(control)
|
|
60
|
+
control.lines.each_with_object({}) do |line, result|
|
|
61
|
+
next if line.strip.empty?
|
|
62
|
+
if line.start_with?(" ", "\t")
|
|
63
|
+
result[result.keys.last] += "\n#{line.chomp}"
|
|
64
|
+
else
|
|
65
|
+
key, value = line.split(":", 2)
|
|
66
|
+
result[key] = value.to_s.strip
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Debian's version order (dpkg --compare-versions): -1, 0 or 1.
|
|
72
|
+
def self.compare(left, right)
|
|
73
|
+
left, right = [left, right].map do |version|
|
|
74
|
+
epoch, rest = version.include?(":") ? version.split(":", 2) : ["0", version]
|
|
75
|
+
upstream, _, revision = rest.include?("-") ? rest.rpartition("-") : [rest, nil, "0"]
|
|
76
|
+
[Integer(epoch, 10), upstream, revision]
|
|
77
|
+
end
|
|
78
|
+
(left[0] <=> right[0]).nonzero? || compare_part(left[1], right[1]).nonzero? || compare_part(left[2], right[2])
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def self.compare_part(left, right)
|
|
82
|
+
until left.empty? && right.empty?
|
|
83
|
+
words = [left, right].map { |part| part[/\A\D*/] }
|
|
84
|
+
length = words.map(&:length).max
|
|
85
|
+
length.times do |index|
|
|
86
|
+
order = words.map { |word| rank(word[index]) }
|
|
87
|
+
return order[0] <=> order[1] unless order[0] == order[1]
|
|
88
|
+
end
|
|
89
|
+
left, right = [left, right].zip(words).map { |part, word| part[word.length..] }
|
|
90
|
+
numbers = [left, right].map { |part| part[/\A\d*/] }
|
|
91
|
+
order = numbers[0].to_i <=> numbers[1].to_i
|
|
92
|
+
return order unless order.zero?
|
|
93
|
+
left, right = [left, right].zip(numbers).map { |part, number| part[number.length..] }
|
|
94
|
+
end
|
|
95
|
+
0
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Tilde sorts before everything, even the end; letters before the rest.
|
|
99
|
+
def self.rank(character)
|
|
100
|
+
return 0 if character.nil?
|
|
101
|
+
return -1 if character == "~"
|
|
102
|
+
character.match?(/[A-Za-z]/) ? character.ord : character.ord + 256
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def publish(debs, secret: nil, passphrase: nil)
|
|
106
|
+
raise Error, "the build contains no deb packages to publish --to apt" if debs.empty?
|
|
107
|
+
debs.each do |path|
|
|
108
|
+
package = self.class.fields(self.class.control(path)).fetch("Package")
|
|
109
|
+
prefix = package.start_with?("lib") ? package[0, 4] : package[0]
|
|
110
|
+
place(path, directory / "pool" / component / prefix / package / path.basename)
|
|
111
|
+
end
|
|
112
|
+
entries = Pathname.glob(directory / "pool/**/*.deb").sort.to_h do |path|
|
|
113
|
+
control = self.class.control(path)
|
|
114
|
+
fields = self.class.fields(control)
|
|
115
|
+
[path, [fields.values_at("Package", "Architecture"), fields.fetch("Version"), control]]
|
|
116
|
+
end
|
|
117
|
+
entries = prune(entries) { |left, right| self.class.compare(left, right) }
|
|
118
|
+
signer(secret: secret, passphrase: passphrase).session { |signing| write_indexes(entries, signing) }
|
|
119
|
+
puts "Published #{entries.length} package#{"s" unless entries.length == 1} to #{directory}. Install with:", *instructions.map { |line| " #{line}" }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def instructions
|
|
123
|
+
["sudo install -d -m 0755 /etc/apt/keyrings",
|
|
124
|
+
"sudo curl -fsSLo /etc/apt/keyrings/#{name}.gpg #{url}/#{name}.gpg",
|
|
125
|
+
"sudo curl -fsSLo /etc/apt/sources.list.d/#{name}.sources #{url}/#{name}.sources",
|
|
126
|
+
"sudo apt update && sudo apt install #{name}"]
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
private
|
|
130
|
+
|
|
131
|
+
def write_indexes(entries, signing)
|
|
132
|
+
architectures = entries.values.map { |(_, architecture), _, _| architecture }.uniq.sort
|
|
133
|
+
architectures = (architectures - ["all"]).then { |specific| specific.empty? ? ["all"] : specific }
|
|
134
|
+
dists = directory / "dists" / suite
|
|
135
|
+
FileUtils.rm_rf(dists)
|
|
136
|
+
indexes = architectures.flat_map do |architecture|
|
|
137
|
+
stanzas = entries.select { |_, ((_, own), _, _)| [architecture, "all"].include?(own) }
|
|
138
|
+
.sort_by { |path, ((package, _), version, _)| [package, version, path.to_s] }
|
|
139
|
+
.map { |path, (_, _, control)| stanza(path, control) }
|
|
140
|
+
relative = "#{component}/binary-#{architecture}/Packages"
|
|
141
|
+
text = stanzas.join("\n")
|
|
142
|
+
write(dists / relative, text)
|
|
143
|
+
write(dists / "#{relative}.gz", gzip(text))
|
|
144
|
+
[relative, "#{relative}.gz"]
|
|
145
|
+
end
|
|
146
|
+
write(dists / "Release", release(dists, architectures, indexes))
|
|
147
|
+
signing.clearsign(dists / "Release", dists / "InRelease")
|
|
148
|
+
signing.detach_sign(dists / "Release", dists / "Release.gpg")
|
|
149
|
+
write(directory / "#{name}.gpg", signing.public_key)
|
|
150
|
+
write(directory / "#{name}.sources", <<~SOURCES)
|
|
151
|
+
Types: deb
|
|
152
|
+
URIs: #{url}
|
|
153
|
+
Suites: #{suite}
|
|
154
|
+
Components: #{component}
|
|
155
|
+
Signed-By: /etc/apt/keyrings/#{name}.gpg
|
|
156
|
+
SOURCES
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def stanza(path, control)
|
|
160
|
+
fields = self.class.fields(control)
|
|
161
|
+
ordered = FIELDS + (fields.keys - FIELDS)
|
|
162
|
+
body = ordered.map { |key| fields.fetch(key).start_with?("\n") ? "#{key}:#{fields.fetch(key)}" : "#{key}: #{fields.fetch(key)}" }.join("\n")
|
|
163
|
+
bytes = path.binread
|
|
164
|
+
"#{body}\nFilename: #{path.relative_path_from(directory)}\nSize: #{bytes.bytesize}\n" \
|
|
165
|
+
"MD5sum: #{Digest::MD5.hexdigest(bytes)}\nSHA1: #{Digest::SHA1.hexdigest(bytes)}\nSHA256: #{Digest::SHA256.hexdigest(bytes)}\n"
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def release(dists, architectures, indexes)
|
|
169
|
+
epoch = ENV["SOURCE_DATE_EPOCH"] ? Integer(ENV.fetch("SOURCE_DATE_EPOCH")) : Time.now.to_i
|
|
170
|
+
lines = ["Origin: #{name}", "Label: #{name}", "Suite: #{suite}", "Codename: #{suite}",
|
|
171
|
+
"Date: #{Time.at(epoch).utc.strftime('%a, %d %b %Y %H:%M:%S UTC')}", "Architectures: #{architectures.join(' ')}",
|
|
172
|
+
"Components: #{component}", "Description: #{name} packages"]
|
|
173
|
+
{ "MD5Sum" => Digest::MD5, "SHA1" => Digest::SHA1, "SHA256" => Digest::SHA256 }.each do |label, digest|
|
|
174
|
+
lines << "#{label}:"
|
|
175
|
+
indexes.each { |relative| lines << " #{digest.file(dists / relative).hexdigest} #{(dists / relative).size} #{relative}" }
|
|
176
|
+
end
|
|
177
|
+
lines.join("\n") + "\n"
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# The same bytes for the same index: no name or time in the header.
|
|
181
|
+
def gzip(text)
|
|
182
|
+
io = StringIO.new("".b)
|
|
183
|
+
writer = Zlib::GzipWriter.new(io, Zlib::BEST_COMPRESSION)
|
|
184
|
+
writer.mtime = 0
|
|
185
|
+
writer.write(text)
|
|
186
|
+
writer.finish
|
|
187
|
+
io.string
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
@@ -6,10 +6,14 @@ require_relative "native_recipe"
|
|
|
6
6
|
require_relative "macos_signing"
|
|
7
7
|
require_relative "windows_signing"
|
|
8
8
|
require_relative "appimage"
|
|
9
|
+
require_relative "flatpak"
|
|
10
|
+
require_relative "snap"
|
|
9
11
|
|
|
10
12
|
module NativePackages
|
|
11
13
|
class Build
|
|
12
14
|
include Support
|
|
15
|
+
# Destinations signed with the OpenPGP key from the environment.
|
|
16
|
+
HOSTED = %w[apt dnf flatpak].freeze
|
|
13
17
|
attr_reader :configuration, :root, :project
|
|
14
18
|
|
|
15
19
|
def initialize(configuration)
|
|
@@ -33,9 +37,11 @@ module NativePackages
|
|
|
33
37
|
def doctor(ids: [], formats: [], release: false, defer_recipes: false)
|
|
34
38
|
configuration.validate
|
|
35
39
|
selected = configuration.select(ids: ids, formats: formats)
|
|
36
|
-
nfpm_version if selected.values.any? { |target| !(target.fetch("formats") - Configuration::NATIVE_FORMATS -
|
|
40
|
+
nfpm_version if selected.values.any? { |target| !(target.fetch("formats") - Configuration::NATIVE_FORMATS - Configuration::IMAGE_FORMATS).empty? }
|
|
37
41
|
selected.each_value do |target|
|
|
38
42
|
AppImage.new(root).doctor(target, update: !target["appimage"].nil?) if target.fetch("formats").include?("appimage")
|
|
43
|
+
Flatpak.new(configuration).doctor(target) if target.fetch("formats").include?("flatpak")
|
|
44
|
+
Snap.new(configuration).doctor(target) if target.fetch("formats").include?("snap")
|
|
39
45
|
end
|
|
40
46
|
selected.each do |id, target|
|
|
41
47
|
next unless target["native"]
|
|
@@ -179,6 +185,20 @@ module NativePackages
|
|
|
179
185
|
outputs = [package_path, zsync].compact.sort
|
|
180
186
|
raise Error, "AppImage build must create only its package and .zsync file" unless files(destination) == outputs
|
|
181
187
|
packages = [package_path]
|
|
188
|
+
elsif format == "flatpak"
|
|
189
|
+
package = render_tree(configuration.package(target), configuration.target_tokens(info, id, target, payload))
|
|
190
|
+
inspection = Inspection.new(root, configuration.data.fetch("libraries")).check(package, target, format)
|
|
191
|
+
package_path, inspection["flatpak"] = Flatpak.new(configuration).build(package, target, destination, name: configuration.name,
|
|
192
|
+
version: number, epoch: info.fetch("SOURCE_DATE_EPOCH"))
|
|
193
|
+
raise Error, "Flatpak build must create only its bundle" unless files(destination) == [package_path]
|
|
194
|
+
packages = [package_path]
|
|
195
|
+
elsif format == "snap"
|
|
196
|
+
package = render_tree(configuration.package(target), configuration.target_tokens(info, id, target, payload))
|
|
197
|
+
inspection = Inspection.new(root, configuration.data.fetch("libraries")).check(package, target, format)
|
|
198
|
+
package_path, inspection["snap"] = Snap.new(configuration).build(package, target, destination, version: number,
|
|
199
|
+
epoch: info.fetch("SOURCE_DATE_EPOCH"))
|
|
200
|
+
raise Error, "Snap build must create only its snap" unless files(destination) == [package_path]
|
|
201
|
+
packages = [package_path]
|
|
182
202
|
else
|
|
183
203
|
package = render_tree(configuration.package(target), configuration.target_tokens(info, id, target, payload))
|
|
184
204
|
if number.include?("-") && (package.fetch("version_schema", "semver") != "semver" || %w[prerelease version_metadata].any? { |key| package.key?(key) && !package[key].to_s.empty? })
|
|
@@ -201,6 +221,8 @@ module NativePackages
|
|
|
201
221
|
raise Error, "after_package must preserve the package path and output set" unless files(destination) == outputs
|
|
202
222
|
AppImage.new(root).check(packages.first) if format == "appimage"
|
|
203
223
|
AppImage.new(root).check_zsync(zsync, packages.first) if format == "appimage" && zsync
|
|
224
|
+
Flatpak.new(configuration).check(packages.first, Flatpak.architecture(target)) if format == "flatpak"
|
|
225
|
+
Snap.new(configuration).check(packages.first) if format == "snap"
|
|
204
226
|
end
|
|
205
227
|
if native
|
|
206
228
|
native.check_output(packages.first, format)
|
|
@@ -396,12 +418,14 @@ module NativePackages
|
|
|
396
418
|
output = Pathname.new(output).expand_path(root)
|
|
397
419
|
manifest = verify(output, ids: ids)
|
|
398
420
|
raise Error, "supply at least one --to destination" if destinations.empty?
|
|
399
|
-
destinations.each { |name| project.repositories.select(name) unless name
|
|
421
|
+
destinations.each { |name| project.repositories.select(name) unless Configuration::DESTINATIONS.include?(name) }
|
|
400
422
|
if manifest.fetch("version").include?("-")
|
|
401
423
|
raise Error, "prereleases can only attach to an existing GitHub prerelease" unless destinations == ["github"]
|
|
402
424
|
marked = capture("gh", "release", "view", "v#{manifest.fetch('version')}", "--repo", project.repository, "--json", "isPrerelease", "--jq", ".isPrerelease")
|
|
403
425
|
raise Error, "destination release must already be marked prerelease" unless marked == "true"
|
|
404
426
|
end
|
|
427
|
+
# Read once: the signing key leaves the environment when it is read.
|
|
428
|
+
signing = OpenPGP.environment unless (destinations & HOSTED).empty?
|
|
405
429
|
destinations.each do |destination|
|
|
406
430
|
if destination == "github"
|
|
407
431
|
paths = manifest.fetch("packages").flat_map { |entry| [entry.fetch("path"), entry["zsync"]].compact.map { |path| output / path } }
|
|
@@ -414,6 +438,14 @@ module NativePackages
|
|
|
414
438
|
write(checksums, paths.map { |path| "#{sha256(path)} #{path.basename}\n" }.join)
|
|
415
439
|
run "gh", "release", "upload", "v#{manifest.fetch('version')}", *paths, checksums, "--repo", project.repository, "--clobber"
|
|
416
440
|
end
|
|
441
|
+
elsif destination == "apt"
|
|
442
|
+
AptRepository.new(configuration).publish(packages(manifest, output, "deb"), **signing)
|
|
443
|
+
elsif destination == "dnf"
|
|
444
|
+
DnfRepository.new(configuration).publish(packages(manifest, output, "rpm"), **signing)
|
|
445
|
+
elsif destination == "flatpak"
|
|
446
|
+
FlatpakRepository.new(configuration).publish(packages(manifest, output, "flatpak"), **signing)
|
|
447
|
+
elsif destination == "snapcraft"
|
|
448
|
+
Snap.new(configuration).publish(packages(manifest, output, "snap"))
|
|
417
449
|
else
|
|
418
450
|
project.repositories.stage(destination, output / "recipes")
|
|
419
451
|
project.repositories.publish(destination, body_file: body_file)
|
|
@@ -421,6 +453,11 @@ module NativePackages
|
|
|
421
453
|
end
|
|
422
454
|
end
|
|
423
455
|
|
|
456
|
+
# The build's packages of `format`.
|
|
457
|
+
def packages(manifest, output, format)
|
|
458
|
+
manifest.fetch("packages").select { |entry| entry.fetch("format") == format }.map { |entry| output / entry.fetch("path") }
|
|
459
|
+
end
|
|
460
|
+
|
|
424
461
|
def aggregate(inputs, output:, finalize_recipes: false)
|
|
425
462
|
configuration.validate
|
|
426
463
|
output = Pathname.new(output).expand_path(root)
|
|
@@ -2,16 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "project"
|
|
4
4
|
require_relative "appimage"
|
|
5
|
+
require_relative "flatpak"
|
|
6
|
+
require_relative "snap"
|
|
7
|
+
require_relative "apt_repository"
|
|
8
|
+
require_relative "dnf_repository"
|
|
9
|
+
require_relative "flatpak_repository"
|
|
5
10
|
require_relative "windows_signing"
|
|
6
11
|
|
|
7
12
|
module NativePackages
|
|
8
13
|
class Configuration
|
|
9
14
|
include Support
|
|
10
15
|
NATIVE_FORMATS = %w[dmg inno msi].freeze
|
|
11
|
-
|
|
16
|
+
# Formats native-packages writes itself from the package's contents,
|
|
17
|
+
# without nFPM.
|
|
18
|
+
IMAGE_FORMATS = %w[appimage flatpak snap].freeze
|
|
19
|
+
# Publish destinations besides the configured downstream repositories.
|
|
20
|
+
DESTINATIONS = %w[github snapcraft apt dnf flatpak].freeze
|
|
21
|
+
FORMATS = (%w[deb rpm archlinux apk ipk msix srpm appimage flatpak snap] + NATIVE_FORMATS).freeze
|
|
12
22
|
NFPM_VERSION = "2.47.0"
|
|
13
23
|
NAMES = %w[native-packages.yaml native-packages.yml].freeze
|
|
14
|
-
KEYS = %w[schema tool nfpm targets release assets templates repositories revisions libraries version_file version_section windows].freeze
|
|
24
|
+
KEYS = %w[schema tool nfpm targets release assets templates repositories revisions libraries version_file version_section windows flatpak snap apt dnf].freeze
|
|
15
25
|
attr_reader :root, :path, :data
|
|
16
26
|
|
|
17
27
|
def self.discover(root, explicit = nil)
|
|
@@ -129,6 +139,14 @@ module NativePackages
|
|
|
129
139
|
elsif target.key?("appimage")
|
|
130
140
|
raise Error, "#{id}.appimage: only for targets that build an AppImage"
|
|
131
141
|
end
|
|
142
|
+
if formats.include?("flatpak")
|
|
143
|
+
raise Error, "#{id}: Flatpak requires a Linux binary target" unless target["platform"] == "linux" && kind == "binary"
|
|
144
|
+
Flatpak.architecture(target)
|
|
145
|
+
end
|
|
146
|
+
if formats.include?("snap")
|
|
147
|
+
raise Error, "#{id}: Snap requires a Linux binary target" unless target["platform"] == "linux" && kind == "binary"
|
|
148
|
+
Snap.architecture(target)
|
|
149
|
+
end
|
|
132
150
|
begin
|
|
133
151
|
update_information(target, "9.8.7")
|
|
134
152
|
rescue Error => error
|
|
@@ -162,11 +180,18 @@ module NativePackages
|
|
|
162
180
|
render_tree(target["before_build"], target_tokens(metadata, id, target, "/payload")) if target["before_build"]
|
|
163
181
|
render_tree(target["after_package"], target_tokens(metadata, id, target, "/payload").merge("PACKAGE" => "/output/package", "FORMAT" => formats.first)) if target["after_package"]
|
|
164
182
|
end
|
|
183
|
+
reserved = data.fetch("repositories").keys & DESTINATIONS
|
|
184
|
+
raise Error, "repositories.#{reserved.first}: that name is a built-in publish destination; choose another" unless reserved.empty?
|
|
165
185
|
data.fetch("templates").each do |destination, source|
|
|
166
186
|
relative_path(render(destination, metadata))
|
|
167
187
|
render((root / relative_path(source)).binread, metadata)
|
|
168
188
|
end
|
|
169
189
|
WindowsSigning.validate(data)
|
|
190
|
+
Flatpak.validate(data)
|
|
191
|
+
Snap.validate(data)
|
|
192
|
+
AptRepository.validate(data)
|
|
193
|
+
DnfRepository.validate(data)
|
|
194
|
+
FlatpakRepository.validate(data)
|
|
170
195
|
project.repositories
|
|
171
196
|
true
|
|
172
197
|
end
|