Skip to content

Commit a36642e

Browse files
committed
fix snapcraft libusb
1 parent 9da6ae2 commit a36642e

4 files changed

Lines changed: 103 additions & 28 deletions

File tree

.github/workflows/release.yml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ jobs:
175175
> "completions/restorekit.$shell"
176176
done
177177
178-
- name: Install snapcraft
179-
run: sudo snap install snapcraft --classic
180-
181178
- uses: goreleaser/goreleaser-action@v6
182179
with:
183180
distribution: goreleaser
@@ -187,4 +184,55 @@ jobs:
187184
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
188185
# One token for both the Homebrew tap and the Scoop bucket.
189186
TAP_GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
187+
188+
# Pack the CLI binary into a snap and publish it to the Snap Store as
189+
# `restorekit-cli` (the plain `restorekit` name is the desktop app, published
190+
# from release-app.yml). GoReleaser can't do this: the binary links libusb
191+
# dynamically, core24 doesn't ship libusb-1.0.so.0, and its `snapcrafts`
192+
# block has no `stage-packages` escape hatch.
193+
#
194+
# One runner per arch — destructive mode builds on the host directly, so
195+
# stage-packages can only pull the host's debs, and ubuntu-24.04 matches the
196+
# snap's core24 base. Pack runs under sudo (snapcraft shells out to `snap`,
197+
# which snapd only allows as root) and swallows snap's stderr, so dump its
198+
# log on failure to see the real error.
199+
snap:
200+
# After `release`, not just `build`, so a failed GitHub release can't leave
201+
# a published snap behind (the ordering GoReleaser gave us before).
202+
needs: [release]
203+
strategy:
204+
fail-fast: false
205+
matrix:
206+
include:
207+
- os: ubuntu-24.04
208+
goarch: amd64
209+
- os: ubuntu-24.04-arm
210+
goarch: arm64
211+
runs-on: ${{ matrix.os }}
212+
steps:
213+
- uses: actions/checkout@v4
214+
215+
- name: Download the prebuilt binary
216+
uses: actions/download-artifact@v4
217+
with:
218+
name: restorekit_linux_${{ matrix.goarch }}
219+
path: snapbuild/bin
220+
221+
- name: Build & publish the snap
222+
env:
190223
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}
224+
run: |
225+
set -euo pipefail
226+
version="${GITHUB_REF_NAME#v}"
227+
sudo snap install snapcraft --classic
228+
# The executable bit doesn't survive the artifact round-trip.
229+
chmod +x snapbuild/bin/restorekit
230+
sed "s/VERSION_PLACEHOLDER/${version}/" crates/restorekit-cli/snap/snapcraft.yaml \
231+
> snapbuild/snapcraft.yaml
232+
cd snapbuild
233+
sudo snapcraft pack --destructive-mode || {
234+
sudo cat /root/.local/state/snapcraft/log/*.log
235+
exit 1
236+
}
237+
snapcraft upload --release=stable \
238+
"restorekit-cli_${version}_${{ matrix.goarch }}.snap"

.goreleaser.yaml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,10 @@ homebrew_casks:
7878
needs root for that step (sudo restorekit dfu). Restores run on macOS
7979
and Linux.
8080
81-
snapcrafts:
82-
# Same naming rationale as the cask: the plain `restorekit` snap name is
83-
# reserved for the desktop app. The app key below is what users type, so
84-
# the command is `restorekit-cli` (the inner binary is still `restorekit`).
85-
- name: restorekit-cli
86-
ids: [restorekit]
87-
title: restorekit
88-
summary: DFU-restore Apple Silicon Macs from the command line
89-
description: |
90-
restorekit lets you fully wipe or restore a T2 or M series mac without
91-
using any apple tools. Plug the target mac into your host's DFU port,
92-
put it in DFU mode (automatic DFU only works from a macOS host), then:
93-
94-
sudo restorekit-cli erase
95-
license: Apache-2.0
96-
grade: stable
97-
confinement: strict
98-
base: core24
99-
publish: true
100-
channel_templates: [stable]
101-
apps:
102-
restorekit-cli:
103-
command: restorekit
104-
plugs: [home, network, raw-usb, removable-media]
81+
# No `snapcrafts:` block — the snap is packed by hand from
82+
# crates/restorekit-cli/snap/snapcraft.yaml in release.yml. The binary links
83+
# libusb dynamically and core24 doesn't ship it, so the snap needs
84+
# `stage-packages`, which GoReleaser's snapcrafts block can't express.
10585

10686
scoops:
10787
# Same naming rationale as the cask: the plain `restorekit` name is reserved

apps/desktop/snap/snapcraft.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ parts:
3737
plugin: dump
3838
source: restorekit.deb
3939
source-type: deb
40-
# GTK3 comes from the gnome extension; webkit2gtk does not.
40+
# GTK3 comes from the gnome extension; webkit2gtk does not. Neither does
41+
# libusb — restorekit-desktop links it dynamically, and it's in neither
42+
# core22 nor gnome-42-2204, so the app dies at exec with
43+
# "libusb-1.0.so.0: cannot open shared object file".
4144
stage-packages:
4245
- libwebkit2gtk-4.1-0
46+
- libusb-1.0-0
4347
override-build: |
4448
craftctl default
4549
sed -i 's|^Icon=.*|Icon=/usr/share/icons/hicolor/128x128/apps/restorekit-desktop.png|' \
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Template for the CLI's snap, packed from the prebuilt binary in release.yml
2+
# (VERSION_PLACEHOLDER is filled in there, same pattern as the desktop app's
3+
# snap). The plain `restorekit` snap name is the desktop app; the CLI ships
4+
# here as `restorekit-cli`. The app key below is what users type, so the
5+
# command is `restorekit-cli` (the inner binary is still `restorekit`).
6+
#
7+
# Hand-written rather than generated by GoReleaser's `snapcrafts` block: the
8+
# binary links libusb dynamically and core24 doesn't ship libusb-1.0.so.0, and
9+
# GoReleaser has no way to add stage-packages to the snap it generates.
10+
#
11+
# base core24 must match the runner the binary is built on (ubuntu-24.04) —
12+
# bump both together. `platforms` is omitted on purpose: it defaults to the
13+
# host architecture, and each arch is packed on its own runner.
14+
name: restorekit-cli
15+
title: restorekit
16+
base: core24
17+
version: "VERSION_PLACEHOLDER"
18+
summary: DFU-restore Apple Silicon Macs from the command line
19+
description: |
20+
restorekit lets you fully wipe or restore a T2 or M series mac without
21+
using any apple tools. Plug the target mac into your host's DFU port,
22+
put it in DFU mode (automatic DFU only works from a macOS host), then:
23+
24+
sudo restorekit-cli erase
25+
26+
license: Apache-2.0
27+
grade: stable
28+
confinement: strict
29+
30+
apps:
31+
restorekit-cli:
32+
command: restorekit
33+
plugs: [home, network, raw-usb, removable-media]
34+
35+
parts:
36+
restorekit:
37+
plugin: dump
38+
# release.yml stages the downloaded binary as bin/restorekit next to this
39+
# file; dumping the directory keeps snapcraft.yaml itself out of the snap.
40+
source: bin
41+
# The one library the "self-contained" binary still links dynamically.
42+
stage-packages:
43+
- libusb-1.0-0

0 commit comments

Comments
 (0)