bots-garden/sidekickspublic Fork
⑂ release/v1.5.0
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/sidekicks.git
git clone ssh://git@rickub.com/bots-garden/sidekicks.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
🛟 Updated. 0332dcc · on release/v1.5.0 · k33g · 16d ago
local-ci-02-build.sh · 221 lines · 9.1 KBBash Blame HistoryRaw
  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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env bash
# Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE
#
# local-ci-02-build.sh — the packages of a release, in release/<TAG>/.
#
# scripts/build-release.sh builds them into dist/ (macOS arm64, Windows amd64
# and arm64; SKIP=windows, LINUX_ARCHES=amd64… work as there). Then, when
# SIGN_IDENTITY is set in .release.env, this script signs, notarizes and
# staples the macOS app, makes the .dmg from the stapled app, signs, notarizes
# and staples the .dmg too (docs/en/how-to/sign-and-notarize-on-macos.md, part B,
# done by a script). Last, it stages everything in release/<TAG>/ with one
# SHA256SUMS.
#
# release/<TAG>/ holds:
#   the packages of scripts/package.sh release-names
#   SHA256SUMS
#   macos-signature.txt      only when the macOS packages were signed
#
# The files are named after the version of build/config.yml, not after TAG: a
# test release (v9.9.9) holds packages named 1.2.0. TAG must be v<version>,
# unless it is a test tag (v9.9.9…).
source "$(dirname "$0")/local-ci-00-common.sh"

SIGN_IDENTITY="${SIGN_IDENTITY:-}"
NOTARY_PROFILE="${NOTARY_PROFILE:-}"
SKIP="${SKIP:-}"

if ! [[ "${TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
	echo "❌ TAG must look like v1.2.3 or v1.2.3-rc.1, got '${TAG}' (check .release.env)"
	exit 1
fi
VERSION="$(scripts/package.sh version)"
case "${TAG}" in
	"v${VERSION}" | v9.9.9*) ;;
	*)
		echo "❌ TAG is ${TAG} but build/config.yml says ${VERSION}: raise info.version, or fix .release.env"
		exit 1
		;;
esac

# The files generated from build/config.yml (Info.plist, the Windows manifest,
# nfpm…) are brought up to date, and LSMinimumSystemVersion is put back to
# 13.0.0, which the generator resets to 12.0.0 (scripts/sync-build-assets.sh,
# docs/en/how-to/set-the-version.md). They are tracked files: when the sync
# changes any of them, the tag would not describe the build, so it stops here.
before="$(git status --porcelain --untracked-files=no -- build)"
scripts/sync-build-assets.sh
after="$(git status --porcelain --untracked-files=no -- build)"
if [ "${before}" != "${after}" ]; then
	echo "❌ the sync changed the build assets: review, commit and push them, then run this script again"
	git status --short --untracked-files=no -- build
	exit 1
fi

# The app that scripts/package.sh macos leaves.
APP="bin/sidekicks.app"

macos_built=true
case " ${SKIP} " in *" macos "*) macos_built=false ;; esac

# checkSigningSetup fails now, before minutes of building, when the signature
# was asked for but cannot be done on this machine.
checkSigningSetup() {
	if [ "$(uname -s)" != "Darwin" ]; then
		echo "❌ SIGN_IDENTITY is set, but signing needs macOS (codesign, notarytool)"
		exit 1
	fi
	if [ -z "${NOTARY_PROFILE}" ]; then
		echo "❌ SIGN_IDENTITY is set but NOTARY_PROFILE is not: a signed app that is not notarized is still blocked by Gatekeeper"
		exit 1
	fi
	local identities
	identities="$(security find-identity -v -p codesigning)"
	if ! grep -qF -- "\"${SIGN_IDENTITY}\"" <<<"${identities}"; then
		echo "❌ no valid identity \"${SIGN_IDENTITY}\" in the keychain"
		echo "   💡 security find-identity -v -p codesigning"
		exit 1
	fi
	if ! xcrun notarytool history --keychain-profile "${NOTARY_PROFILE}" >/dev/null 2>&1; then
		echo "❌ the notarytool profile \"${NOTARY_PROFILE}\" does not work"
		echo "   💡 xcrun notarytool history --keychain-profile \"${NOTARY_PROFILE}\""
		exit 1
	fi
}

