native-packages 0.11.0 → 0.13.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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -1
  3. data/README.md +2 -1
  4. data/docs/_guides/apple-notarization.md +2 -0
  5. data/docs/_guides/building-packages.md +5 -0
  6. data/docs/_guides/distribution-recipes.md +2 -1
  7. data/docs/_guides/getting-started.md +4 -2
  8. data/docs/_guides/github-actions.md +4 -4
  9. data/docs/_guides/hosted-repositories.md +213 -0
  10. data/docs/_guides/native-recipes.md +3 -1
  11. data/docs/_guides/publishing.md +19 -0
  12. data/docs/_guides/release-signing.md +3 -3
  13. data/docs/_guides/windows-signing.md +4 -2
  14. data/docs/_reference/commands.md +4 -3
  15. data/docs/_reference/configuration.md +8 -3
  16. data/docs/_reference/platforms.md +123 -6
  17. data/docs/_reference/troubleshooting.md +2 -2
  18. data/docs/index.md +4 -4
  19. data/docs/releasing.md +2 -2
  20. data/examples/native-packages-all-formats.yaml +1 -1
  21. data/examples/native-packages-linux-distribution.yaml +76 -0
  22. data/examples/native-packages.yaml +1 -1
  23. data/lib/native_packages/appimage.rb +4 -66
  24. data/lib/native_packages/apt_repository.rb +180 -0
  25. data/lib/native_packages/build.rb +41 -2
  26. data/lib/native_packages/configuration.rb +29 -2
  27. data/lib/native_packages/dnf_repository.rb +131 -0
  28. data/lib/native_packages/flatpak.rb +171 -0
  29. data/lib/native_packages/flatpak_repository.rb +63 -0
  30. data/lib/native_packages/hosted_repository.rb +97 -0
  31. data/lib/native_packages/inspection.rb +3 -2
  32. data/lib/native_packages/macos_signing.rb +20 -2
  33. data/lib/native_packages/openpgp.rb +116 -0
  34. data/lib/native_packages/pacman_repository.rb +202 -0
  35. data/lib/native_packages/snap.rb +166 -0
  36. data/lib/native_packages/staging.rb +74 -0
  37. data/lib/native_packages/support.rb +1 -1
  38. metadata +12 -1
