native-packages 0.10.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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -1
  3. data/README.md +5 -2
  4. data/docs/_guides/building-packages.md +5 -0
  5. data/docs/_guides/distribution-recipes.md +3 -1
  6. data/docs/_guides/getting-started.md +2 -2
  7. data/docs/_guides/github-actions.md +6 -4
  8. data/docs/_guides/hosted-repositories.md +170 -0
  9. data/docs/_guides/multi-platform.md +1 -1
  10. data/docs/_guides/native-recipes.md +6 -2
  11. data/docs/_guides/omarchy.md +131 -0
  12. data/docs/_guides/prereleases.md +1 -1
  13. data/docs/_guides/publishing.md +19 -0
  14. data/docs/_guides/release-signing.md +4 -4
  15. data/docs/_guides/windows-signing.md +259 -0
  16. data/docs/_reference/commands.md +32 -3
  17. data/docs/_reference/configuration.md +33 -3
  18. data/docs/_reference/platforms.md +126 -8
  19. data/docs/_reference/troubleshooting.md +22 -2
  20. data/docs/index.md +1 -1
  21. data/docs/releasing.md +2 -2
  22. data/examples/native-packages-all-formats.yaml +1 -1
  23. data/examples/native-packages-linux-distribution.yaml +76 -0
  24. data/examples/native-packages.yaml +1 -1
  25. data/lib/native_packages/appimage.rb +4 -66
  26. data/lib/native_packages/apt_repository.rb +190 -0
  27. data/lib/native_packages/build.rb +59 -6
  28. data/lib/native_packages/cli.rb +19 -2
  29. data/lib/native_packages/configuration.rb +29 -2
  30. data/lib/native_packages/dnf_repository.rb +131 -0
  31. data/lib/native_packages/flatpak.rb +171 -0
  32. data/lib/native_packages/flatpak_repository.rb +63 -0
  33. data/lib/native_packages/hosted_repository.rb +73 -0
  34. data/lib/native_packages/inspection.rb +3 -2
  35. data/lib/native_packages/macos_signing.rb +20 -2
  36. data/lib/native_packages/omarchy.rb +140 -0
  37. data/lib/native_packages/openpgp.rb +114 -0
  38. data/lib/native_packages/snap.rb +166 -0
  39. data/lib/native_packages/staging.rb +74 -0
  40. data/lib/native_packages/support.rb +1 -1
  41. data/lib/native_packages/windows_signing.rb +284 -0
  42. metadata +15 -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,6 @@
1
1
  schema: 1
2
2
  tool:
3
- version: '0.10.0'
3
+ version: '0.12.0'
4
4
  nfpm: '2.47.0'
5
5
  nfpm:
6
6
  name: example-app
@@ -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
@@ -4,11 +4,16 @@ require_relative "configuration"
4
4
  require_relative "inspection"
5
5
  require_relative "native_recipe"
6
6
  require_relative "macos_signing"
7
+ require_relative "windows_signing"
7
8
  require_relative "appimage"
9
+ require_relative "flatpak"
10
+ require_relative "snap"
8
11
 
9
12
  module NativePackages
10
13
  class Build
11
14
  include Support
15
+ # Destinations signed with the OpenPGP key from the environment.
16
+ HOSTED = %w[apt dnf flatpak].freeze
12
17
  attr_reader :configuration, :root, :project
13
18
 
14
19
  def initialize(configuration)
@@ -32,15 +37,18 @@ module NativePackages
32
37
  def doctor(ids: [], formats: [], release: false, defer_recipes: false)
33
38
  configuration.validate
34
39
  selected = configuration.select(ids: ids, formats: formats)
35
- nfpm_version if selected.values.any? { |target| !(target.fetch("formats") - Configuration::NATIVE_FORMATS - ["appimage"]).empty? }
40
+ nfpm_version if selected.values.any? { |target| !(target.fetch("formats") - Configuration::NATIVE_FORMATS - Configuration::IMAGE_FORMATS).empty? }
36
41
  selected.each_value do |target|
37
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")
38
45
  end
39
46
  selected.each do |id, target|
40
47
  next unless target["native"]
41
48
  metadata = configuration.target_tokens(configuration.tokens("9.8.7"), id, target, "/payload").merge("PACKAGE" => "/output/package", "FORMAT" => target.fetch("formats").first)
