Skip to content

Commit 271c50b

Browse files
authored
Merge pull request #21 from a8cteam51/fix/review-0.5.0
0.5.0: review fixes, a recorder that only records for Oatcake, hardened signing
2 parents 6a3d53d + ea59ea9 commit 271c50b

85 files changed

Lines changed: 6772 additions & 3266 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/release.yml‎

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ name: Release
55
# Scripts/version.sh patch && git push --follow-tags
66
# Running the workflow by hand (Actions › Release › Run workflow) builds and signs without releasing.
77
#
8-
# Secrets (README › Releasing):
8+
# The job runs in the "release" environment, which holds the secrets and waits for its approver:
9+
# a branch's own copy of this file can't read them, and nothing is signed without that approval.
10+
#
11+
# Secrets, in the release environment (README › Releasing):
912
# OATCAKE_SIGNING_P12, OATCAKE_SIGNING_P12_PASSWORD the "Oatcake Release" code-signing identity
1013
# OATCAKE_UPDATE_KEY the Ed25519 key that signs latest.json
1114
on:
@@ -19,6 +22,9 @@ permissions:
1922
jobs:
2023
release:
2124
runs-on: macos-26
25+
# A release takes about seven minutes. Anything much longer is stuck.
26+
timeout-minutes: 30
27+
environment: release
2228
permissions:
2329
contents: write # to create the release
2430
steps:
@@ -36,6 +42,17 @@ jobs:
3642
exit 1
3743
fi
3844
45+
# Tested and built before the signing identity is on the runner: nothing that runs while the
46+
# package and its dependency are built or tested can sign with it. Packaging then only copies
47+
# what was built (OATCAKE_BIN), without running swift again.
48+
- run: swift test
49+
50+
- name: Build
51+
run: |
52+
swift build -c release --product Oatcake
53+
swift build -c release --product OatcakeRecorder
54+
echo "OATCAKE_BIN=$(swift build -c release --show-bin-path)" >> "$GITHUB_ENV"
55+
3956
# A throwaway keychain holding only the release identity. It's self-signed and so not trusted,
4057
# which codesign accepts; what matters is that every release carries the same one.
4158
- name: Import the signing certificate
@@ -59,14 +76,12 @@ jobs:
5976
# codesign on the runner only finds identities in keychains on the search list.
6077
security list-keychains -d user -s "$keychain" $(security list-keychains -d user | tr -d '"')
6178
security find-identity -p codesigning "$keychain"
62-
# Fail here rather than after the build if the identity can't sign.
79+
# Fail here rather than part-way through packaging if the identity can't sign.
6380
cp /usr/bin/true "$RUNNER_TEMP/sign-test"
6481
codesign --force --sign "Oatcake Release" --keychain "$keychain" "$RUNNER_TEMP/sign-test"
6582
echo "OATCAKE_SIGN_KEYCHAIN=$keychain" >> "$GITHUB_ENV"
6683
67-
- run: swift test
68-
69-
# Builds the app and the recorder, bundles them with llama.cpp's server (a fixed build, checked
84+
# Bundles the app and the recorder (built above) with llama.cpp's server (a fixed build, checked
7085
# against its SHA-256) and signs the lot (Scripts/bundle.sh).
7186
- name: Package
7287
env:
@@ -88,7 +103,36 @@ jobs:
88103
*"certificate leaf"*) ;;
89104
*) echo "::error::$bundle isn't signed with the release certificate."; exit 1 ;;
90105
esac
106+
# And for the hardened runtime, so nothing else on a Mac can load its code into it.
107+
case "$(codesign -d -v "$bundle" 2>&1)" in
108+
*"(runtime)"*) ;;
109+
*) echo "::error::$bundle isn't signed for the hardened runtime."; exit 1 ;;
110+
esac
111+
done
112+
# The app's requirement names the versions it stands for, so the permissions macOS gives
113+
# it aren't also an earlier release's (Scripts/bundle.sh).
114+
for bundle in "$app" "$app/Contents/Resources/OatcakeRecorder.app"; do
115+
case "$(codesign -d -r - "$bundle" 2>/dev/null)" in
116+
*CFBundleShortVersionString*) ;;
117+
*) echo "::error::$bundle's designated requirement doesn't name a version."; exit 1 ;;
118+
esac
91119
done
120+
# Without this on Oatcake itself, macOS never asks for the microphone and nothing can be recorded.
121+
for bundle in "$app" "$app/Contents/Resources/OatcakeRecorder.app"; do
122+
case "$(codesign -d --entitlements - "$bundle" 2>/dev/null)" in
123+
*com.apple.security.device.audio-input*) ;;
124+
*) echo "::error::$bundle isn't signed as using the microphone."; exit 1 ;;
125+
esac
126+
done
127+
128+
# install.sh names the certificate it accepts. It has to be the one this was signed with, or
129+
# the installer published with this release would turn the release away.
130+
- name: Check install.sh accepts this build
131+
run: |
132+
certificate="$(sed -n "s/^ *CERTIFICATE='\(.*\)'$/\1/p" install.sh)"
133+
test -n "$certificate"
134+
codesign --verify --deep --strict -R "=identifier \"local.oatcake\" and $certificate" build/Oatcake.app
135+
codesign --verify --deep --strict -R "=identifier \"local.oatcake.recorder\" and $certificate" build/Oatcake.app/Contents/Resources/OatcakeRecorder.app
92136
93137
# ditto keeps the code signatures intact.
94138
- name: Zip
@@ -110,7 +154,8 @@ jobs:
110154
--zip "$ZIP" \
111155
--url "https://github.com/$GITHUB_REPOSITORY/releases/download/$GITHUB_REF_NAME/$ZIP" \
112156
--notes "$RUNNER_TEMP/notes.txt" > latest.json
113-
cat latest.json
157+
# What was signed, without the signature: a run by hand signs a build that isn't released.
158+
plutil -extract payload raw -o - latest.json | base64 --decode
114159
115160
- name: Release
116161
if: github.ref_type == 'tag'
@@ -120,18 +165,20 @@ jobs:
120165
For Apple Silicon Macs on macOS 15 or later. To install, paste this into Terminal:
121166
122167
```
123-
curl -fsSL https://raw.githubusercontent.com/a8cteam51/oatcake/trunk/install.sh | sh
168+
curl -fsSL https://github.com/a8cteam51/oatcake/releases/latest/download/install.sh | sh
124169
```
125170
126171
Or download the zip below, move Oatcake to your Applications folder and open it. Oatcake isn't notarised, so macOS blocks a copy downloaded with a browser until you click Open Anyway in System Settings › Privacy & Security; the install line avoids that.
127172
128173
Installed copies update themselves (Settings › Updates). The first recording asks for microphone and system-audio permission for "OatcakeRecorder".
129-
# --notes goes above the generated list of changes.
130-
run: gh release create "$GITHUB_REF_NAME" "$ZIP" latest.json --repo "$GITHUB_REPOSITORY" --title "Oatcake $GITHUB_REF_NAME" --generate-notes --notes "$NOTES"
174+
# --notes goes above the generated list of changes. install.sh goes out with the release, so
175+
# the install line runs the installer that was approved with it, not whatever trunk holds.
176+
run: gh release create "$GITHUB_REF_NAME" "$ZIP" latest.json install.sh --repo "$GITHUB_REPOSITORY" --title "Oatcake $GITHUB_REF_NAME" --generate-notes --notes "$NOTES"
131177

