CI/CD Guide
Automate preference management with CI/CD integration.
Headless Mode
Section titled “Headless Mode”Run macprefs without interactive prompts:
macprefs apply --config my-prefs.json --yesThe --yes flag skips the interactive confirmation prompt, enabling unattended execution.
JSON Output
Section titled “JSON Output”Get machine-readable output for parsing in scripts:
macprefs plan --config my-prefs.json --format jsonExit Codes
Section titled “Exit Codes”macprefs uses standard exit codes for scripting:
| Code | Meaning |
|---|---|
0 | Success / No drift / Valid |
1 | Error / Gated feature / Invalid |
2 | Drift detected (changes pending) / Non-critical issues |
Examples:
planreturns0if config matches current state,2if changes are neededapplyreturns0on success,1on errorpreflightreturns0(PASS),2(ISSUES FOUND), or1(FAIL)
GitHub Actions Example
Section titled “GitHub Actions Example”name: Apply Preferenceson: workflow_dispatch:
jobs: apply: runs-on: macos-latest steps: - uses: actions/checkout@v4
- name: Install macprefs run: brew install macprefs
- name: Run preflight run: macprefs preflight
- name: Apply preferences run: macprefs apply --config ./config.json --yes env: MACPREFS_LICENSE: ${{ secrets.MACPREFS_LICENSE }}name: Check Drifton: schedule: - cron: '0 9 * * 1' # Every Monday at 9am
jobs: check: runs-on: macos-latest steps: - uses: actions/checkout@v4
- name: Install macprefs run: brew install macprefs
- name: Check for drift id: plan run: | macprefs plan --config ./config.json --format json > plan.json echo "exit_code=$?" >> $GITHUB_OUTPUT env: MACPREFS_LICENSE: ${{ secrets.MACPREFS_LICENSE }}
- name: Report drift if: steps.plan.outputs.exit_code == '2' run: echo "Configuration drift detected!"Validation in CI
Section titled “Validation in CI”Add config validation to your PR checks:
name: Validate Configon: pull_request: paths: - '**.json'
jobs: validate: runs-on: macos-latest steps: - uses: actions/checkout@v4
- name: Install macprefs run: brew install macprefs
- name: Validate config files run: | for f in configs/*.json; do echo "Validating $f..." macprefs validate --config "$f" doneEnvironment Variables
Section titled “Environment Variables”| Variable | Description |
|---|---|
MACPREFS_LICENSE | License key for Pro features |
MACPREFS_CONFIG | Default config file path (optional) |
Best Practices
Section titled “Best Practices”- Always run preflight first - Ensure the target system is ready
- Use
--rollback-on-fail- Enabled by default, reverts on errors - Validate configs in CI - Catch schema errors before deployment
- Store configs in version control - Track changes over time
- Use exit codes for logic - Branch on
0,1, or2as needed