42
49
  NativeRecipe.new(root).doctor(target, render_tree(target.fetch("native").fetch("command"), metadata))
43
50
  MacosSigning.new(root).doctor if target["platform"] == "macos"
51
+ WindowsSigning.new(configuration).doctor if target["platform"] == "windows"
44
52
  end
45
53
  required = []
46
54
  required << "readelf" if selected.values.any? { |target| target["platform"] == "linux" && target.fetch("kind", "binary") == "binary" }
@@ -95,8 +103,13 @@ module NativePackages
95
103
  end
96
104
  output = Pathname.new(output || root / "dist/packages" / number).expand_path(root)
97
105
  if dry_run
98
- puts JSON.pretty_generate("version" => number, "mode" => release ? "release" : "local", "output" => output.to_s,
99
- "recipes" => defer_recipes ? "deferred" : "included", "targets" => selected.transform_values { |target| target.slice("formats", "platform", "arch", "input", "before_build", "after_package", "native") })
106
+ plan = { "version" => number, "mode" => release ? "release" : "local", "output" => output.to_s,
107
+ "recipes" => defer_recipes ? "deferred" : "included", "targets" => selected.transform_values { |target| target.slice("formats", "platform", "arch", "input", "before_build", "after_package", "native") } }
108
+ windows = WindowsSigning.new(configuration)
109
+ if windows.configured? && selected.values.any? { |target| target["platform"] == "windows" && target["native"] }
110
+ plan["windows_signing"] = { "provider" => WindowsSigning::PROVIDER, "state" => windows.state }
111
+ end
112
+ puts JSON.pretty_generate(plan)
100
113
  return
101
114
  end
102
115
  raise Error, "output exists: #{output}; choose a fresh --output" if output.exist?
@@ -142,7 +155,11 @@ module NativePackages
142
155
  else
143
156
  copy_input(source, payload, input.fetch("kind", "archive"))
144
157
  end
145
- signer = target["platform"] == "macos" ? MacosSigning.new(root) : nil
158
+ signer = if target["platform"] == "macos"
159
+ MacosSigning.new(root)
160
+ elsif target["platform"] == "windows" && native
161
+ WindowsSigning.new(configuration)
162
+ end
146
163
  with_signing(signer) do |signing|
147
164
  signing.sign_payload(payload) if signing
148
165
  payload_digest = native && native.digest(payload)
@@ -168,6 +185,20 @@ module NativePackages
168
185
  outputs = [package_path, zsync].compact.sort
169
186
  raise Error, "AppImage build must create only its package and .zsync file" unless files(destination) == outputs
170
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]
171
202
  else
172
203
  package = render_tree(configuration.package(target), configuration.target_tokens(info, id, target, payload))
173
204
  if number.include?("-") && (package.fetch("version_schema", "semver") != "semver" || %w[prerelease version_metadata].any? { |key| package.key?(key) && !package[key].to_s.empty? })
@@ -190,12 +221,19 @@ module NativePackages
190
221
  raise Error, "after_package must preserve the package path and output set" unless files(destination) == outputs
191
222
  AppImage.new(root).check(packages.first) if format == "appimage"
192
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"
193
226
  end
194
227
  if native
195
228
  native.check_output(packages.first, format)
196
229
  raise Error, "native recipes/signing must not change their input payload" unless native.digest(payload) == payload_digest
197
230
  end
198
- inspection["apple"] = signing.notarize(packages.first) if signing
231
+ if signing.is_a?(MacosSigning)
232
+ inspection["apple"] = signing.notarize(packages.first)
233
+ elsif signing
234
+ inspection["windows_signature"] = signing.sign_package(packages.first)
235
+ native.check_output(packages.first, format)
236
+ end
199
237
  record = { "target" => id, "format" => format, "path" => packages.first.relative_path_from(staging).to_s,
200
238
  "sha256" => sha256(packages.first), "validation" => inspection }
201
239
  record["zsync"] = zsync.relative_path_from(staging).to_s if format == "appimage" && zsync
@@ -380,12 +418,14 @@ module NativePackages
380
418
  output = Pathname.new(output).expand_path(root)
381
419
  manifest = verify(output, ids: ids)