@@ -0,0 +1,202 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require "rubygems/package"
5
+ require "stringio"
6
+ require_relative "hosted_repository"
7
+
8
+ module NativePackages
9
+ # A signed pacman repository for Arch Linux: a directory per architecture
10
+ # (x86_64/, aarch64/) holds the .pkg.tar.zst files, each with a detached
11
+ # .sig, and the databases pacman reads (REPO.db and REPO.files), written by
12
+ # this class as repo-add writes them, without pacman's own tools. Static
13
+ # hosts serve no symlinks, so REPO.db and REPO.db.tar.gz are two copies of
14
+ # the same file, as are REPO.files and REPO.files.tar.gz. Beside the
15
+ # architectures goes the public key (REPO.asc) for users to trust.
16
+ class PacmanRepository < HostedRepository
17
+ KEYS = (HostedRepository::KEYS + %w[name]).freeze
18
+ # The architecture directories an `any` package goes into when the
19
+ # repository has none yet.
20
+ ARCHITECTURES = %w[x86_64 aarch64].freeze
21
+ # .PKGINFO keys that may repeat, and the desc entries they become.
22
+ LISTS = { "group" => "GROUPS", "license" => "LICENSE", "replaces" => "REPLACES", "conflict" => "CONFLICTS",
23
+ "provides" => "PROVIDES", "depend" => "DEPENDS", "optdepend" => "OPTDEPENDS", "makedepend" => "MAKEDEPENDS",
24
+ "checkdepend" => "CHECKDEPENDS" }.freeze
25
+ PACKAGE = /\.pkg\.tar(?:\.(?:zst|xz|gz|bz2|lz4|lzo|lrz|Z))?\z/
26
+
27
+ def self.validate(data)
28
+ settings = data["pacman"]
29
+ return if settings.nil?
30
+ check(settings, "pacman", KEYS)
31
+ end
32
+
33
+ def initialize(configuration)
34
+ super(configuration, configuration.data.fetch("pacman") { raise Error, "configure pacman to publish --to pacman" })
35
+ end
36
+
37
+ # The fields of the package at `path`, from its .PKGINFO: single values
38
+ # as strings, repeatable ones as arrays.
39
+ def self.info(path)
40
+ text = Open3.capture3("bsdtar", "-xOqf", path.to_s, ".PKGINFO", binmode: true).then do |output, error, status|
41
+ raise Error, "#{File.basename(path)} is not a pacman package: #{error.strip}" unless status.success? && !output.empty?
42
+ output.force_encoding(Encoding::UTF_8)
43
+ end
44
+ fields = text.each_line.each_with_object(Hash.new { |hash, key| hash[key] = [] }) do |line, result|
45
+ next if line.start_with?("#") || !line.include?("=")
46
+ key, value = line.split("=", 2).map(&:strip)
47
+ result[key] << value.gsub(/\s+/, " ")
48
+ end
49
+ %w[pkgname pkgver arch].each { |key| raise Error, "#{File.basename(path)}: .PKGINFO has no #{key}" if fields[key].empty? }
50
+ fields.to_h { |key, values| [key, LISTS.key?(key) || key == "backup" ? values : values.last] }
51
+ end
52
+
53
+ # The files the package installs, as repo-add lists them.
54
+ def self.contents(path)
55
+ output, error, status = Open3.capture3("bsdtar", "--exclude=^.*", "-tf", path.to_s, binmode: true)
56
+ raise Error, "#{File.basename(path)} could not be listed: #{error.strip}" unless status.success?
57
+ output.force_encoding(Encoding::UTF_8).lines.map(&:chomp).reject(&:empty?).uniq.sort_by(&:b)
58
+ end
59
+
60
+ # pacman's version order (vercmp): -1, 0 or 1.
61
+ def self.compare(left, right)
62
+ return 0 if left == right
63
+ left, right = [left, right].map do |version|
64
+ epoch, rest = version.match?(/\A\d*:/) ? version.split(":", 2) : ["0", version]
65
+ upstream, _, release = rest.include?("-") ? rest.rpartition("-") : [rest, nil, nil]
66
+ [epoch.empty? ? "0" : epoch, upstream, release]
67
+ end
68
+ order = compare_part(left[0], right[0]).nonzero? || compare_part(left[1], right[1])
69
+ return order unless order.zero? && left[2] && right[2]
70
+ compare_part(left[2], right[2])
71
+ end
72
+
73
+ # libalpm's rpmvercmp, which differs from RPM's: no special tilde or
74
+ # caret, a letter suffix sorts before the bare version (1.0a < 1.0), and
75
+ # a longer separator wins.
76
+ def self.compare_part(left, right)
77
+ return 0 if left == right
78
+ one, two = left, right
79
+ until one.empty? || two.empty?
80
+ separators = [one[/\A[^A-Za-z0-9]*/].length, two[/\A[^A-Za-z0-9]*/].length]
81
+ one, two = one[separators[0]..], two[separators[1]..]
82
+ break if one.empty? || two.empty?
83
+ return separators[0] < separators[1] ? -1 : 1 unless separators[0] == separators[1]
84
+ numeric = one.match?(/\A\d/)
85
+ pattern = numeric ? /\A\d+/ : /\A[A-Za-z]+/
86
+ mine, theirs = one[pattern], two[pattern]
87
+ # A number is newer than letters.
88
+ return numeric ? 1 : -1 unless theirs
89
+ order = if numeric
90
+ a, b = [mine, theirs].map { |number| number.sub(/\A0+/, "") }
91
+ (a.length <=> b.length).nonzero? || (a <=> b)
92
+ else
93
+ mine <=> theirs
94
+ end
95
+ return order unless order.zero?
96
+ one, two = one[mine.length..], two[theirs.length..]
97
+ end
98
+ return 0 if one.empty? && two.empty?
99
+ # A remaining letter never beats the end.
100
+ (one.empty? && !two.match?(/\A[A-Za-z]/)) || one.match?(/\A[A-Za-z]/) ? -1 : 1
101
+ end
102
+
103
+ def publish(packages, secret: nil, passphrase: nil)
104
+ raise Error, "the build contains no Arch packages to publish --to pacman" if packages.empty?
105
+ raise Error, "install bsdtar (libarchive) to publish --to pacman" unless available?("bsdtar")
106
+ infos = packages.to_h { |path| [path, self.class.info(path)] }
107
+ present = published.map { |path| path.dirname.basename.to_s }.uniq
108
+ built = infos.values.map { |info| info.fetch("arch") } - ["any"]
109
+ architectures = (present | built).then { |found| found.empty? ? ARCHITECTURES : found }
110
+ remaining = nil
111
+ signer(secret: secret, passphrase: passphrase).session do |signing|
112
+ infos.each do |path, info|
113
+ (info.fetch("arch") == "any" ? architectures : [info.fetch("arch")]).each do |architecture|
114
+ destination = directory / architecture / path.basename
115
+ place(path, destination)
116
+ signature = Pathname.new("#{destination}.sig")
117
+ signing.detach_sign(destination, signature, armor: false) unless signature.exist?
118
+ end
119
+ end
120
+ # Indexes cover every package in the directory, not only this build's.
121
+ entries = published.to_h do |path|
122
+ info = self.class.info(path)
123
+ [path, [[path.dirname.basename.to_s, info.fetch("pkgname")], info.fetch("pkgver"), info]]
124
+ end
125
+ remaining = prune(entries) { |left, right| self.class.compare(left, right) }
126
+ (entries.keys - remaining.keys).each do |path|
127
+ signature = Pathname.new("#{path}.sig")
128
+ signature.delete if signature.exist?
129
+ end
130
+ remaining.group_by { |path, _| path.dirname }.sort.each do |folder, rows|
131
+ write_databases(folder, rows.to_h, signing)
132
+ end
133
+ write(directory / "#{repository}.asc", signing.public_key(armor: true))
134
+ end
135
+ puts "Published #{remaining.length} package#{"s" unless remaining.length == 1} to #{directory}. Install with:", *instructions.map { |line| " #{line}" }
136
+ end
137
+
138
+ def instructions
139
+ fingerprint = OpenPGP.fingerprint(settings.fetch("signing_key"), "signing_key")
140
+ ["curl -fsSL #{url}/#{repository}.asc | sudo pacman-key --add -",
141
+ "sudo pacman-key --lsign-key #{fingerprint}",
142
+ "printf '\\n[#{repository}]\\nSigLevel = Required\\nServer = #{url}/$arch\\n' | sudo tee -a /etc/pacman.conf",
143
+ "sudo pacman -Syu #{name}"]
144
+ end
145
+
146
+ private
147
+
148
+ # Every package in the directory, whichever project published it.
149
+ def published = Pathname.glob(directory / "*/*.pkg.tar*").select { |path| PACKAGE.match?(path.basename.to_s) }.sort
150
+
151
+ # REPO.db and REPO.files in `folder`, as gzip-compressed tar archives,
152
+ # each signed and written twice: once under each name pacman may ask for.
153
+ def write_databases(folder, entries, signing)
154
+ rows = entries.map { |path, (_, _, info)| [path, info, desc(path, info)] }.sort_by { |_, info, _| [info.fetch("pkgname"), info.fetch("pkgver")] }
155
+ databases = {
156
+ "db" => rows.map { |_, info, text| [entry(info), { "desc" => text }] },
157
+ "files" => rows.map { |path, info, text| [entry(info), { "desc" => text, "files" => "%FILES%\n#{self.class.contents(path).map { |line| "#{line}\n" }.join}" }] }
158
+ }
159
+ databases.each do |kind, members|
160
+ archive = gzip(tar(members))
161
+ base = folder / "#{repository}.#{kind}"
162
+ write(base, archive)
163
+ signing.detach_sign(base, Pathname.new("#{base}.sig"), armor: false)
164
+ write(Pathname.new("#{base}.tar.gz"), archive)
165
+ write(Pathname.new("#{base}.tar.gz.sig"), Pathname.new("#{base}.sig").binread)
166
+ end
167
+ end
168
+
169
+ def entry(info) = "#{info.fetch('pkgname')}-#{info.fetch('pkgver')}"
170
+
171
+ # The package's desc entry, in repo-add's order. Signatures are served
172
+ # beside the packages rather than embedded, as repo-add does by default.
173
+ def desc(path, info)
174
+ fields = [["FILENAME", path.basename.to_s], ["NAME", info["pkgname"]], ["BASE", info["pkgbase"]], ["VERSION", info["pkgver"]],
175
+ ["DESC", info["pkgdesc"]], ["GROUPS", info["group"]], ["CSIZE", path.size.to_s], ["ISIZE", info["size"]],
176
+ ["SHA256SUM", Digest::SHA256.file(path).hexdigest], ["URL", info["url"]], ["LICENSE", info["license"]], ["ARCH", info["arch"]],
177
+ ["BUILDDATE", info["builddate"]], ["PACKAGER", info["packager"]], ["REPLACES", info["replaces"]], ["CONFLICTS", info["conflict"]],
178
+ ["PROVIDES", info["provides"]], ["DEPENDS", info["depend"]], ["OPTDEPENDS", info["optdepend"]],
179
+ ["MAKEDEPENDS", info["makedepend"]], ["CHECKDEPENDS", info["checkdepend"]]]
180
+ fields.filter_map do |key, value|
181
+ values = Array(value)
182
+ next if values.empty? || values.first.to_s.empty?
183
+ "%#{key}%\n#{values.map { |line| "#{line}\n" }.join}\n"
184
+ end.join
185
+ end
186
+
187
+ # A tar archive of one directory per package, holding its entries.
188
+ def tar(members)
189
+ io = StringIO.new("".b)
190
+ Gem::Package::TarWriter.new(io) do |writer|
191
+ members.each do |folder, files|
192
+ writer.mkdir(folder, 0o755)
193
+ files.each do |file, text|
194
+ bytes = text.b
195
+ writer.add_file_simple("#{folder}/#{file}", 0o644, bytes.bytesize) { |stream| stream.write(bytes) }
196
+ end
197
+ end
198
+ end
199
+ io.string
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,166 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "staging"
4
+
5
+ module NativePackages
6
+ # Builds a .snap from the same contents nFPM packages: the files become the
7
+ # snap's root, beside a generated meta/snap.yaml, packed with mksquashfs
8
+ # as `snap pack` packs a prime directory. No snapcraft, LXD or network is
9
+ # involved, and no extension (such as gnome) is applied, so the snap uses
10
+ # its base snap's libraries and whatever the package installs.
11
+ class Snap
12
+ include Support
13
+ include Staging
14
+ # nFPM architecture => Snap architecture.
15
+ ARCHES = { "amd64" => "amd64", "arm64" => "arm64", "arm7" => "armhf", "ppc64le" => "ppc64el", "s390x" => "s390x",
16
+ "riscv64" => "riscv64" }.freeze
17
+ KEYS = %w[name summary description title license base confinement grade icon apps plugs slots layout environment store].freeze
18
+ APP_KEYS = %w[command desktop plugs slots environment daemon command-chain common-id restart-condition stop-command
19
+ install-mode autostart].freeze
20
+ NAME = /\A(?=.{2,40}\z)(?=[a-z0-9-]*[a-z])[a-z0-9]+(?:-[a-z0-9]+)*\z/
21
+ APP = /\A[a-zA-Z0-9](?:-?[a-zA-Z0-9])*\z/
22
+ CHANNEL = %r{\A(?:[a-z0-9][a-z0-9._-]*/)?(?:stable|candidate|beta|edge)(?:/[a-z0-9][a-z0-9._-]*)?\z}
23
+ CREDENTIALS = "SNAPCRAFT_STORE_CREDENTIALS"
24
+ attr_reader :root, :settings, :name
25
+
26
+ def initialize(configuration)
27
+ @root = configuration.root
28
+ @settings = configuration.data.fetch("snap", {})
29
+ @name = settings.fetch("name", configuration.name)
30
+ end
31
+
32
+ def self.architecture(target)
33
+ ARCHES.fetch(target.fetch("arch")) { raise Error, "snap does not support #{target.fetch('arch')}; use #{ARCHES.keys.join(', ')}" }
34
+ end
35
+
36
+ def self.validate(data)
37
+ building = data.fetch("targets").values.any? { |target| target.fetch("formats", []).include?("snap") }
38
+ settings = data["snap"]
39
+ raise Error, "snap targets need a top-level snap section" if building && settings.nil?
40
+ return if settings.nil?
41
+ raise Error, "snap: expected a mapping" unless settings.is_a?(Hash)
42
+ raise Error, "snap: no target builds the snap format" unless building
43
+ unknown = settings.keys - KEYS
44
+ raise Error, "snap: unknown fields #{unknown.join(', ')}" unless unknown.empty?
45
+ name = settings.fetch("name", data.fetch("nfpm").fetch("name"))
46
+ raise Error, "snap.name: use 2 to 40 lowercase letters, digits and single hyphens, as #{name.inspect} is not" unless name.is_a?(String) && NAME.match?(name)
47
+ raise Error, "snap.base: expected a base such as core24" unless settings["base"].is_a?(String) && /\A(?:core\d{2}|bare)\z/.match?(settings["base"])
48
+ raise Error, "snap.confinement: use strict, classic or devmode" unless %w[strict classic devmode].include?(settings.fetch("confinement", "strict"))
49
+ raise Error, "snap.grade: use stable or devel" unless %w[stable devel].include?(settings.fetch("grade", "stable"))
50
+ summary = settings.fetch("summary", data.fetch("nfpm")["description"].to_s.lines.first.to_s.strip)
51
+ raise Error, "snap.summary: write a summary of at most 78 characters" unless summary.is_a?(String) && !summary.empty? && summary.length <= 78
52
+ %w[description title license].each do |key|
53
+ raise Error, "snap.#{key}: expected a string" if settings.key?(key) && !settings[key].is_a?(String)
54
+ end
55
+ %w[plugs slots layout environment].each do |key|
56
+ raise Error, "snap.#{key}: expected a mapping" if settings.key?(key) && !settings[key].is_a?(Hash)
57
+ end
58
+ if settings.key?("icon") && !(settings["icon"].is_a?(String) && settings["icon"].match?(/\.(?:png|svg)\z/))
59
+ raise Error, "snap.icon: name a .png or .svg file the package installs, such as /usr/share/icons/hicolor/scalable/apps/app.svg"
60
+ end
61
+ apps = settings["apps"]
62
+ raise Error, "snap.apps: declare at least one app with a command" unless apps.is_a?(Hash) && !apps.empty?
63
+ apps.each do |app, definition|
64
+ raise Error, "snap.apps: invalid app name #{app.inspect}" unless app.is_a?(String) && APP.match?(app)
65
+ raise Error, "snap.apps.#{app}: expected a mapping" unless definition.is_a?(Hash)
66
+ unknown = definition.keys - APP_KEYS
67
+ raise Error, "snap.apps.#{app}: unknown fields #{unknown.join(', ')}" unless unknown.empty?
68
+ unless definition["command"].is_a?(String) && !definition["command"].strip.empty?
69
+ raise Error, "snap.apps.#{app}.command: name a program the package installs, such as usr/bin/#{name}"
70
+ end
71
+ %w[plugs slots].each do |key|
72
+ next unless definition.key?(key)
73
+ raise Error, "snap.apps.#{app}.#{key}: expected a list of names" unless definition[key].is_a?(Array) && definition[key].all?(String)
74
+ end
75
+ raise Error, "snap.apps.#{app}.desktop: name a .desktop file the package installs" if definition.key?("desktop") && !definition["desktop"].to_s.end_with?(".desktop")
76
+ end
77
+ store = settings["store"]
78
+ return if store.nil?
79
+ raise Error, "snap.store: expected a mapping with channels" unless store.is_a?(Hash) && store.keys == ["channels"]
80
+ channels = store["channels"]
81
+ unless channels.is_a?(Array) && !channels.empty? && channels.all? { |channel| channel.is_a?(String) && CHANNEL.match?(channel) }
82
+ raise Error, "snap.store.channels: list channels such as stable or latest/edge"
83
+ end
84
+ end
85
+
86
+ def filename(version, target) = "#{name}_#{version}_#{self.class.architecture(target)}.snap"
87
+
88
+ def doctor(target)
89
+ self.class.architecture(target)
90
+ raise Error, "install mksquashfs (squashfs-tools) to build snaps" unless available?("mksquashfs")
91
+ end
92
+
93
+ # Returns the snap's path and what went into it.
94
+ def build(package, target, destination, version:, epoch:)
95
+ doctor(target)
96
+ raise Error, "snap versions are at most 32 characters" if version.length > 32
97
+ output = destination / filename(version, target)
98
+ Dir.mktmpdir("native-packages-snap-") do |directory|
99
+ prime = Pathname.new(directory) / "prime"
100
+ prime.mkpath
101
+ stage(package, prime, "snap")
102
+ raise Error, "snap: the package must not install /meta or /snap, which the snap's own metadata uses" if (prime / "meta").exist? || (prime / "snap").exist?
103
+ apps = settings.fetch("apps").to_h { |app, definition| [app, integrate(prime, app, definition)] }
104
+ if settings["icon"]
105
+ icon = inside(prime, settings["icon"], "snap")
106
+ raise Error, "snap.icon: the package installs no #{settings['icon']}" unless icon.file?
107
+ write(prime / "meta/gui/icon#{icon.extname}", icon.binread)
108
+ apps.each_key do |app|
109
+ desktop = prime / "meta/gui/#{app}.desktop"
110
+ write(desktop, desktop.read.gsub(/^Icon=.*$/, "Icon=${SNAP}/meta/gui/icon#{icon.extname}")) if desktop.file?
111
+ end
112
+ end
113
+ write(prime / "meta/snap.yaml", YAML.dump(metadata(package, version, target, apps)).delete_prefix("---\n"))
114
+ normalize(prime, epoch)
115
+ run "mksquashfs", prime, output, "-noappend", "-comp", "xz", "-no-fragments", "-no-progress", "-quiet", "-all-root", "-no-xattrs",
116
+ env: { "SOURCE_DATE_EPOCH" => epoch.to_s }
117
+ check(output)
118
+ [output, { "name" => name, "base" => settings.fetch("base"), "confinement" => settings.fetch("confinement", "strict"),
119
+ "apps" => apps.keys, "libraries" => "base" }]
120
+ end
121
+ end
122
+
123
+ # meta/snap.yaml. The summary, description and license default to the
124
+ # package's.
125
+ def metadata(package, version, target, apps)
126
+ result = { "name" => name, "version" => version, "summary" => settings.fetch("summary", package.fetch("description").lines.first.strip),
127
+ "description" => settings.fetch("description", package.fetch("description")) }
128
+ result["title"] = settings["title"] if settings["title"]
129
+ license = settings.fetch("license", package["license"])
130
+ result["license"] = license if license
131
+ result.merge!("base" => settings.fetch("base"), "grade" => settings.fetch("grade", "stable"),
132
+ "confinement" => settings.fetch("confinement", "strict"), "architectures" => [self.class.architecture(target)], "apps" => apps)
133
+ %w[plugs slots layout environment].each { |key| result[key] = settings[key] if settings[key] }
134
+ result
135
+ end
136
+
137
+ # Checks the app's command and puts its desktop entry in meta/gui, where
138
+ # snapd looks for it, launching the snap's app.
139
+ def integrate(prime, app, definition)
140
+ command = Shellwords.split(definition.fetch("command")).first.delete_prefix("$SNAP/")
141
+ executable = prime / relative_path(command)
142
+ raise Error, "snap.apps.#{app}.command: the package installs no executable #{command}" unless executable.file? && executable.executable?
143
+ if (desktop = definition["desktop"])
144
+ source = inside(prime, desktop.start_with?("/") ? desktop : "/#{desktop}", "snap")
145
+ raise Error, "snap.apps.#{app}.desktop: the package installs no #{desktop}" unless source.file?
146
+ launcher = app == name ? name : "#{name}.#{app}"
147
+ entry = source.read.gsub(/^Exec=(\S+)/) { "Exec=#{launcher}" }
148
+ write(prime / "meta/gui/#{app}.desktop", entry)
149
+ end
150
+ definition.except("desktop")
151
+ end
152
+
153
+ # Fails unless `path` is a squashfs image, the format of every snap.
154
+ def check(path)
155
+ raise Error, "not a snap (squashfs) file: #{path}" unless path.binread(4) == "hsqs".b
156
+ end
157
+
158
+ def publish(paths)
159
+ channels = settings.dig("store", "channels") or raise Error, "configure snap.store.channels to publish --to snapcraft"
160
+ raise Error, "set #{CREDENTIALS} to a Snap Store login from snapcraft export-login" if ENV.fetch(CREDENTIALS, "").empty?
161
+ raise Error, "install snapcraft to publish to the Snap Store" unless available?("snapcraft")
162
+ raise Error, "the build contains no snaps" if paths.empty?
163
+ paths.each { |path| run "snapcraft", "upload", "--release=#{channels.join(',')}", path }
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NativePackages
4
+ # Lays out a package's nFPM contents as a directory tree, for the formats
5
+ # nFPM does not write (AppImage, Flatpak and Snap), and fixes its modes and
6
+ # times so the same inputs give the same bytes.
7
+ module Staging
8
+ include Support
9
+
10
+ # nFPM overrides replace the contents list when one is supplied.
11
+ def contents(package, packager)
12
+ package.fetch("overrides", {}).fetch(packager, {}).fetch("contents", package.fetch("contents"))
13
+ .reject { |item| item["packager"] && item["packager"] != packager }
14
+ end
15
+
16
+ def inside(tree, destination, packager)
17
+ raise Error, "#{packager}: content destinations must be absolute: #{destination}" unless destination.to_s.start_with?("/")
18
+ tree / relative_path(destination.to_s.delete_prefix("/"))
19
+ end
20
+
21
+ def stage(package, tree, packager)
22
+ contents(package, packager).each do |item|
23
+ type = item.fetch("type", "file")
24
+ next if type == "ghost"
25
+ target = inside(tree, item.fetch("dst"), packager)
26
+ mode = item.dig("file_info", "mode")
27
+ case type
28
+ when "dir"
29
+ target.mkpath
30
+ when "symlink"
31
+ target.dirname.mkpath
32
+ File.symlink(item.fetch("src"), target)
33
+ when "file", "tree", "config", "config|noreplace", "config|missingok"
34
+ source = File.expand_path(item.fetch("src"), root)
35
+ paths = package["disable_globbing"] ? [source].select { |path| File.exist?(path) } : Dir.glob(source).sort
36
+ raise Error, "missing package content: #{source}" if paths.empty?
37
+ # As nFPM does: a glob source, or a destination ending in a slash,
38
+ # makes the destination a directory that takes each match's name.
39
+ pattern = !package["disable_globbing"] && item.fetch("src").match?(/[*?\[{]/)
40
+ single = paths.length == 1 && File.file?(paths.first) && type != "tree" && !pattern && !item.fetch("dst").end_with?("/")
41
+ paths.each do |path|
42
+ if File.directory?(path)
43
+ target.mkpath
44
+ FileUtils.cp_r(Dir.children(path).map { |child| File.join(path, child) }, target)
45
+ else
46
+ file = single ? target : target / File.basename(path)
47
+ file.dirname.mkpath
48
+ FileUtils.cp(path, file)
49
+ file.chmod(mode) if mode
50
+ end
51
+ end
52
+ else
53
+ raise Error, "#{packager}: unsupported content type #{type}"
54
+ end
55
+ end
56
+ end
57
+
58
+ # The same bytes for the same inputs: fixed modes and times.
59
+ def normalize(tree, epoch)
60
+ time = Time.at(epoch)
61
+ Pathname.glob(tree / "**/*", File::FNM_DOTMATCH).each do |path|
62
+ next if path.basename.to_s == "."
63
+ if path.symlink?
64
+ File.lutime(time, time, path)
65
+ else
66
+ path.chmod(path.directory? || path.executable? ? 0o755 : 0o644)
67
+ File.utime(time, time, path)
68
+ end
69
+ end
70
+ tree.chmod(0o755)
71
+ File.utime(time, time, tree)
72
+ end
73
+ end
74
+ end
@@ -12,7 +12,7 @@ require "tmpdir"
12
12
  require "yaml"
13
13
 
14
14
  module NativePackages
15
- VERSION = "0.11.0"
15
+ VERSION = "0.13.0"
16
16
  class Error < StandardError; end
17
17
 
18
18
  module Support
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: native-packages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carmine Paolino
@@ -25,6 +25,7 @@ files:
25
25
  - docs/_guides/distribution-recipes.md
26
26
  - docs/_guides/getting-started.md
27
27
  - docs/_guides/github-actions.md
28
+ - docs/_guides/hosted-repositories.md
28
29
  - docs/_guides/multi-platform.md
29
30
  - docs/_guides/native-recipes.md
30
31
  - docs/_guides/omarchy.md
@@ -47,6 +48,7 @@ files:
47
48
  - docs/platforms.md
48
49
  - docs/releasing.md
49
50
  - examples/native-packages-all-formats.yaml
51
+ - examples/native-packages-linux-distribution.yaml
50
52
  - examples/native-packages.yaml
51
53
  - examples/packaging/arch/example-app-bin/PKGBUILD.in
52
54
  - examples/packaging/nfpm.yml
@@ -55,17 +57,26 @@ files:
55
57
  - exe/native-packages
56
58
  - lib/native_packages.rb
57
59
  - lib/native_packages/appimage.rb
60
+ - lib/native_packages/apt_repository.rb
58
61
  - lib/native_packages/build.rb
59
62
  - lib/native_packages/cli.rb
60
63
  - lib/native_packages/configuration.rb
64
+ - lib/native_packages/dnf_repository.rb
65
+ - lib/native_packages/flatpak.rb
66
+ - lib/native_packages/flatpak_repository.rb
67
+ - lib/native_packages/hosted_repository.rb
61
68
  - lib/native_packages/inspection.rb
62
69
  - lib/native_packages/macos_signing.rb
63
70
  - lib/native_packages/native_recipe.rb
64
71
  - lib/native_packages/omarchy.rb
72
+ - lib/native_packages/openpgp.rb
73
+ - lib/native_packages/pacman_repository.rb
65
74
  - lib/native_packages/project.rb
66
75
  - lib/native_packages/release_signing.rb
67
76
  - lib/native_packages/repositories.rb
68
77
  - lib/native_packages/scaffold.rb
78
+ - lib/native_packages/snap.rb
79
+ - lib/native_packages/staging.rb
69
80
  - lib/native_packages/support.rb
70
81
  - lib/native_packages/windows_signing.rb
71
82
  homepage: https://github.com/crmne/native-packages