132178
# What install.sh and installed copies will fetch.
133179
- name: Check the feed serves this release
134180
if: github.ref_type == 'tag'
135181
run: |
136182
sleep 5
137183
curl -fsSL "https://github.com/$GITHUB_REPOSITORY/releases/latest/download/latest.json" | cmp - latest.json
184+
curl -fsSL "https://github.com/$GITHUB_REPOSITORY/releases/latest/download/install.sh" | cmp - install.sh

‎.github/workflows/test.yml‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Test
2+
3+
# Every pull request and every push to trunk: build everything and run the tests. No secrets here;
4+
# signing and releasing are the Release workflow's, behind its environment.
5+
on:
6+
pull_request:
7+
push:
8+
branches: [trunk]
9+
10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: test-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
test:
19+
runs-on: macos-26
20+
timeout-minutes: 30
21+
steps:
22+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
23+
with:
24+
persist-credentials: false
25+
26+
- run: swift build
27+
28+
# A test that hangs would hold the job for hours and say nothing. After five minutes this says
29+
# where the tests are stuck, and fails.
30+
- name: Run the tests
31+
run: |
32+
swift test & tests=$!
33+
for _ in $(seq 1 60); do kill -0 "$tests" 2>/dev/null || break; sleep 5; done
34+
if kill -0 "$tests" 2>/dev/null; then
35+
echo "::error::The tests were still running after five minutes."
36+
for helper in $(pgrep -f 'swiftpm-testing-helper|xctest'); do sudo sample "$helper" 3 2>/dev/null | sed -n '1,400p'; done
37+
kill "$tests"
38+
exit 1
39+
fi
40+
wait "$tests"
41+
42+
- name: Check the scripts parse
43+
run: |
44+
sh -n install.sh
45+
bash -n Scripts/bundle.sh
46+
bash -n Scripts/version.sh