382
420
  raise Error, "supply at least one --to destination" if destinations.empty?
383
- destinations.each { |name| project.repositories.select(name) unless name == "github" }
421
+ destinations.each { |name| project.repositories.select(name) unless Configuration::DESTINATIONS.include?(name) }
384
422
  if manifest.fetch("version").include?("-")
385
423
  raise Error, "prereleases can only attach to an existing GitHub prerelease" unless destinations == ["github"]
386
424
  marked = capture("gh", "release", "view", "v#{manifest.fetch('version')}", "--repo", project.repository, "--json", "isPrerelease", "--jq", ".isPrerelease")
387
425
  raise Error, "destination release must already be marked prerelease" unless marked == "true"
388
426
  end
427
+ # Read once: the signing key leaves the environment when it is read.
428
+ signing = OpenPGP.environment unless (destinations & HOSTED).empty?
389
429
  destinations.each do |destination|
390
430
  if destination == "github"
391
431
  paths = manifest.fetch("packages").flat_map { |entry| [entry.fetch("path"), entry["zsync"]].compact.map { |path| output / path } }
@@ -398,6 +438,14 @@ module NativePackages
398
438
  write(checksums, paths.map { |path| "#{sha256(path)} #{path.basename}\n" }.join)
399
439
  run "gh", "release", "upload", "v#{manifest.fetch('version')}", *paths, checksums, "--repo", project.repository, "--clobber"
400
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"))
401
449
  else
402
450
  project.repositories.stage(destination, output / "recipes")
403
451
  project.repositories.publish(destination, body_file: body_file)
@@ -405,6 +453,11 @@ module NativePackages
405
453
  end
406
454
  end
407
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
+
408
461
  def aggregate(inputs, output:, finalize_recipes: false)
409
462
  configuration.validate
410
463
  output = Pathname.new(output).expand_path(root)
@@ -3,6 +3,7 @@
3
3
  require_relative "build"
4
4
  require_relative "scaffold"
5
5
  require_relative "release_signing"
6
+ require_relative "omarchy"
6
7
 
7
8
  module NativePackages
8
9
  module CLI
@@ -16,6 +17,7 @@ module NativePackages
16
17
  [--output DIRECTORY] [--dry-run] Choose output or inspect the plan
17
18
  [--defer-recipes] Build targets without recipe assets/tools
18
19
  notarize-macos DIRECTORY --output DIRECTORY Copy, sign and notarize portable Mac code
20
+ sign-windows FILE... Sign Windows files in place (Azure Artifact Signing)
19
21
  release-checksums DIRECTORY --output FILE Hash a flat directory of release artifacts
20
22
  sign-checksums FILE --public-key HEX_FILE Sign verified checksums with Ed25519
21
23
  [--key-env VARIABLE] Default: NATIVE_PACKAGES_SIGNING_KEY
@@ -31,6 +33,8 @@ module NativePackages
31
33
  publish TARGET [--body-file FILE] Publish a staged downstream update
32
34
  status [TARGET] [--json] [--offline] Check downstream versions and requests
33
35
  check-version TAG Check the application's version
36
+ omarchy-recipe CHECKOUT --release TAG Write a first Omarchy -bin recipe
37
+ [--package NAME] into an omarchy-pkgs checkout
34
38
  Legacy commands remain available:
35
39
  prepare VERSION [--output DIRECTORY]
36
40
  check DIRECTORY
@@ -70,6 +74,10 @@ module NativePackages
70
74
  flags.on("--version VERSION") { |value| options[:value] = value }
71
75
  flags.on("--dry-run") { options[:dry_run] = true }
72
76
  end
77
+ if command == "omarchy-recipe"
78
+ flags.on("--release TAG") { |value| options[:release] = value }
79
+ flags.on("--package NAME") { |value| options[:package] = value }
80
+ end
73
81
  flags.on("--finalize-recipes") { options[:finalize_recipes] = true } if command == "aggregate"
74
82
  if command == "init"
75
83
  flags.on("--interactive") { options[:interactive] = true }
