@@ -38,59 +38,83 @@ notarizefile() { # $1: path to file to notarize, $2: identifier
3838 filepath=${1:? " need a filepath" }
3939 identifier=${2:? " need an identifier" }
4040
41- # upload file
41+ # upload file and wait for completion
4242 echo " ## uploading $filepath for notarization"
43- requestUUID =$( xcrun notarytool submit --wait \
43+ SUBMIT_OUTPUT =$( xcrun notarytool submit --wait \
4444 --keychain-profile " $dev_keychain_label " \
45- " $filepath " 2>&1 |
46- awk ' / id:/ { print $NF; }' | tail -n 1)
45+ " $filepath " 2>&1 )
4746
48- echo " Notarization RequestUUID: $requestUUID "
47+ echo " $SUBMIT_OUTPUT "
48+
49+ # Extract the request UUID
50+ requestUUID=$( echo " $SUBMIT_OUTPUT " | awk ' / id:/ { print $NF; }' | tail -n 1)
4951
5052 if [[ $requestUUID == " " ]]; then
51- echo " could not upload for notarization"
52- exit 1
53+ echo " ## Error: could not get notarization request UUID "
54+ return 1
5355 fi
5456
55- # # wait for status to be not "in progress" any more
56- # request_status="In Progress"
57-
58- # while [[ "$request_status" == "In Progress" ]]; do
59- # echo -n "waiting... "
60- # sleep 10
61- # request_status=$(requeststatus "$requestUUID")
62- # echo "$request_status"
63- # done
57+ echo " Notarization RequestUUID: $requestUUID "
6458
65- # print status information
66- xcrun notarytool info \
59+ # Get detailed status
60+ echo " ## Checking notarization status..."
61+ STATUS_OUTPUT=$( xcrun notarytool info \
6762 --keychain-profile " $dev_keychain_label " \
68- " $requestUUID "
69- echo
63+ " $requestUUID " 2>&1 )
7064
71- # if [[ $request_status != "success" ]]; then
72- # echo "## could not notarize $filepath"
73- # exit 1
74- # fi
65+ echo " $STATUS_OUTPUT "
7566
67+ # Extract status
68+ request_status=$( echo " $STATUS_OUTPUT " | awk -F ' : ' ' /status:/ { print $2; }' | head -1 | tr -d ' ' )
69+
70+ if [[ " $request_status " == " Accepted" ]]; then
71+ echo " ## ✓ Notarization succeeded!"
72+ return 0
73+ else
74+ echo " ## ✗ Notarization failed with status: $request_status "
75+ echo " ## Getting notarization logs..."
76+ xcrun notarytool log \
77+ --keychain-profile " $dev_keychain_label " \
78+ " $requestUUID " 2>&1 | head -50
79+ return 1
80+ fi
7681}
7782
7883# Build the binary
7984xcrun swift build -c release --arch arm64 --arch x86_64
8085bindir=$( xcrun swift build -c release --arch arm64 --arch x86_64 --show-bin-path)
8186
8287# Determine signing identity for binary (allow override via environment variable)
83- # Default to 3rd Party Mac Developer Application (for Mac App Store) or Developer ID Application (for direct distribution)
84- APP_SIGNING_IDENTITY=" ${APP_SIGNING_IDENTITY:- 3rd Party Mac Developer Application: Brett Terpstra (47TRS7H4BH)} "
88+ # Try Developer ID Application first (for notarization), fall back to 3rd Party Mac Developer Application
89+ if [ -z " $APP_SIGNING_IDENTITY " ]; then
90+ # Try Developer ID Application first
91+ if security find-identity -v -p codesigning | grep -q " Developer ID Application: Brett Terpstra (47TRS7H4BH)" ; then
92+ APP_SIGNING_IDENTITY=" Developer ID Application: Brett Terpstra (47TRS7H4BH)"
93+ else
94+ # Fall back to 3rd Party Mac Developer Application
95+ APP_SIGNING_IDENTITY=" 3rd Party Mac Developer Application: Brett Terpstra (47TRS7H4BH)"
96+ fi
97+ fi
8598
8699# Initialize notarization flag - will be set based on PKG signing success
87100SKIP_NOTARIZATION=true
88101
89102# Check if the identity exists, if not use ad-hoc signing
90103if security find-identity -v -p codesigning | grep -q " $APP_SIGNING_IDENTITY " ; then
91104 echo " ## Signing binary with: $APP_SIGNING_IDENTITY "
92- codesign --force --verbose --sign " $APP_SIGNING_IDENTITY " -o runtime --timestamp $bindir /$executable
93- codesign --verify -vvvv $bindir /$executable
105+ if codesign --force --verbose --sign " $APP_SIGNING_IDENTITY " -o runtime --timestamp $bindir /$executable 2>&1 ; then
106+ codesign --verify -vvvv $bindir /$executable
107+ # Check if we're using Developer ID Application (required for notarization)
108+ if [[ " $APP_SIGNING_IDENTITY " == * " Developer ID Application" * ]]; then
109+ echo " ## ✓ Binary signed with Developer ID Application (ready for notarization)"
110+ else
111+ echo " ## Note: Using 3rd Party certificate - notarization will be skipped"
112+ fi
113+ else
114+ echo " ## Warning: Failed to sign with '$APP_SIGNING_IDENTITY ', trying ad-hoc signing"
115+ codesign --force --verbose --sign " -" $bindir /$executable
116+ codesign --verify -vvvv $bindir /$executable
117+ fi
94118else
95119 echo " ## Warning: Identity '$APP_SIGNING_IDENTITY ' not found, using ad-hoc signing for binary"
96120 codesign --force --verbose --sign " -" $bindir /$executable
@@ -117,7 +141,13 @@ if [ -n "$INSTALLER_SIGNATURE" ] && [ "$INSTALLER_SIGNATURE" != "-" ]; then
117141 " $pkgpath " 2>&1 ; then
118142 echo " ## ✓ PKG signed successfully"
119143 # PKG is signed with Developer ID Installer, can be notarized
120- SKIP_NOTARIZATION=false
144+ # BUT: Binary must also be signed with Developer ID Application for notarization to succeed
145+ if [[ " $APP_SIGNING_IDENTITY " == * " Developer ID Application" * ]]; then
146+ SKIP_NOTARIZATION=false
147+ else
148+ echo " ## Note: Binary not signed with Developer ID Application - notarization will be skipped"
149+ SKIP_NOTARIZATION=true
150+ fi
121151 else
122152 PKG_BUILD_EXIT=$?
123153 echo " ## Warning: Failed to sign with '$INSTALLER_SIGNATURE ' (exit code: $PKG_BUILD_EXIT ), building unsigned pkg"
@@ -143,11 +173,20 @@ if [ "$SKIP_NOTARIZATION" = "false" ]; then
143173 # upload for notarization
144174 echo " Path: $pkgpath "
145175 echo " Identifier $identifier "
146- notarizefile " $pkgpath " " $identifier "
147-
148- # staple result
149- echo " ## Stapling $pkgpath "
150- xcrun stapler staple " $pkgpath "
176+ if notarizefile " $pkgpath " " $identifier " ; then
177+ # Only staple if notarization succeeded
178+ echo " ## Stapling $pkgpath "
179+ xcrun stapler staple " $pkgpath "
180+ if [ $? -eq 0 ]; then
181+ echo " ## ✓ Package stapled successfully"
182+ else
183+ echo " ## Warning: Stapling failed"
184+ fi
185+ else
186+ echo " ## Error: Notarization failed, skipping stapling"
187+ echo " ## The PKG is signed but not notarized. You may need to fix signing issues."
188+ exit 1
189+ fi
151190else
152191 echo " ## Skipping notarization (ad-hoc or unsigned build)"
153192fi
0 commit comments