Skip to content

Commit eb73c6c

Browse files
committed
refactor(ci): extract single-architecture Snap build workflow
Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent 80c7072 commit eb73c6c

4 files changed

Lines changed: 193 additions & 153 deletions

File tree

‎.github/workflows/build-snap.yml‎

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Build Snap
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
checkout-ref:
10+
required: true
11+
type: string
12+
arch:
13+
description: "Snap package architecture"
14+
required: true
15+
type: string
16+
runner:
17+
description: "GitHub Actions runner label"
18+
required: true
19+
type: string
20+
cli-artifact-name:
21+
required: true
22+
type: string
23+
gateway-artifact-name:
24+
required: true
25+
type: string
26+
supervisor-artifact-name:
27+
required: true
28+
type: string
29+
upload-channel:
30+
required: false
31+
type: string
32+
default: ""
33+
description: "Snap Store channel to upload to; leave empty to skip upload"
34+
35+
secrets:
36+
publish-credentials:
37+
required: false
38+
description: "Snap Store credentials (SNAPCRAFT_STORE_CREDENTIALS)"
39+
permissions:
40+
contents: read
41+
42+
defaults:
43+
run:
44+
shell: bash
45+
46+
jobs:
47+
build-snap:
48+
name: Build Snap (Linux ${{ inputs.arch }})
49+
runs-on: ${{ inputs.runner }}
50+
timeout-minutes: 60
51+
environment: ${{ inputs.upload-channel != '' && inputs.upload-channel || '' }}
52+
steps:
53+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
54+
with:
55+
ref: ${{ inputs.checkout-ref }}
56+
fetch-depth: 0
57+
58+
- name: Install snapd
59+
run: |
60+
set -euo pipefail
61+
if ! command -v snapd >/dev/null 2>&1; then
62+
sudo apt-get update
63+
sudo apt-get install -y snapd
64+
fi
65+
sudo systemctl enable --now snapd.socket
66+
sudo systemctl start snapd
67+
sudo snap wait system seed.loaded
68+
69+
- name: Install LXD
70+
run: |
71+
set -euo pipefail
72+
sudo snap install lxd
73+
sudo usermod -aG lxd "$USER"
74+
sudo lxd waitready
75+
sudo lxd init --auto
76+
sudo iptables -P FORWARD ACCEPT
77+
sudo chgrp lxd /var/snap/lxd/common/lxd/unix.socket
78+
sudo chmod 660 /var/snap/lxd/common/lxd/unix.socket
79+
80+
- name: Install snapcraft
81+
run: sudo snap install snapcraft --classic
82+
83+
- name: Download prebuilt CLI binary
84+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
85+
with:
86+
name: ${{ inputs.cli-artifact-name }}
87+
path: prebuilt/cli
88+
89+
- name: Download prebuilt gateway binary
90+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
91+
with:
92+
name: ${{ inputs.gateway-artifact-name }}
93+
path: prebuilt/gateway
94+
95+
- name: Download prebuilt sandbox binary
96+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
97+
with:
98+
name: ${{ inputs.supervisor-artifact-name }}
99+
path: prebuilt/sandbox
100+
101+
- name: Prepare snap build directory
102+
run: |
103+
set -euo pipefail
104+
find_binary() {
105+
find "$1" -type f -name "$2" -print -quit
106+
}
107+
cli="$(find_binary prebuilt/cli openshell)"
108+
gateway="$(find_binary prebuilt/gateway openshell-gateway)"
109+
sandbox="$(find_binary prebuilt/sandbox openshell-sandbox)"
110+
test -n "$cli" && test -n "$gateway" && test -n "$sandbox"
111+
112+
mkdir -p snap/prebuilt/meta/gui
113+
install -m 0755 "$cli" snap/prebuilt/openshell
114+
install -m 0755 "$gateway" snap/prebuilt/openshell-gateway
115+
install -m 0755 "$sandbox" snap/prebuilt/openshell-sandbox
116+
install -m 0755 tasks/scripts/snap-gateway-wrapper.sh snap/prebuilt/openshell-gateway-wrapper
117+
cp LICENSE README.md snap/prebuilt/
118+
cp snap/local/term.desktop snap/prebuilt/meta/gui/term.desktop
119+
cp snap/local/icon.png snap/prebuilt/meta/gui/icon.png
120+
python3 tasks/scripts/release.py get-version --snap > snap/prebuilt/version
121+
122+
- name: Build snap
123+
run: |
124+
set -euo pipefail
125+
runtime_dir="/run/user/$(id -u)"
126+
sudo install -d -m 0700 -o "$(id -u)" -g "$(id -g)" "$runtime_dir"
127+
export XDG_RUNTIME_DIR="$runtime_dir"
128+
sg lxd -c "XDG_RUNTIME_DIR=${runtime_dir} snapcraft pack -v"
129+
130+
- name: Upload snapcraft logs on failure
131+
if: failure()
132+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
133+
with:
134+
name: snapcraft-logs-${{ inputs.arch }}
135+
path: "~/.local/state/snapcraft/log/snapcraft-*.log"
136+
retention-days: 7
137+
138+
- name: Capture Snap filename
139+
id: capture
140+
run: |
141+
set -euo pipefail
142+
snap_file=$(find . -maxdepth 1 -type f -name '*.snap' -printf '%f\n' | head -1)
143+
if [ -z "$snap_file" ]; then
144+
echo "::error::No .snap file found after snapcraft pack"
145+
exit 1
146+
fi
147+
echo "snap-file=$snap_file" >> "$GITHUB_OUTPUT"
148+
echo "Built Snap: $snap_file"
149+
150+
- name: Upload snap artifact (${{ inputs.arch }})
151+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
152+
with:
153+
name: snap-linux-${{ inputs.arch }}
154+
path: |
155+
${{ steps.capture.outputs.snap-file }}
156+
*.comp
157+
retention-days: 5
158+
159+
- name: Upload Snap to Snap Store
160+
if: inputs.upload-channel != ''
161+
env:
162+
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.publish-credentials }}
163+
INPUTS_UPLOAD_CHANNEL: ${{ inputs.upload-channel }}
164+
run: |
165+
set -euo pipefail
166+
snap_file="${{ steps.capture.outputs.snap-file }}"
167+
snap_name="${snap_file%.snap}"
168+
snap_name="${snap_name%%_*}"
169+
170+
component_args=()
171+
shopt -s nullglob
172+
for component in "${snap_name}"+*.comp; do
173+
echo "Adding component: $component"
174+
component_args+=(--component "$component")
175+
done
176+
177+
echo "Uploading $snap_file to ${INPUTS_UPLOAD_CHANNEL}"
178+
snapcraft upload --release "${INPUTS_UPLOAD_CHANNEL}" "$snap_file" "${component_args[@]}"

