|
| 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 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +on: |
| 17 | + workflow_call: |
| 18 | + inputs: |
| 19 | + mode: |
| 20 | + description: 'Build mode: dev, preview, or release (affects bundle metadata)' |
| 21 | + type: string |
| 22 | + default: 'preview' |
| 23 | + version: |
| 24 | + description: 'Bundle version string (e.g. 1.2.3)' |
| 25 | + type: string |
| 26 | + default: '0.0.0-preview' |
| 27 | + artifact-name: |
| 28 | + description: 'Name for the uploaded artifact' |
| 29 | + type: string |
| 30 | + default: 'native-bin-macos' |
| 31 | + secrets: |
| 32 | + OP_CI_TOKEN: |
| 33 | + required: true |
| 34 | + |
| 35 | +jobs: |
| 36 | + build-swift-binary: |
| 37 | + runs-on: macos-latest |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v6 |
| 40 | + |
| 41 | + - name: Setup Bun |
| 42 | + uses: oven-sh/setup-bun@v2 |
| 43 | + |
| 44 | + # skip bun dep caching since less likely to hit |
| 45 | + |
| 46 | + - name: Install node deps |
| 47 | + run: bun install |
| 48 | + |
| 49 | + - name: Enable turborepo build cache |
| 50 | + uses: rharkor/caching-for-turbo@v2.3.11 |
| 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 | + # Load secrets from 1Password via varlock (scoped to the Swift package) |
| 71 | + - name: Load signing secrets |
| 72 | + uses: dmno-dev/varlock-action@v1.0.1 |
| 73 | + with: |
| 74 | + working-directory: packages/encryption-binary-swift |
| 75 | + env: |
| 76 | + OP_CI_TOKEN: ${{ secrets.OP_CI_TOKEN }} |
| 77 | + |
| 78 | + # Import signing certificate into a temporary keychain |
| 79 | + - name: Import signing certificate |
| 80 | + run: | |
| 81 | + KEYCHAIN_PATH=$RUNNER_TEMP/signing.keychain-db |
| 82 | + KEYCHAIN_PASSWORD=$(openssl rand -base64 24) |
| 83 | +
|
| 84 | + echo "$APPLE_CERTIFICATE_BASE64" | base64 --decode > $RUNNER_TEMP/certificate.p12 |
| 85 | +
|
| 86 | + security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" |
| 87 | + security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH" |
| 88 | + security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" |
| 89 | +
|
| 90 | + security import $RUNNER_TEMP/certificate.p12 \ |
| 91 | + -P "$APPLE_CERTIFICATE_PASSWORD" \ |
| 92 | + -A -t cert -f pkcs12 \ |
| 93 | + -k "$KEYCHAIN_PATH" |
| 94 | +
|
| 95 | + security set-key-partition-list -S apple-tool:,apple:,codesign: \ |
| 96 | + -s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" |
| 97 | +
|
| 98 | + security list-keychains -d user -s "$KEYCHAIN_PATH" login.keychain-db |
| 99 | +
|
| 100 | + echo "APPLE_SIGNING_IDENTITY=$APPLE_SIGNING_IDENTITY" >> $GITHUB_ENV |
| 101 | +
|
| 102 | + # Compile (cached), bundle with mode-specific metadata, and sign |
| 103 | + - name: Build, bundle, and sign |
| 104 | + run: | |
| 105 | + bun run --filter @varlock/encryption-binary-swift build:swift \ |
| 106 | + -- --mode ${{ inputs.mode }} --version ${{ inputs.version }} --sign "$APPLE_SIGNING_IDENTITY" |
| 107 | +
|
| 108 | + - name: Verify binary |
| 109 | + run: | |
| 110 | + APP_PATH="packages/varlock/native-bins/darwin/VarlockEnclave.app" |
| 111 | + echo "=== App bundle contents ===" |
| 112 | + ls -la "$APP_PATH/Contents/MacOS/" |
| 113 | + echo "=== Binary architectures ===" |
| 114 | + lipo -info "$APP_PATH/Contents/MacOS/varlock-local-encrypt" |
| 115 | + echo "=== Code signature ===" |
| 116 | + codesign -dvv "$APP_PATH" 2>&1 || true |
| 117 | + echo "=== Info.plist ===" |
| 118 | + cat "$APP_PATH/Contents/Info.plist" |
| 119 | +
|
| 120 | + - name: Upload native binary artifact |
| 121 | + uses: actions/upload-artifact@v7 |
| 122 | + with: |
| 123 | + name: ${{ inputs.artifact-name }} |
| 124 | + path: packages/varlock/native-bins/darwin/VarlockEnclave.app |
| 125 | + retention-days: 7 |
| 126 | + |
| 127 | + # Cache the signed .app so other jobs (e.g. release-preview) can restore |
| 128 | + # it on a Linux runner without needing a macOS build |
| 129 | + - name: Cache signed .app bundle |
| 130 | + uses: actions/cache/save@v5 |
| 131 | + with: |
| 132 | + path: packages/varlock/native-bins/darwin/VarlockEnclave.app |
| 133 | + key: native-bin-macos-signed-${{ hashFiles('packages/encryption-binary-swift/swift/**') }} |
| 134 | + |
| 135 | + - name: Cleanup signing keychain |
| 136 | + if: always() |
| 137 | + run: | |
| 138 | + KEYCHAIN_PATH=$RUNNER_TEMP/signing.keychain-db |
| 139 | + if [ -f "$KEYCHAIN_PATH" ]; then |
| 140 | + security delete-keychain "$KEYCHAIN_PATH" || true |
| 141 | + fi |
| 142 | + rm -f $RUNNER_TEMP/certificate.p12 |
0 commit comments