# notarize FILE: submits FILE to Apple, waits, fails unless it is Accepted;
# prints the submission id.
notarize() {
	local file=$1 out="${work}/notary.json" status submission
	if ! xcrun notarytool submit "${file}" --keychain-profile "${NOTARY_PROFILE}" --wait --output-format json >"${out}"; then
		echo "   ❌ notarytool submit failed:" >&2
		cat "${out}" >&2
		exit 1
	fi
	status="$(jq -r '.status // empty' "${out}")"
	submission="$(jq -r '.id // empty' "${out}")"
	if [ "${status}" != "Accepted" ]; then
		echo "   ❌ notarization ${submission}: ${status:-no status}" >&2
		echo "   💡 xcrun notarytool log ${submission} --keychain-profile \"${NOTARY_PROFILE}\"" >&2
		exit 1
	fi
	printf '%s\n' "${submission}"
}

# signMacPackages replaces the .dmg and the .zip of dist/ with the signed,
# notarized and stapled ones. The work happens in the temporary folder: the
# repository may sit in a synced folder (kDrive, iCloud…) whose client writes
# metadata into files while codesign and stapler rewrite them.
signMacPackages() {
	local dmg zip dir="${work}/sign" details submission_app submission_dmg
	dmg="$(scripts/package.sh names macos arm64 | sed -n 1p)"
	zip="$(scripts/package.sh names macos arm64 | sed -n 2p)"
	[ -d "${APP}" ] || { echo "❌ no ${APP}: did the macOS build run?"; exit 1; }
	mkdir -p "${dir}"
	ditto "${APP}" "${dir}/sidekicks.app"
	xattr -cr "${dir}/sidekicks.app"

	# The app. --options runtime (hardened runtime) and --timestamp are what the
	# notary service requires.
	codesign --force --options runtime --timestamp --sign "${SIGN_IDENTITY}" "${dir}/sidekicks.app"
	codesign --verify --strict --verbose=2 "${dir}/sidekicks.app"
	details="$(codesign -dv --verbose=4 "${dir}/sidekicks.app" 2>&1)"
	local expected
	for expected in "Authority=Developer ID Application" "flags=.*runtime" "Timestamp="; do
		if ! grep -q -- "${expected}" <<<"${details}"; then
			echo "   ❌ the app signature has no ${expected}"
			printf '%s\n' "${details}"
			exit 1
		fi
	done
	echo "   ✅ app signed (Developer ID, hardened runtime, timestamp)"

	ditto -c -k --keepParent "${dir}/sidekicks.app" "${dir}/notarize.zip"
	echo "   ⏳ waiting for Apple's notary service (the app, a few minutes)..."
	submission_app="$(notarize "${dir}/notarize.zip")"
	xcrun stapler staple "${dir}/sidekicks.app"
	spctl -a -vvv -t exec "${dir}/sidekicks.app" 2>&1 | tee "${dir}/spctl-app.txt"
	grep -q "source=Notarized Developer ID" "${dir}/spctl-app.txt" || { echo "   ❌ Gatekeeper does not accept the app"; exit 1; }
	echo "   ✅ app notarized (submission ${submission_app}) and stapled"

	# The .dmg, made from the stapled app, with the layout of `make package-macos`.
	wails3 tool package --format dmg --name sidekicks --out "${dir}" \
		--background build/darwin/dmg-background.png \
		--volume-icon build/darwin/icons.icns \
		--file-icon build/darwin/dmg-file-icon.icns \
		--window-width 540 --window-height 380
	hdiutil verify "${dir}/sidekicks.dmg"
	codesign --force --timestamp --sign "${SIGN_IDENTITY}" "${dir}/sidekicks.dmg"
	echo "   ⏳ waiting for Apple's notary service (the dmg, a few minutes)..."
	submission_dmg="$(notarize "${dir}/sidekicks.dmg")"
	xcrun stapler staple "${dir}/sidekicks.dmg"
	hdiutil verify "${dir}/sidekicks.dmg"
	spctl -a -vvv -t open --context context:primary-signature "${dir}/sidekicks.dmg" 2>&1 | tee "${dir}/spctl-dmg.txt"
	grep -q "source=Notarized Developer ID" "${dir}/spctl-dmg.txt" || { echo "   ❌ Gatekeeper does not accept the dmg"; exit 1; }
	echo "   ✅ dmg signed, notarized (submission ${submission_dmg}) and stapled"

	# Back to dist/, then a copy that must be identical.
	cp "${dir}/sidekicks.dmg" "dist/${dmg}"
	rm -f "dist/${zip}"
	ditto -c -k --keepParent "${dir}/sidekicks.app" "dist/${zip}"
	if ! cmp -s "${dir}/sidekicks.dmg" "dist/${dmg}"; then
		echo "   ❌ dist/${dmg} differs from the signed copy (a synced folder?)"
		exit 1
	fi

	{
		printf 'assets: %s %s\n' "${dmg}" "${zip}"
		grep '^Authority=Developer ID Application' <<<"${details}"
		grep '^TeamIdentifier=' <<<"${details}" || true
		printf 'notarization app: %s Accepted\n' "${submission_app}"
		printf 'notarization dmg: %s Accepted\n' "${submission_dmg}"
	} >"${work}/macos-signature.txt"
}

if [ -n "${SIGN_IDENTITY}" ] && [ "${macos_built}" = true ]; then
	checkSigningSetup
fi

echo "🚀 Building Sidekicks ${VERSION} for ${TAG} — ${ABOUT:-Sidekicks}"
scripts/build-release.sh

if [ "${macos_built}" = true ]; then
	echo ""
	if [ -n "${SIGN_IDENTITY}" ]; then
		echo "🔏 Signing and notarizing the macOS packages..."
		signMacPackages
	else
		echo "⚠️  the macOS packages are not signed: SIGN_IDENTITY is not set in .release.env"
	fi
fi

echo ""
echo "📦 Staging release/${TAG}/"
rm -rf "${assets_dir}"
mkdir -p "${assets_dir}"
# build-release.sh's SHA256SUMS describes the unsigned macOS files: dropped, and
# written again over what ships.
find dist -maxdepth 1 -type f ! -name SHA256SUMS -exec cp {} "${assets_dir}/" \;
if [ -f "${work}/macos-signature.txt" ]; then
	cp "${work}/macos-signature.txt" "${assets_dir}/macos-signature.txt"
fi

# What ships is what scripts/package.sh release-names says, no more, no less.
sums_tmp="${work}/SHA256SUMS"
: >"${sums_tmp}"
for name in $(scripts/package.sh release-names); do
	[ "${name}" = SHA256SUMS ] && continue
	case "${name}" in
		*macos*) [ "${macos_built}" = true ] || continue ;;
		*windows*) case " ${SKIP} " in *" windows "*) continue ;; esac ;;
	esac
	[ -f "${assets_dir}/${name}" ] || { echo "❌ ${assets_dir}/${name} is missing"; exit 1; }
	(cd "${assets_dir}" && if command -v sha256sum >/dev/null; then sha256sum -- "${name}"; else shasum -a 256 -- "${name}"; fi) >>"${sums_tmp}"
done
cp "${sums_tmp}" "${assets_dir}/SHA256SUMS"
chmod 644 "${assets_dir}/SHA256SUMS"
cat "${assets_dir}/SHA256SUMS"

echo ""
ls -lh "${assets_dir}"
echo "✅ ${assets_dir}/ is ready"