‎.github/workflows/release-dev.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ jobs:
256256
with:
257257
checkout-ref: ${{ github.sha }}
258258
upload-channel: latest/edge
259-
github-environment: latest/edge
260259
secrets:
261260
publish-credentials: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}
262261

‎.github/workflows/release-tag.yml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,7 @@ jobs:
310310
uses: ./.github/workflows/snap-package.yml
311311
with:
312312
checkout-ref: ${{ inputs.tag || github.ref }}
313-
upload-channel: ${{ needs.compute-versions.outputs.is_prerelease == 'true' && 'latest/edge' || 'latest/stable' }}
314-
github-environment: ${{ needs.compute-versions.outputs.is_prerelease == 'true' && 'latest/edge' || 'latest/stable' }}
315-
publish: ${{ needs.compute-versions.outputs.is_prerelease != 'true' }}
313+
upload-channel: ${{ needs.compute-versions.outputs.is_prerelease != 'true' && 'latest/stable' || '' }}
316314
secrets:
317315
publish-credentials: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}
318316

‎.github/workflows/snap-package.yml‎

Lines changed: 14 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,14 @@ on:
1010
required: true
1111
type: string
1212
upload-channel:
13-
required: true
13+
required: false
1414
type: string
15+
default: ""
1516
description: "Snap Store channel to upload to (e.g., latest/edge, latest/candidate, latest/stable)"
16-
github-environment:
17-
required: true
18-
type: string
19-
description: "GitHub deployment environment for approval gates (e.g., latest/edge, latest/stable)"
20-
publish:
21-
required: false
22-
type: boolean
23-
default: true
24-
description: "Whether to upload the built snap to the Snap Store"
2517

2618
secrets:
2719
publish-credentials:
28-
required: true
20+
required: false
2921
description: "Snap Store credentials (SNAPCRAFT_STORE_CREDENTIALS)"
3022