@@ -92,8 +100,8 @@ module NativePackages
92
100
  arity = { "init" => 0..0, "migrate" => 0..0, "build" => 0..0, "doctor" => 0..0, "aggregate" => 1..,
93
101
  "release-checksums" => 1..1, "sign-checksums" => 1..1, "verify-checksums" => 1..1,
94
102
  "prepare" => 1..1, "check" => 1..1, "artifacts" => 1..1, "publish-release" => 2..2,
95
- "notarize-macos" => 1..1, "repositories" => 0..0, "stage" => 2..2, "diff" => 1..1, "publish" => options[:from] ? 0..0 : 1..1,
96
- "publish-aur" => 1..1, "status" => 0..1, "check-version" => 1..1, "validate" => 0..0 }[command]
103
+ "notarize-macos" => 1..1, "sign-windows" => 1.., "repositories" => 0..0, "stage" => 2..2, "diff" => 1..1, "publish" => options[:from] ? 0..0 : 1..1,
104
+ "publish-aur" => 1..1, "status" => 0..1, "check-version" => 1..1, "validate" => 0..0, "omarchy-recipe" => 1..1 }[command]
97
105
  raise Error, HELP unless arity&.cover?(arguments.length)
98
106
  if %w[release-checksums sign-checksums verify-checksums].include?(command)
99
107
  path = Pathname.new(arguments.first).expand_path(root)
@@ -116,6 +124,15 @@ module NativePackages
116
124
  end
117
125
  path = Configuration.discover(root, config_path)
118
126
  configuration = path && Configuration.new(path)
127
+ if command == "sign-windows"
128
+ raise Error, "create native-packages.yaml with windows.signing to sign Windows files" unless configuration
129
+ return WindowsSigning.new(configuration).sign_files(arguments.map { |file| Pathname.new(file).expand_path(root) })
130
+ end
131
+ if command == "omarchy-recipe"
132
+ raise Error, "create native-packages.yaml with init" unless configuration
133
+ raise Error, "omarchy-recipe requires --release" unless options[:release]
134
+ return Omarchy.new(configuration).recipe(Pathname.new(arguments.first).expand_path(root), **options.slice(:release, :package))
135
+ end
119
136
  if %w[build doctor aggregate].include?(command) || options[:from]
120
137
  raise Error, "create native-packages.yaml with init, or convert existing packaging with migrate" unless configuration
121
138
  builder = Build.new(configuration)
@@ -2,15 +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"
10
+ require_relative "windows_signing"
5
11
 
6
12
  module NativePackages
7
13
  class Configuration
8
14
  include Support
9
15
  NATIVE_FORMATS = %w[dmg inno msi].freeze
10
- FORMATS = (%w[deb rpm archlinux apk ipk msix srpm appimage] + NATIVE_FORMATS).freeze
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
11
22
  NFPM_VERSION = "2.47.0"
12
23
  NAMES = %w[native-packages.yaml native-packages.yml].freeze
13
- KEYS = %w[schema tool nfpm targets release assets templates repositories revisions libraries version_file version_section].freeze
24
+ KEYS = %w[schema tool nfpm targets release assets templates repositories revisions libraries version_file version_section windows flatpak snap apt dnf].freeze
14
25
  attr_reader :root, :path, :data
15
26
 
16
27
  def self.discover(root, explicit = nil)
@@ -128,6 +139,14 @@ module NativePackages
128
139
  elsif target.key?("appimage")
129
140
  raise Error, "#{id}.appimage: only for targets that build an AppImage"
130
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
131
150
  begin
132
151
  update_information(target, "9.8.7")
133
152
  rescue Error => error
@@ -161,10 +180,18 @@ module NativePackages
161
180
  render_tree(target["before_build"], target_tokens(metadata, id, target, "/payload")) if target["before_build"]
162
181
  render_tree(target["after_package"], target_tokens(metadata, id, target, "/payload").merge("PACKAGE" => "/output/package", "FORMAT" => formats.first)) if target["after_package"]
163
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?
164
185
  data.fetch("templates").each do |destination, source|
165
186
  relative_path(render(destination, metadata))
166
187
  render((root / relative_path(source)).binread, metadata)
167
188
  end
189
+ WindowsSigning.validate(data)
190
+ Flatpak.validate(data)
191
+ Snap.validate(data)
192
+ AptRepository.validate(data)
193
+ DnfRepository.validate(data)
194
+ FlatpakRepository.validate(data)
168
195
  project.repositories
169
196
  true
170
197
  end