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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -1
- data/README.md +2 -1
- data/docs/_guides/apple-notarization.md +2 -0
- data/docs/_guides/building-packages.md +5 -0
- data/docs/_guides/distribution-recipes.md +2 -1
- data/docs/_guides/getting-started.md +4 -2
- data/docs/_guides/github-actions.md +4 -4
- data/docs/_guides/hosted-repositories.md +213 -0
- data/docs/_guides/native-recipes.md +3 -1
- data/docs/_guides/publishing.md +19 -0
- data/docs/_guides/release-signing.md +3 -3
- data/docs/_guides/windows-signing.md +4 -2
- data/docs/_reference/commands.md +4 -3
- data/docs/_reference/configuration.md +8 -3
- data/docs/_reference/platforms.md +123 -6
- data/docs/_reference/troubleshooting.md +2 -2
- data/docs/index.md +4 -4
- 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 +180 -0
- data/lib/native_packages/build.rb +41 -2
- data/lib/native_packages/configuration.rb +29 -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 +97 -0
- data/lib/native_packages/inspection.rb +3 -2
- data/lib/native_packages/macos_signing.rb +20 -2
- data/lib/native_packages/openpgp.rb +116 -0
- data/lib/native_packages/pacman_repository.rb +202 -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 +12 -1
data/docs/index.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
layout: home
|
|
3
3
|
title: native-packages
|
|
4
|
+
seo:
|
|
5
|
+
title: DEB, RPM, AppImage, DMG and MSI from one config
|
|
4
6
|
description: Turn your built application into Linux packages, macOS disk images, and Windows installers. Publish releases from one configuration.
|
|
5
7
|
permalink: /
|
|
6
8
|
hero:
|
|
@@ -11,9 +13,7 @@ hero:
|
|
|
11
13
|
- theme: brand
|
|
12
14
|
text: Get started
|
|
13
15
|
link: /getting-started/
|
|
14
|
-
-
|
|
15
|
-
text: GitHub
|
|
16
|
-
link: https://github.com/crmne/native-packages
|
|
16
|
+
- star: true
|
|
17
17
|
image:
|
|
18
18
|
src: /assets/images/logo.svg
|
|
19
19
|
alt: native-packages logo
|
|
@@ -25,7 +25,7 @@ features:
|
|
|
25
25
|
details: Describe your app's files, package metadata, and build targets in a single YAML file.
|
|
26
26
|
- icon: 🐧
|
|
27
27
|
title: Linux packages
|
|
28
|
-
details: Create DEB, RPM, AppImage, Arch, Alpine, and IPK packages from your compatible Linux builds.
|
|
28
|
+
details: Create DEB, RPM, AppImage, Flatpak, Snap, Arch, Alpine, and IPK packages from your compatible Linux builds.
|
|
29
29
|
- icon: 🖥️
|
|
30
30
|
title: Native installers
|
|
31
31
|
details: Connect your macOS DMG script and your Windows MSI or Inno Setup script, or package Windows apps as MSIX.
|
data/docs/releasing.md
CHANGED
|
@@ -23,7 +23,7 @@ Update the gemspec, `NativePackages::VERSION`, example/version references and ch
|
|
|
23
23
|
Create a GitHub release for that commit:
|
|
24
24
|
|
|
25
25
|
```sh
|
|
26
|
-
gh release create v0.
|
|
26
|
+
gh release create v0.12.0 --target main --title 'native-packages 0.12.0' --notes-file release-notes.md
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
Adding `--draft` permits review before publication and does not trigger the publisher. The tag must match the exact gem version and point to a commit on `main`. Set `--prerelease` only for a prerelease gem version.
|
|
@@ -36,7 +36,7 @@ If the workflow itself needs a correction, fix it on `main` and dispatch the
|
|
|
36
36
|
corrected release workflow against the existing published tag:
|
|
37
37
|
|
|
38
38
|
```sh
|
|
39
|
-
gh workflow run release.yml --ref main -f tag=v0.
|
|
39
|
+
gh workflow run release.yml --ref main -f tag=v0.12.0
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
Validation resolves the original tag to an exact commit, requires it to be on
|
|
@@ -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.13.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,180 @@
|
|
|
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[name 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/#{repository}.gpg #{url}/#{repository}.gpg",
|
|
125
|
+
"sudo curl -fsSLo /etc/apt/sources.list.d/#{repository}.sources #{url}/#{repository}.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 / "#{repository}.gpg", signing.public_key)
|
|
150
|
+
write(directory / "#{repository}.sources", <<~SOURCES)
|
|
151
|
+
Types: deb
|
|
152
|
+
URIs: #{url}
|
|
153
|
+
Suites: #{suite}
|
|
154
|
+
Components: #{component}
|
|
155
|
+
Signed-By: /etc/apt/keyrings/#{repository}.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: #{repository}", "Label: #{repository}", "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: #{repository} 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
|
+
end
|
|
180
|
+
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 pacman 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,16 @@ 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 == "pacman"
|
|
446
|
+
PacmanRepository.new(configuration).publish(packages(manifest, output, "archlinux"), **signing)
|
|
447
|
+
elsif destination == "flatpak"
|
|
448
|
+
FlatpakRepository.new(configuration).publish(packages(manifest, output, "flatpak"), **signing)
|
|
449
|
+
elsif destination == "snapcraft"
|
|
450
|
+
Snap.new(configuration).publish(packages(manifest, output, "snap"))
|
|
417
451
|
else
|
|
418
452
|
project.repositories.stage(destination, output / "recipes")
|
|
419
453
|
project.repositories.publish(destination, body_file: body_file)
|
|
@@ -421,6 +455,11 @@ module NativePackages
|
|
|
421
455
|
end
|
|
422
456
|
end
|
|
423
457
|
|
|
458
|
+
# The build's packages of `format`.
|
|
459
|
+
def packages(manifest, output, format)
|
|
460
|
+
manifest.fetch("packages").select { |entry| entry.fetch("format") == format }.map { |entry| output / entry.fetch("path") }
|
|
461
|
+
end
|
|
462
|
+
|
|
424
463
|
def aggregate(inputs, output:, finalize_recipes: false)
|
|
425
464
|
configuration.validate
|
|
426
465
|
output = Pathname.new(output).expand_path(root)
|
|
@@ -2,16 +2,27 @@
|
|
|
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 "pacman_repository"
|
|
5
11
|
require_relative "windows_signing"
|
|
6
12
|
|
|
7
13
|
module NativePackages
|
|
8
14
|
class Configuration
|
|
9
15
|
include Support
|
|
10
16
|
NATIVE_FORMATS = %w[dmg inno msi].freeze
|
|
11
|
-
|
|
17
|
+
# Formats native-packages writes itself from the package's contents,
|
|
18
|
+
# without nFPM.
|
|
19
|
+
IMAGE_FORMATS = %w[appimage flatpak snap].freeze
|
|
20
|
+
# Publish destinations besides the configured downstream repositories.
|
|
21
|
+
DESTINATIONS = %w[github snapcraft apt dnf pacman flatpak].freeze
|
|
22
|
+
FORMATS = (%w[deb rpm archlinux apk ipk msix srpm appimage flatpak snap] + NATIVE_FORMATS).freeze
|
|
12
23
|
NFPM_VERSION = "2.47.0"
|
|
13
24
|
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
|
|
25
|
+
KEYS = %w[schema tool nfpm targets release assets templates repositories revisions libraries version_file version_section windows flatpak snap apt dnf pacman].freeze
|
|
15
26
|
attr_reader :root, :path, :data
|
|
16
27
|
|
|
17
28
|
def self.discover(root, explicit = nil)
|
|
@@ -129,6 +140,14 @@ module NativePackages
|
|
|
129
140
|
elsif target.key?("appimage")
|
|
130
141
|
raise Error, "#{id}.appimage: only for targets that build an AppImage"
|
|
131
142
|
end
|
|
143
|
+
if formats.include?("flatpak")
|
|
144
|
+
raise Error, "#{id}: Flatpak requires a Linux binary target" unless target["platform"] == "linux" && kind == "binary"
|
|
145
|
+
Flatpak.architecture(target)
|
|
146
|
+
end
|
|
147
|
+
if formats.include?("snap")
|
|
148
|
+
raise Error, "#{id}: Snap requires a Linux binary target" unless target["platform"] == "linux" && kind == "binary"
|
|
149
|
+
Snap.architecture(target)
|
|
150
|
+
end
|
|
132
151
|
begin
|
|
133
152
|
update_information(target, "9.8.7")
|
|
134
153
|
rescue Error => error
|
|
@@ -162,11 +181,19 @@ module NativePackages
|
|
|
162
181
|
render_tree(target["before_build"], target_tokens(metadata, id, target, "/payload")) if target["before_build"]
|
|
163
182
|
render_tree(target["after_package"], target_tokens(metadata, id, target, "/payload").merge("PACKAGE" => "/output/package", "FORMAT" => formats.first)) if target["after_package"]
|
|
164
183
|
end
|
|
184
|
+
reserved = data.fetch("repositories").keys & DESTINATIONS
|
|
185
|
+
raise Error, "repositories.#{reserved.first}: that name is a built-in publish destination; choose another" unless reserved.empty?
|
|
165
186
|
data.fetch("templates").each do |destination, source|
|
|
166
187
|
relative_path(render(destination, metadata))
|
|
167
188
|
render((root / relative_path(source)).binread, metadata)
|
|
168
189
|
end
|
|
169
190
|
WindowsSigning.validate(data)
|
|
191
|
+
Flatpak.validate(data)
|
|
192
|
+
Snap.validate(data)
|
|
193
|
+
AptRepository.validate(data)
|
|
194
|
+
DnfRepository.validate(data)
|
|
195
|
+
PacmanRepository.validate(data)
|
|
196
|
+
FlatpakRepository.validate(data)
|
|
170
197
|
project.repositories
|
|
171
198
|
true
|
|
172
199
|
end
|