3123
permissions:
@@ -47,141 +39,14 @@ jobs:
4739
- arch: arm64
4840
rust_arch: aarch64
4941
runner: linux-arm64-cpu8
50-
runs-on: ${{ matrix.runner }}
51-
timeout-minutes: 60
52-
environment: ${{ inputs.github-environment }}
53-
steps:
54-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
55-
with:
56-
ref: ${{ inputs.checkout-ref }}
57-
fetch-depth: 0
58-
59-
- name: Install snapd
60-
run: |
61-
set -euo pipefail
62-
if ! command -v snapd >/dev/null 2>&1; then
63-
sudo apt-get update
64-
sudo apt-get install -y snapd
65-
fi
66-
sudo systemctl enable --now snapd.socket
67-
sudo systemctl start snapd
68-
sudo snap wait system seed.loaded
69-
70-
- name: Install LXD
71-
run: |
72-
set -euo pipefail
73-
sudo snap install lxd
74-
sudo usermod -aG lxd "$USER"
75-
sudo lxd waitready
76-
sudo lxd init --auto
77-
sudo iptables -P FORWARD ACCEPT
78-
sudo chgrp lxd /var/snap/lxd/common/lxd/unix.socket
79-
sudo chmod 660 /var/snap/lxd/common/lxd/unix.socket
80-
81-
- name: Install snapcraft
82-
run: |
83-
set -euo pipefail
84-
sudo snap install snapcraft --classic
85-
86-
- name: Download prebuilt CLI binary
87-
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
88-
with:
89-
name: openshell-${{ matrix.rust_arch }}-unknown-linux-musl
90-
path: prebuilt/cli
91-
92-
- name: Download prebuilt gateway binary
93-
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
94-
with:
95-
name: openshell-gateway-${{ matrix.rust_arch }}-unknown-linux-gnu
96-
path: prebuilt/gateway
97-
98-
- name: Download prebuilt sandbox binary
99-
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
100-
with:
101-
name: openshell-sandbox-${{ matrix.rust_arch }}-unknown-linux-musl
102-
path: prebuilt/sandbox
103-
104-
- name: Configure prebuilt binaries
105-
run: |
106-
set -euo pipefail
107-
chmod +x prebuilt/cli/openshell
108-
chmod +x prebuilt/gateway/openshell-gateway
109-
chmod +x prebuilt/sandbox/openshell-sandbox
110-
ls -laR prebuilt/
111-
112-
- name: Prepare snap build directory
113-
run: |
114-
set -euo pipefail
115-
mkdir -p snap/prebuilt
116-
117-
cp prebuilt/cli/openshell snap/prebuilt/openshell
118-
cp prebuilt/gateway/openshell-gateway snap/prebuilt/openshell-gateway
119-
cp prebuilt/sandbox/openshell-sandbox snap/prebuilt/openshell-sandbox
120-
121-
cp tasks/scripts/snap-gateway-wrapper.sh snap/prebuilt/openshell-gateway-wrapper
122-
cp LICENSE snap/prebuilt/
123-
cp README.md snap/prebuilt/
124-
125-
mkdir -p snap/prebuilt/meta/gui
126-
cp snap/local/term.desktop snap/prebuilt/meta/gui/term.desktop
127-
cp snap/local/icon.png snap/prebuilt/meta/gui/icon.png
128-
129-
python3 tasks/scripts/release.py get-version --snap > snap/prebuilt/version
130-
131-
- name: Build snap
132-
run: |
133-
set -euo pipefail
134-
runtime_dir="/run/user/$(id -u)"
135-
sudo install -d -m 0700 -o "$(id -u)" -g "$(id -g)" "$runtime_dir"
136-
export XDG_RUNTIME_DIR="$runtime_dir"
137-
sg lxd -c "XDG_RUNTIME_DIR=${runtime_dir} snapcraft pack -v"
138-
139-
- name: Upload snapcraft logs on failure
140-
if: failure()
141-
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
142-
with:
143-
name: snapcraft-logs
144-
path: "~/.local/state/snapcraft/log/snapcraft-*.log"
145-
retention-days: 7
146-
147-
- name: Capture snap filename
148-
id: capture
149-
run: |
150-
set -euo pipefail
151-
SNAP_FILE=$(ls -1 *.snap 2>/dev/null | head -1)
152-
if [ -z "$SNAP_FILE" ]; then
153-
echo "ERROR: No .snap file found after snapcraft pack"
154-
exit 1
155-
fi
156-
echo "snap-file=${SNAP_FILE}" >> $GITHUB_OUTPUT
157-
echo "Built snap: ${SNAP_FILE}"
158-
159-
- name: Upload snap artifact (${{ matrix.arch }})
160-
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
161-
with:
162-
name: snap-linux-${{ matrix.arch }}
163-
path: |
164-
${{ steps.capture.outputs.snap-file }}
165-
*.comp
166-
retention-days: 5
167-
168-
- name: Upload snap to Snap Store
169-
if: inputs.publish
170-
env:
171-
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.publish-credentials }}
172-
INPUTS_UPLOAD_CHANNEL: ${{ inputs.upload-channel }}
173-
run: |
174-
set -euo pipefail
175-
SNAP_FILE="${{ steps.capture.outputs.snap-file }}"
176-
SNAP_NAME="${SNAP_FILE%.snap}"
177-
SNAP_NAME="${SNAP_NAME%%_*}"
178-
179-
COMPONENT_ARGS=()
180-
shopt -s nullglob
181-
for comp in "${SNAP_NAME}"+*.comp; do
182-
echo "Adding component: $comp"
183-
COMPONENT_ARGS+=(--component "$comp")
184-
done
185-
186-
echo "Uploading $SNAP_FILE to ${INPUTS_UPLOAD_CHANNEL}"
187-
snapcraft upload --release "${INPUTS_UPLOAD_CHANNEL}" "$SNAP_FILE" "${COMPONENT_ARGS[@]}"
42+
uses: ./.github/workflows/build-snap.yml
43+
with:
44+
checkout-ref: ${{ inputs.checkout-ref }}
45+
arch: ${{ matrix.arch }}
46+
runner: ${{ matrix.runner }}
47+
cli-artifact-name: openshell-${{ matrix.rust_arch }}-unknown-linux-musl
48+
gateway-artifact-name: openshell-gateway-${{ matrix.rust_arch }}-unknown-linux-gnu
49+
supervisor-artifact-name: openshell-sandbox-${{ matrix.rust_arch }}-unknown-linux-musl
50+
upload-channel: ${{ inputs.upload-channel }}
51+
secrets:
52+
publish-credentials: ${{ secrets.publish-credentials }}

0 commit comments

Comments
 (0)