Skip to content

Commit aba5885

Browse files
authored
ci: add macOS PKG package build support for CLI (#516)
1 parent 3889ccf commit aba5885

File tree

3 files changed

+127
-7
lines changed

3 files changed

+127
-7
lines changed

.github/workflows/release-cli.yml

Lines changed: 120 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,124 @@ jobs:
182182
cli/*.apk
183183
retention-days: 30
184184

185+
build-and-package-macos:
186+
runs-on: ${{ matrix.os }}
187+
strategy:
188+
matrix:
189+
os: [macos-13, macos-14]
190+
191+
steps:
192+
- name: Checkout code
193+
uses: actions/checkout@v4
194+
with:
195+
fetch-depth: 0
196+
ssh-key: ${{ secrets.DEPLOY_KEY }}
197+
198+
- name: Set up Python
199+
uses: actions/setup-python@v4
200+
with:
201+
python-version: "3.11"
202+
203+
- name: Install Poetry
204+
uses: snok/install-poetry@v1
205+
with:
206+
version: latest
207+
virtualenvs-create: true
208+
virtualenvs-in-project: true
209+
210+
- name: Cache dependencies
211+
uses: actions/cache@v3
212+
with:
213+
path: cli/.venv
214+
key: venv-${{ matrix.os }}-${{ hashFiles('cli/poetry.lock') }}
215+
216+
- name: Install dependencies
217+
working-directory: cli
218+
run: poetry install
219+
220+
- name: Extract version from pyproject.toml
221+
id: version
222+
working-directory: cli
223+
run: |
224+
VERSION=$(poetry version --short)
225+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
226+
echo "Extracted version: $VERSION"
227+
228+
- name: Install fpm
229+
run: |
230+
sudo gem install --no-document fpm
231+
232+
- name: Build CLI binary
233+
working-directory: cli
234+
env:
235+
NIXOPUS_DISABLE_DOCKER: "1"
236+
run: |
237+
chmod +x build.sh
238+
if [ ! -d "helpers" ]; then
239+
ln -s ../helpers helpers
240+
fi
241+
echo "Running production build (PyInstaller)"
242+
./build.sh --no-test --no-cleanup --no-archive
243+
244+
- name: Prepare binary for packaging
245+
working-directory: cli
246+
run: |
247+
mkdir -p packaging/usr/local/bin
248+
if [ -f "dist/nixopus" ]; then
249+
cp dist/nixopus packaging/usr/local/bin/
250+
if [ -d "dist/nixopus_darwin_amd64" ]; then
251+
cp -r dist/nixopus_darwin_amd64 packaging/usr/local/bin/
252+
elif [ -d "dist/nixopus_darwin_arm64" ]; then
253+
cp -r dist/nixopus_darwin_arm64 packaging/usr/local/bin/
254+
fi
255+
else
256+
echo "Build output not found in expected location"
257+
ls -la dist/
258+
exit 1
259+
fi
260+
chmod +x packaging/usr/local/bin/nixopus
261+
262+
- name: Set architecture variables
263+
run: |
264+
ARCH=$(uname -m)
265+
case "$ARCH" in
266+
x86_64) PKG_ARCH=amd64 ;;
267+
aarch64|arm64) PKG_ARCH=arm64 ;;
268+
*) PKG_ARCH=$ARCH ;;
269+
esac
270+
echo "ARCH=$ARCH" >> $GITHUB_ENV
271+
echo "PKG_ARCH=$PKG_ARCH" >> $GITHUB_ENV
272+
273+
- name: Create PKG package
274+
working-directory: cli
275+
run: |
276+
VERSION="${{ steps.version.outputs.VERSION }}"
277+
fpm -s dir -t osxpkg \
278+
-n nixopus \
279+
-v "$VERSION" \
280+
-a "$PKG_ARCH" \
281+
--description "A CLI for Nixopus" \
282+
--maintainer "Nixopus <raghavyuva@gmail.com>" \
283+
--license "FSL" \
284+
--url "https://github.com/nixopus/cli" \
285+
--prefix / \
286+
packaging/=/
287+
PKG_SOURCE="nixopus-${VERSION}.pkg"
288+
PKG_TARGET="nixopus-${VERSION}-darwin-$PKG_ARCH.pkg"
289+
mv "$PKG_SOURCE" "$PKG_TARGET"
290+
291+
- name: Upload artifacts
292+
uses: actions/upload-artifact@v4
293+
with:
294+
name: nixopus-packages-${{ matrix.os }}-${{ env.ARCH }}
295+
path: |
296+
cli/*.pkg
297+
retention-days: 30
298+
185299
create-release:
186-
needs: build-and-package
300+
needs:
301+
- build-and-package
302+
- build-and-package-macos
187303
runs-on: ubuntu-22.04
188304
permissions:
189305
contents: write
@@ -212,7 +328,7 @@ jobs:
212328
while IFS= read -r -d '' file; do
213329
filename=$(basename "$file")
214330
PACKAGE_FILES+=("$filename")
215-
done < <(find ./artifacts -type f \( -name "*.deb" -o -name "*.rpm" -o -name "*.tar" -o -name "*.apk" \) -print0)
331+
done < <(find ./artifacts -type f \( -name "*.deb" -o -name "*.rpm" -o -name "*.tar" -o -name "*.apk" -o -name "*.pkg" \) -print0)
216332
217333
echo "Found package files: ${PACKAGE_FILES[@]}"
218334
@@ -256,14 +372,14 @@ jobs:
256372
257373
echo "Creating release with tag: $RELEASE_TAG"
258374
echo "Files to upload:"
259-
find ./artifacts -type f \( -name "*.deb" -o -name "*.rpm" -o -name "*.tar" -o -name "*.apk" \) -exec ls -la {} \;
375+
find ./artifacts -type f \( -name "*.deb" -o -name "*.rpm" -o -name "*.tar" -o -name "*.apk" -o -name "*.pkg" \) -exec ls -la {} \;
260376
261377
gh release create "$RELEASE_TAG" \
262378
--title "Nixopus CLI v$CLI_VERSION" \
263379
--notes "Nixopus CLI v$CLI_VERSION - Packages: DEB, RPM, TAR, APK for x86_64 and ARM64" \
264380
--target ${{ github.ref_name }} \
265381
--prerelease
266382
267-
find ./artifacts -type f \( -name "*.deb" -o -name "*.rpm" -o -name "*.tar" -o -name "*.apk" \) -exec gh release upload "$RELEASE_TAG" {} \;
383+
find ./artifacts -type f \( -name "*.deb" -o -name "*.rpm" -o -name "*.tar" -o -name "*.apk" -o -name "*.pkg" \) -exec gh release upload "$RELEASE_TAG" {} \;
268384
env:
269385
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

cli/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "nixopus"
3-
version = "0.1.13"
3+
version = "0.1.14"
44
description = "A CLI for Nixopus"
55
authors = ["Nixopus <raghavyuva@gmail.com>"]
66
readme = "README.md"

scripts/install.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ detect_arch() {
111111
detect_os() {
112112
case "$(uname -s)" in
113113
Darwin*)
114-
echo "tar" # macOS uses tar fallback
114+
echo "pkg"
115115
;;
116116
Linux*)
117117
if command -v apt &>/dev/null; then
@@ -159,6 +159,7 @@ build_package_name() {
159159
rpm) echo "nixopus-${CLI_VERSION}-1.$([ "$arch" = "amd64" ] && echo "x86_64" || echo "aarch64").rpm" ;;
160160
apk) echo "nixopus_${CLI_VERSION}_${arch}.apk" ;;
161161
tar) echo "nixopus-${CLI_VERSION}.tar" ;;
162+
pkg) echo "nixopus-${CLI_VERSION}-darwin-${arch}.pkg" ;;
162163
*) log_error "Unknown package type: $pkg_type"; exit 1 ;;
163164
esac
164165
}
@@ -228,6 +229,9 @@ install_package() {
228229
fi
229230
fi
230231
;;
232+
pkg)
233+
sudo installer -pkg "$temp_file" -target /
234+
;;
231235
esac
232236

233237
# Cleanup
@@ -263,7 +267,7 @@ install_cli() {
263267
check_permissions() {
264268
local pkg_type="$1"
265269
case "$pkg_type" in
266-
deb|rpm|apk)
270+
deb|rpm|apk|pkg)
267271
if [[ $EUID -ne 0 ]] && ! sudo -n true 2>/dev/null; then
268272
echo "This script requires sudo privileges for package installation."
269273
fi

0 commit comments

Comments
 (0)