Skip to content

Commit 2522381

Browse files
committed
feat(swift): optional codesigning and private SPM dependency auth
Two opt-in capabilities for the shared Swift build, both off by default so existing consumers are unaffected: - entitlements: when set, ad-hoc codesign the built binary with the given entitlements plist right after swift build (mirrors local build-swift.sh). Threaded through swift-pkg-pr.yml and swift-release.yml into swift-build. - private-deps: when true, mint a short-lived owner-scoped token from the org App (APP_ID/APP_PRIVATE_KEY) and configure git so SwiftPM can clone private/internal org dependencies without listing repo names.
1 parent d26f447 commit 2522381

3 files changed

Lines changed: 66 additions & 2 deletions

File tree

.github/blocks/swift-build/action.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ inputs:
1717
description: "Space-separated list of SPM resource bundle names to include (e.g. 'Foo_Foo.bundle')"
1818
required: false
1919
default: ""
20+
entitlements:
21+
description: "Path to an entitlements plist (relative to repo root). When set, the built binary is ad-hoc codesigned with these entitlements. Needed for daemons that require private entitlements (e.g. to connect to imagent)."
22+
required: false
23+
default: ""
24+
github-token:
25+
description: "Token with read access to private/internal SPM dependencies. When set, git is configured to use it for github.com clones (so SwiftPM can fetch private deps)."
26+
required: false
27+
default: ""
2028

2129
outputs:
2230
binary-path:
@@ -49,13 +57,27 @@ runs:
4957
- name: Create artifacts directory
5058
run: mkdir -p artifacts
5159
shell: bash
60+
- name: Configure git auth for private/internal SPM dependencies
61+
if: inputs.github-token != ''
62+
shell: bash
63+
env:
64+
GH_TOKEN: ${{ inputs.github-token }}
65+
run: |
66+
git config --global url."https://x-access-token:${GH_TOKEN}@github.com/".insteadOf "https://github.com/"
5267
- name: Build Swift Binary
5368
shell: bash
5469
id: build
5570
run: |
5671
swift build -c release
57-
cp ".build/release/${{ inputs.binary-name }}" artifacts
58-
echo "binary-path=.build/release/${{ inputs.binary-name }}" >> $GITHUB_OUTPUT
72+
BIN=".build/release/${{ inputs.binary-name }}"
73+
if [ -n "${{ inputs.entitlements }}" ]; then
74+
echo "::group::Codesign $BIN (entitlements: ${{ inputs.entitlements }})"
75+
codesign -s - --entitlements "${{ inputs.entitlements }}" -f "$BIN"
76+
codesign -dvvv "$BIN" || true
77+
echo "::endgroup::"
78+
fi
79+
cp "$BIN" artifacts
80+
echo "binary-path=$BIN" >> $GITHUB_OUTPUT
5981
6082
# ── Collect resource bundles ──
6183
BUNDLES_PATH=""

.github/workflows/swift-pkg-pr.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ on:
2424
required: false
2525
default: ""
2626
description: "Space-separated list of SPM resource bundle names to include in the .pkg"
27+
entitlements:
28+
type: string
29+
required: false
30+
default: ""
31+
description: "Path to an entitlements plist for ad-hoc codesigning the built binary."
32+
private-deps:
33+
type: boolean
34+
required: false
35+
default: false
36+
description: "Mint an app token (APP_ID/APP_PRIVATE_KEY) so SwiftPM can clone private/internal org dependencies."
2737
secrets:
2838
SECRET_ENV_VARS:
2939
required: false
@@ -54,12 +64,24 @@ jobs:
5464
| **Commit** | ${{ github.sha }} |
5565
| **Run** | [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
5666
67+
# ── Mint app token for private SPM dependencies (optional) ───────────
68+
- name: Mint app token for private SPM deps
69+
id: app-token
70+
if: inputs.private-deps
71+
uses: actions/create-github-app-token@v1
72+
with:
73+
app-id: ${{ secrets.APP_ID }}
74+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
75+
owner: ${{ github.repository_owner }}
76+
5777
# ── Build ────────────────────────────────────────────────────────────
5878
- name: Swift Build
5979
id: build
6080
uses: photon-hq/buildspace/.github/blocks/swift-build@main
6181
with:
6282
binary-name: ${{ inputs.package-name }}
83+
entitlements: ${{ inputs.entitlements }}
84+
github-token: ${{ steps.app-token.outputs.token }}
6385
compile-env: |-
6486
VERSION=PR-${{ github.event.pull_request.number }}
6587
DEPLOYMENT_ENVIRONMENT=development

.github/workflows/swift-release.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ on:
2323
required: false
2424
default: ""
2525
description: "Space-separated list of SPM resource bundle names to include in the .pkg"
26+
entitlements:
27+
type: string
28+
required: false
29+
default: ""
30+
description: "Path to an entitlements plist for ad-hoc codesigning the built binary."
31+
private-deps:
32+
type: boolean
33+
required: false
34+
default: false
35+
description: "Mint an app token (APP_ID/APP_PRIVATE_KEY) so SwiftPM can clone private/internal org dependencies."
2636
labels-to-check:
2737
type: string
2838
required: false
@@ -115,12 +125,22 @@ jobs:
115125
needs: prepare-release
116126
runs-on: macos-26
117127
steps:
128+
- name: Mint app token for private SPM deps
129+
id: app-token
130+
if: inputs.private-deps
131+
uses: actions/create-github-app-token@v1
132+
with:
133+
app-id: ${{ secrets.APP_ID }}
134+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
135+
owner: ${{ github.repository_owner }}
118136
- name: Swift Build
119137
id: build
120138
uses: photon-hq/buildspace/.github/blocks/swift-build@main
121139
with:
122140
binary-name: ${{ inputs.package-name }}
123141
use-cache: "false"
142+
entitlements: ${{ inputs.entitlements }}
143+
github-token: ${{ steps.app-token.outputs.token }}
124144
compile-env: |-
125145
VERSION=${{ needs.prepare-release.outputs.version }}
126146
DEPLOYMENT_ENVIRONMENT=production

0 commit comments

Comments
 (0)