‎Package.swift‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,37 @@ let package = Package(
1010
.package(url: "https://github.com/FluidInference/FluidAudio.git", exact: "0.18.3", traits: ["Diarizer"]),
1111
],
1212
targets: [
13+
// What Oatcake and its recorder agree on: the files they pass between them and what's in
14+
// each. Shared, so the two programs can't drift apart.
15+
.target(
16+
name: "RecorderContract",
17+
swiftSettings: [.swiftLanguageMode(.v6)]
18+
),
1319
// Everything that isn't a window: files, recordings, the speech pipeline, the calendar,
1420
// summaries, Ask and updates.
1521
.target(
1622
name: "OatcakeCore",
17-
dependencies: [.product(name: "FluidAudio", package: "FluidAudio")],
18-
swiftSettings: [.swiftLanguageMode(.v5)]
23+
dependencies: ["RecorderContract", .product(name: "FluidAudio", package: "FluidAudio")],
24+
swiftSettings: [.swiftLanguageMode(.v6)]
1925
),
2026
// The app, and (with --analyse) the analysis helper it runs for each recording.
2127
.executableTarget(
2228
name: "Oatcake",
2329
dependencies: ["OatcakeCore"],
24-
swiftSettings: [.swiftLanguageMode(.v5)]
30+
swiftSettings: [.swiftLanguageMode(.v6)]
2531
),
26-
// The recorder: its own app bundle inside Oatcake.app, so macOS asks for microphone and
27-
// system-audio permission for it alone.
32+
// The recorder: its own app bundle inside Oatcake.app. macOS counts the microphone and system
33+
// audio it uses as Oatcake's, and asks for them in Oatcake's name.
2834
.executableTarget(
2935
name: "OatcakeRecorder",
30-
swiftSettings: [.swiftLanguageMode(.v5)]
36+
dependencies: ["RecorderContract"],
37+
swiftSettings: [.swiftLanguageMode(.v6)]
3138
),
3239
.testTarget(
3340
name: "OatcakeCoreTests",
3441
dependencies: ["OatcakeCore"],
3542
resources: [.copy("Fixtures")],
36-
swiftSettings: [.swiftLanguageMode(.v5)]
43+
swiftSettings: [.swiftLanguageMode(.v6)]
3744
),
3845
]
3946
)

0 commit comments

Comments
 (0)