|
| 1 | +name: Build macOS native binary |
| 2 | + |
| 3 | +# Reusable workflow that compiles, bundles, and Developer ID signs the |
| 4 | +# VarlockEnclave Swift binary on a macOS runner. |
| 5 | +# |
| 6 | +# The Swift .build directory is cached by source hash, so the compile |
| 7 | +# step (~minutes) is near-instant on cache hit. The .app bundle wrapping |
| 8 | +# (plist, icon, signing) always runs since it varies by mode/version. |
| 9 | +# |
| 10 | +# Notarization is intentionally NOT included here — it's a separate |
| 11 | +# workflow for production releases. |
| 12 | + |
| 13 | +on: |
| 14 | + workflow_call: |
| 15 | + inputs: |
| 16 | + mode: |
| 17 | + description: 'Build mode: dev, preview, or release (affects bundle metadata)' |
| 18 | + type: string |
| 19 | + default: 'preview' |
| 20 | + version: |
| 21 | + description: 'Bundle version string (e.g. 1.2.3)' |
| 22 | + type: string |
| 23 | + default: '0.0.0-preview' |
| 24 | + artifact-name: |
| 25 | + description: 'Name for the uploaded artifact' |
| 26 | + type: string |
| 27 | + default: 'native-bin-macos' |
| 28 | + secrets: |
| 29 | + OP_CI_TOKEN: |
| 30 | + required: true |
| 31 | + |
| 32 | +jobs: |
| 33 | + build: |
| 34 | + runs-on: macos-latest |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v6 |
| 37 | + |
| 38 | + - name: Setup Bun |
| 39 | + uses: oven-sh/setup-bun@v2 |
| 40 | + |
| 41 | + - name: Cache bun dependencies |
| 42 | + uses: actions/cache@v5 |
| 43 | + with: |
| 44 | + path: ~/.bun/install/cache |
| 45 | + key: bun-${{ runner.os }}-${{ hashFiles('bun.lock') }} |
| 46 | + restore-keys: | |
| 47 | + bun-${{ runner.os }}- |
| 48 | +
|
| 49 | + - name: Install node deps |
| 50 | + run: bun install |
| 51 | + |
| 52 | + # Cache the Swift .build directory so compilation is fast on unchanged source |
| 53 | + - name: Compute Swift source hash |
| 54 | + id: swift-hash |
| 55 | + run: | |
| 56 | + HASH=$(find packages/encryption-binary-swift/swift -type f | sort | xargs shasum -a 256 | shasum -a 256 | cut -d' ' -f1) |
| 57 | + echo "hash=$HASH" >> $GITHUB_OUTPUT |
| 58 | + echo "Swift source hash: $HASH" |
| 59 | +
|
| 60 | + - name: Cache Swift build artifacts |
| 61 | + uses: actions/cache@v5 |
| 62 | + with: |
| 63 | + path: packages/encryption-binary-swift/swift/.build |
| 64 | + key: varlock-swift-build-${{ steps.swift-hash.outputs.hash }} |
| 65 | + |
| 66 | + # Build varlock JS so we can use it to resolve secrets from 1Password |
| 67 | + - name: Build varlock libs |
| 68 | + run: bun run build:libs |
| 69 | + |
| 70 | + # Import signing certificate from 1Password (secrets scoped to the Swift package) |
| 71 | + - name: Import signing certificate |
| 72 | + working-directory: packages/encryption-binary-swift |
| 73 | + run: | |
| 74 | + eval "$(bunx varlock load --format shell)" |
| 75 | +
|
| 76 | + KEYCHAIN_PATH=$RUNNER_TEMP/signing.keychain-db |
| 77 | + KEYCHAIN_PASSWORD=$(openssl rand -base64 24) |
| 78 | +
|
| 79 | + echo "$APPLE_CERTIFICATE_BASE64" | base64 --decode > $RUNNER_TEMP/certificate.p12 |
| 80 | +
|
| 81 | + security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" |
| 82 | + security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH" |
| 83 | + security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" |
| 84 | +
|
| 85 | + security import $RUNNER_TEMP/certificate.p12 \ |
| 86 | + -P "$APPLE_CERTIFICATE_PASSWORD" \ |
| 87 | + -A -t cert -f pkcs12 \ |
| 88 | + -k "$KEYCHAIN_PATH" |
| 89 | +
|
| 90 | + security set-key-partition-list -S apple-tool:,apple:,codesign: \ |
| 91 | + -s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" |
| 92 | +
|
| 93 | + security list-keychains -d user -s "$KEYCHAIN_PATH" login.keychain-db |
| 94 | +
|
| 95 | + echo "APPLE_SIGNING_IDENTITY=$APPLE_SIGNING_IDENTITY" >> $GITHUB_ENV |
| 96 | + env: |
| 97 | + OP_CI_TOKEN: ${{ secrets.OP_CI_TOKEN }} |
| 98 | + |
| 99 | + # Compile (cached), bundle with mode-specific metadata, and sign |
| 100 | + - name: Build, bundle, and sign |
| 101 | + run: | |
| 102 | + bun run --filter @varlock/encryption-binary-swift build:swift \ |
| 103 | + -- --mode ${{ inputs.mode }} --version ${{ inputs.version }} --sign "$APPLE_SIGNING_IDENTITY" |
| 104 | +
|
| 105 | + - name: Verify binary |
| 106 | + run: | |
| 107 | + APP_PATH="packages/varlock/native-bins/darwin/VarlockEnclave.app" |
| 108 | + echo "=== App bundle contents ===" |
| 109 | + ls -la "$APP_PATH/Contents/MacOS/" |
| 110 | + echo "=== Binary architectures ===" |
| 111 | + lipo -info "$APP_PATH/Contents/MacOS/varlock-local-encrypt" |
| 112 | + echo "=== Code signature ===" |
| 113 | + codesign -dvv "$APP_PATH" 2>&1 || true |
| 114 | + echo "=== Info.plist ===" |
| 115 | + cat "$APP_PATH/Contents/Info.plist" |
| 116 | +
|
| 117 | + - name: Upload native binary artifact |
| 118 | + uses: actions/upload-artifact@v7 |
| 119 | + with: |
| 120 | + name: ${{ inputs.artifact-name }} |
| 121 | + path: packages/varlock/native-bins/darwin/VarlockEnclave.app |
| 122 | + retention-days: 7 |
| 123 | + |
| 124 | + - name: Cleanup signing keychain |
| 125 | + if: always() |
| 126 | + run: | |
| 127 | + KEYCHAIN_PATH=$RUNNER_TEMP/signing.keychain-db |
| 128 | + if [ -f "$KEYCHAIN_PATH" ]; then |
| 129 | + security delete-keychain "$KEYCHAIN_PATH" || true |
| 130 | + fi |
| 131 | + rm -f $RUNNER_TEMP/certificate.p12 |
0 commit comments