Repository navigation
184 lines (167 loc) · 9.62 KB
/
Copy pathrelease.yml
File metadata and controls
184 lines (167 loc) · 9.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: Release
# Pushing a version tag builds Oatcake.app, signs it with the release certificate, and publishes it
# with latest.json, the signed manifest that install.sh and Oatcake's own updater read:
# Scripts/version.sh patch && git push --follow-tags
# Running the workflow by hand (Actions › Release › Run workflow) builds and signs without releasing.
#
# The job runs in the "release" environment, which holds the secrets and waits for its approver:
# a branch's own copy of this file can't read them, and nothing is signed without that approval.
#
# Secrets, in the release environment (docs/releasing.md):
# OATCAKE_SIGNING_P12, OATCAKE_SIGNING_P12_PASSWORD the "Oatcake Release" code-signing identity
# OATCAKE_UPDATE_KEY the Ed25519 key that signs latest.json
on:
push:
tags: ["v*"]
workflow_dispatch:
permissions:
contents: read
jobs:
release:
runs-on: macos-26
# A release takes about seven minutes. Anything much longer is stuck.
timeout-minutes: 30
environment: release
permissions:
contents: write # to create the release
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0 # the previous tag, for the release notes
- name: Check the tag matches VERSION
if: github.ref_type == 'tag'
run: |
version="v$(tr -d '[:space:]' < VERSION)"
if [ "$version" != "$GITHUB_REF_NAME" ]; then
echo "::error::Tag $GITHUB_REF_NAME doesn't match VERSION ($version). Use Scripts/version.sh to make the tag."
exit 1
fi
# Tested and built before the signing identity is on the runner: nothing that runs while the
# package and its dependency are built or tested can sign with it. Packaging then only copies
# what was built (OATCAKE_BIN), without running swift again.
- run: swift test
- name: Build
run: |
swift build -c release --product Oatcake
swift build -c release --product OatcakeRecorder
echo "OATCAKE_BIN=$(swift build -c release --show-bin-path)" >> "$GITHUB_ENV"
# A throwaway keychain holding only the release identity. It's self-signed and so not trusted,
# which codesign accepts; what matters is that every release carries the same one.
- name: Import the signing certificate
env:
P12: ${{ secrets.OATCAKE_SIGNING_P12 }}
P12_PASSWORD: ${{ secrets.OATCAKE_SIGNING_P12_PASSWORD }}
run: |
if [ -z "$P12" ]; then
echo "::error::The OATCAKE_SIGNING_P12 secret is missing, so the app can't be signed for updates."
exit 1
fi
keychain="$RUNNER_TEMP/signing.keychain-db"
password="$(openssl rand -hex 16)"
security create-keychain -p "$password" "$keychain"
security set-keychain-settings -lut 3600 "$keychain"
security unlock-keychain -p "$password" "$keychain"
printf '%s' "$P12" | base64 --decode > "$RUNNER_TEMP/signing.p12"
security import "$RUNNER_TEMP/signing.p12" -k "$keychain" -P "$P12_PASSWORD" -T /usr/bin/codesign
rm "$RUNNER_TEMP/signing.p12"
security set-key-partition-list -S apple-tool:,apple: -s -k "$password" "$keychain" > /dev/null
# codesign on the runner only finds identities in keychains on the search list.
security list-keychains -d user -s "$keychain" $(security list-keychains -d user | tr -d '"')
security find-identity -p codesigning "$keychain"
# Fail here rather than part-way through packaging if the identity can't sign.
cp /usr/bin/true "$RUNNER_TEMP/sign-test"
codesign --force --sign "Oatcake Release" --keychain "$keychain" "$RUNNER_TEMP/sign-test"
echo "OATCAKE_SIGN_KEYCHAIN=$keychain" >> "$GITHUB_ENV"
# Bundles the app and the recorder (built above) with llama.cpp's server (a fixed build, checked
# against its SHA-256) and signs the lot (Scripts/bundle.sh).
- name: Package
env:
OATCAKE_SIGN_IDENTITY: Oatcake Release
OATCAKE_REQUIRE_SIGNING: "1"
run: Scripts/bundle.sh
# Both the app and the recorder must name the certificate, not an ad-hoc hash, or installed
# copies couldn't update to this one and macOS would ask for permissions again. So must
# llama.cpp's server and its libraries, which come signed ad-hoc by their own build.
- name: Check the signatures
run: |
app=build/Oatcake.app
codesign --verify --deep --strict "$app"
for bundle in "$app" "$app/Contents/Resources/OatcakeRecorder.app" "$app"/Contents/Resources/llama/llama-server "$app"/Contents/Resources/llama/*.dylib; do
requirement="$(codesign -d -r - "$bundle" 2>/dev/null)"
echo "$bundle: $requirement"
case "$requirement" in
*"certificate leaf"*) ;;
*) echo "::error::$bundle isn't signed with the release certificate."; exit 1 ;;
esac
# And for the hardened runtime, so nothing else on a Mac can load its code into it.
case "$(codesign -d -v "$bundle" 2>&1)" in
*"(runtime)"*) ;;
*) echo "::error::$bundle isn't signed for the hardened runtime."; exit 1 ;;
esac
done
# The app's requirement names the versions it stands for, so the permissions macOS gives
# it aren't also an earlier release's (Scripts/bundle.sh).
for bundle in "$app" "$app/Contents/Resources/OatcakeRecorder.app"; do
case "$(codesign -d -r - "$bundle" 2>/dev/null)" in
*CFBundleShortVersionString*) ;;
*) echo "::error::$bundle's designated requirement doesn't name a version."; exit 1 ;;
esac
done
# Without this on Oatcake itself, macOS never asks for the microphone and nothing can be recorded.
for bundle in "$app" "$app/Contents/Resources/OatcakeRecorder.app"; do
case "$(codesign -d --entitlements - "$bundle" 2>/dev/null)" in
*com.apple.security.device.audio-input*) ;;
*) echo "::error::$bundle isn't signed as using the microphone."; exit 1 ;;
esac
done
# install.sh names the certificate it accepts. It has to be the one this was signed with, or
# the installer published with this release would turn the release away.
- name: Check install.sh accepts this build
run: |
certificate="$(sed -n "s/^ *CERTIFICATE='\(.*\)'$/\1/p" install.sh)"
test -n "$certificate"
codesign --verify --deep --strict -R "=identifier \"local.oatcake\" and $certificate" build/Oatcake.app
codesign --verify --deep --strict -R "=identifier \"local.oatcake.recorder\" and $certificate" build/Oatcake.app/Contents/Resources/OatcakeRecorder.app
# ditto keeps the code signatures intact.
- name: Zip
run: |
zip="Oatcake-${GITHUB_REF_NAME//\//-}-arm64.zip" # a branch name's / can't be in a file name
ditto -c -k --sequesterRsrc --keepParent build/Oatcake.app "$zip"
echo "ZIP=$zip" >> "$GITHUB_ENV"
ls -lh "$zip"
# Notes: the commit subjects since the previous tag, without Scripts/version.sh's own commit.
- name: Sign latest.json
env:
OATCAKE_UPDATE_KEY: ${{ secrets.OATCAKE_UPDATE_KEY }}
run: |
previous="$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || true)"
git log --no-merges --format='- %s' ${previous:+"$previous..HEAD"} | grep -v -E '^- v?[0-9]+\.[0-9]+\.[0-9]+$' > "$RUNNER_TEMP/notes.txt" || true
swift Scripts/sign-manifest.swift \
--app build/Oatcake.app \
--zip "$ZIP" \
--url "https://github.com/$GITHUB_REPOSITORY/releases/download/$GITHUB_REF_NAME/$ZIP" \
--notes "$RUNNER_TEMP/notes.txt" > latest.json
# What was signed, without the signature: a run by hand signs a build that isn't released.
plutil -extract payload raw -o - latest.json | base64 --decode
- name: Release
if: github.ref_type == 'tag'
env:
GH_TOKEN: ${{ github.token }}
NOTES: |
For Apple Silicon Macs on macOS 15 or later. To install, paste this into Terminal:
```
curl -fsSL https://github.com/a8cteam51/oatcake/releases/latest/download/install.sh | sh
```
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.
Installed copies update themselves (Settings › Updates). The first recording asks for microphone and system-audio permission for "OatcakeRecorder".
# --notes goes above the generated list of changes. install.sh goes out with the release, so
# the install line runs the installer that was approved with it, not whatever trunk holds.
run: gh release create "$GITHUB_REF_NAME" "$ZIP" latest.json install.sh --repo "$GITHUB_REPOSITORY" --title "Oatcake $GITHUB_REF_NAME" --generate-notes --notes "$NOTES"
# What install.sh and installed copies will fetch.
- name: Check the feed serves this release
if: github.ref_type == 'tag'
run: |
sleep 5
curl -fsSL "https://github.com/$GITHUB_REPOSITORY/releases/latest/download/latest.json" | cmp - latest.json
curl -fsSL "https://github.com/$GITHUB_REPOSITORY/releases/latest/download/install.sh" | cmp - install.sh