-
Notifications
You must be signed in to change notification settings - Fork 74
Completes the Swift implementation of munkipkg #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: swift
Are you sure you want to change the base?
Conversation
Core Features: - Project creation (plist, json, yaml formats) - Package building with pkgbuild integration - Package import (flat and bundle formats) - BOM export for Git workflow integration Implementation: - Swift Package Manager with ArgumentParser and Yams - macOS 11.0+ target (aligned with Munki v7) - Async/await for improved performance - Fixed import functionality Payload directory handling Components: - buildinfo.swift: Multi-format configuration handling - munkipkg.swift: Main CLI implementation - cliutils.swift: Simplified async CLI utilities - errors.swift: Error hierarchy with exit codes - munkipkgoptions.swift: Argument parsing Testing: - Core workflows verified (create, build, import, export-bom) - Format compatibility across all types confirmed - Unit test suite with module visibility Documentation: - Updated README with Swift installation instructions - Removed Python dependency references - Added Swift Package Manager build docs Backward compatibility maintained.
- Updated swift-tools-version from 5.4 to 5.5 - Fixed test resource loading with Bundle.module - Added explicit resource declaration in Package.swift - Updated documentation to reflect Swift 5.5 requirement All unit tests pass (12 tests in 2 suites) Release build completes successfully in ~2 seconds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Completes the Swift implementation of munkipkg to achieve feature parity with the original Python version, targeting macOS 11+ with Universal binary support. The implementation leverages Swift's modern features including async/await, ArgumentParser, and native YAML support.
- Adds full command-line interface with project creation, package building, and import functionality
- Implements comprehensive build configuration handling for plist, JSON, and YAML formats
- Provides async CLI utilities for external tool execution with proper error handling
Reviewed Changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Package.swift | Swift Package Manager configuration with dependencies for ArgumentParser and Yams |
| munkipkg.swift | Main application logic implementing all core functionality (create, build, import, BOM export) |
| munkipkgoptions.swift | Removes YAML validation restriction, enabling full YAML support |
| buildinfo.swift | Adds complete YAML support and public API access for testing |
| cliutils.swift | Streamlines CLI execution with async/await patterns, removing ~290 lines of unused code |
| errors.swift | Adds structured error hierarchy with specific exit codes and factory methods |
| README.md | Updates documentation for Swift implementation with installation and usage instructions |
| Test files | Adds proper module imports and modernizes test resource handling |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
a085b83 to
659925a
Compare
|
I appreciate the enthusiasm. This is a huge PR. How much of this was generated via AI? For my own projects, I write them partially to understand/learn the language, the frameworks, the coding approaches, and the algorithms. Accepting AI-generated code or big PRs that I don't really understand doesn't really help that goal. Happy to have a discussion here. |
|
Assisted yes! I've been using Claude to learn Swift this whole year and having a back and forth with it to learn and understand the language. It's been a goal of mine to build apps so I am using the work projects we love to use for Mac admin'ing as a place to learn and experiment. Always better when you have a specific something you want to do and a project as it so much more tangible and direct to learn. But if it looks as if I am doing a prompt and accepting all changes ( Heavily used for running the tests and generating test units, which helps and not my forté. The commit messages and PR were also assisted for speed, but I read and review because I never like the tone or how authoritative it sounds. I need to learn to send smaller PR. |
- Rewrote performBuild() with workflow: * Create build directory structure * Build component packages with pkgbuild * Support distribution-style packages with productbuild * Implement code signing with identity, keychain, and timestamp * Implement notarization with keychain-profile authentication * Implement stapling functionality * Add proper error handling and output control - Enhanced runCliAsync in cliutils to support all build commands
- Added analyzePermissionsInBom() function to parse BOM file metadata * Extracts mode, uid, gid, and size information * Returns structured permission map for analysis - Enhanced notarization to support dual authentication methods: * Keychain-profile method (existing) * Apple ID authentication with apple_id, team_id, password * Optional asc_provider for multi-team accounts - Added additional certificates support in signing: * Uses additionalCertNames from SigningInfo * Iterates cert names with --certs flag for productbuild - Added MissingBomFileError to errors.swift for better error handling - Integrated permission analysis into syncFromBomInfo()
Pull Request that adds the remaining parts of the Swift implementation of
munkipkgto bring it feature parity to the original Python version. Targets the same deployment requirements as Munki v7 (macOS 11+, Universal binaries).What was implemented
Key Details per .swift file
buildinfo.swift - Configuration Handling
Implements comprehensive build configuration management supporting all three file formats (plist, json, yaml). Uses Swift's
Codableprotocol for type-safe serialization/deserialization with proper error handling. Includes automatic variable substitution (e.g.,${version}in package names) and validation of configuration options.PropertyListEncoder/DecoderJSONEncoder/Decodermunkipkg.swift - Main Application Logic
Implements the complete command-line interface and core workflows using Swift's ArgumentParser. Handles all primary operations: project creation, package building, package import, and BOM export. Uses async/await for external tool invocation (pkgbuild, pkgutil, lsbom).
cliutils.swift - CLI Execution Utilities
Added Swift async/await patterns, reducing the code by ~290 lines while maintaining functionality.
Enhacements:
runCLI()(synchronous) andrunCliAsync()(asynchronous)exitCode,stdout,stderr)Improvements:
usleep()calls with cooperativeTask.yield()for better async behaviorerrors.swift - Error Type System
Defines an error hierarchy with specific exit codes for different failure scenarios. Implements
LocalizedErrorprotocol for proper error message presentation and Swift error handling patterns.MunkiPkgErrorclass with custom exit codesProjectExistsError,InvalidProjectError,ImportFailedError,BuildFailedErrorerrorDescriptionimplementation for user-facing messagesmunkipkgoptions.swift - Command-Line Argument Parsing
Leverages ArgumentParser for type-safe CLI option handling with automatic validation and help generation. Groups related options into logical categories for better organization and validation.
--buildas default action)Unit Test Suite (munkipkgTests/)
Test coverage for core functionality with proper module visibility through
@testable import. Includes fixture files for testing configuration formats.Test coverage:
Testing and Validation
Build and Development
Build completed successfully with Swift 5.5 in ~2 seconds
Universal binary created at .build/release/munkipkg
Minor non-breaking warnings about Swift 6 compatibility
Unit Tests
swift testTest run with 12 tests in 2 suites passed after 0.006 seconds
All BuildInfo tests: ✓ PASSED
All munkipkg tests: ✓ PASSED
Test Results:
Testing
Project Creation:
All three formats (plist, json, yaml) create proper directory structure with correct configuration files.
Package Building:
Successfully builds packages from all project formats with consistent output and proper naming conventions.
Import Functionality:
Successfully imports existing packages with proper payload extraction and metadata preservation.
BOM Export:
Correctly exports Bill-of-Materials information for Git workflow integration.
Compatibility Verification:
How to Test
Build and Install
cd swift/munkipkg swift build -c release sudo cp .build/release/munkipkg /usr/local/bin/Core Functionality Testing
Create projects in all formats
Build packages
Import existing packages
Export BOM information
What Changed
Swift Implementation:
Documentation Updates: