Debian Codegraph @

.ci/macos/notarize.sh

raw symbols SCIP
1 #!/bin/bash
2
3 set -u
4
5 # Modified version of script found at:
6 # https://forum.qt.io/topic/96652/how-to-notarize-qt-application-on-macos/18
7
8 # Add Qt binaries to path
9 export QTPATH=(${PATH}/Qt/6.*/macos/bin)
10 pipx ensurepath
11 . ~/.zshrc
12 export PATH=${QTPATH}:${PATH}
13
14 security unlock-keychain -p "${RUNNER_USER_PW}" login.keychain
15
16 if [ -n "${CI_PIPELINE_TRIGGERED:-}" ] && [ "${TRIGGERED_BY:-}" = "cirrus" ]; then
17 echo "cirrus build id: ${TRIGGER_BUILD_ID}"
18 cat "${TRIGGER_PAYLOAD}"
19 # download the build artifacts from cirrus api
20 curl "https://api.cirrus-ci.com/v1/artifact/build/${TRIGGER_BUILD_ID}/binaries.zip" -o binaries.zip
21 # cirrus ci artifacts task name is 'binaries' so that's the zip name.
22 unzip binaries.zip
23 # we zip 'build/nheko.app' in cirrus ci, cirrus itself puts it in a 'build' directory
24 # so move it to the right place for the rest of the process.
25 unzip nheko.zip
26 fi
27
28 if [ ! -d "nheko.app" ]; then
29 echo "nheko.app is missing, you did something wrong!"
30 exit 1
31 fi
32
33 echo "[INFO] Signing app contents"
34 find "nheko.app/Contents"|while read -r fname; do
35 if [ -f "$fname" ]; then
36 echo "[INFO] Signing $fname"
37 codesign --force --timestamp --options=runtime --sign "${APPLE_DEV_IDENTITY}" "$fname"
38 fi
39 done
40
41 codesign --force --timestamp --options=runtime --sign "${APPLE_DEV_IDENTITY}" "nheko.app"
42
43 NOTARIZE_SUBMIT_LOG=$(mktemp /tmp/notarize-submit.XXXXXX)
44 NOTARIZE_STATUS_LOG=$(mktemp /tmp/notarize-status.XXXXXX)
45
46 finish() {
47 rm "$NOTARIZE_SUBMIT_LOG" "$NOTARIZE_STATUS_LOG"
48 }
49 trap finish EXIT
50
51 dmgbuild -s .ci/macos/settings.json "Nheko" nheko.dmg
52 codesign -s "${APPLE_DEV_IDENTITY}" nheko.dmg
53
54 user=$(id -nu)
55 chown "${user}" nheko.dmg
56
57 echo "--> Start Notarization process"
58 # OLD altool usage: xcrun altool -t osx -f nheko.dmg --primary-bundle-id "io.github.nheko-reborn.nheko" --notarize-app -u "${APPLE_DEV_USER}" -p "${APPLE_DEV_PASS}" > "$NOTARIZE_SUBMIT_LOG" 2>&1
59 xcrun notarytool submit nheko.dmg --apple-id "${APPLE_DEV_USER}" --password "${APPLE_DEV_PASS}" --team-id "${APPLE_TEAM_ID}" > "$NOTARIZE_SUBMIT_LOG" 2>&1
60 # OLD altool usage: requestUUID="$(awk -F ' = ' '/RequestUUID/ {print $2}' "$NOTARIZE_SUBMIT_LOG")"
61 requestUUID="$(awk -F ': ' '/id/ {print $2}' "$NOTARIZE_SUBMIT_LOG" | head -1)"
62
63 if [ -z "${requestUUID}" ]; then
64 echo "Something went wrong when submitting the request... we don't have a UUID"
65 exit 1
66 else
67 echo "Received requestUUID: \"${requestUUID}\""
68 fi
69
70 while sleep 60 && date; do
71 echo "--> Checking notarization status for \"${requestUUID}\""
72
73 # OLD altool usage: xcrun altool --notarization-info "${requestUUID}" -u "${APPLE_DEV_USER}" -p "${APPLE_DEV_PASS}" > "$NOTARIZE_STATUS_LOG" 2>&1
74 xcrun notarytool info "${requestUUID}" --apple-id "${APPLE_DEV_USER}" --password "${APPLE_DEV_PASS}" --team-id "${APPLE_TEAM_ID}" > "$NOTARIZE_STATUS_LOG" 2>&1
75
76 sub_status="$(awk -F ': ' '/status/ {print $2}' "$NOTARIZE_STATUS_LOG")"
77 #isSuccess=$(grep "success" "$NOTARIZE_STATUS_LOG")
78 #isFailure=$(grep "invalid" "$NOTARIZE_STATUS_LOG")
79
80 echo "Status for submission \"${requestUUID}\": \"${sub_status}\""
81
82 if [ "${sub_status}" = "Accepted" ]; then
83 echo "Notarization done!"
84 xcrun stapler staple -v nheko.dmg
85 echo "Stapler done!"
86 break
87 fi
88 if [ "${sub_status}" = "Invalid" ] || [ "${sub_status}" = "Rejected" ]; then
89 echo "Notarization failed"
90 xcrun notarytool log "${requestUUID}" --apple-id "${APPLE_DEV_USER}" --password "${APPLE_DEV_PASS}" --team-id "${APPLE_TEAM_ID}" > "$NOTARIZE_STATUS_LOG" 2>&1
91 cat "$NOTARIZE_STATUS_LOG" 1>&2
92 exit 1
93 fi
94 echo "Notarization not finished yet, sleep 1m then check again..."
95 done
96
97 VERSION=${CI_COMMIT_SHORT_SHA}
98
99 if [ -n "$VERSION" ]; then
100 mv nheko.dmg "nheko-${VERSION}-${PLAT}.dmg"
101 mkdir -p artifacts
102 cp "nheko-${VERSION}-${PLAT}.dmg" artifacts/
103 fi