Skip to content

Commit ff0c53a

Browse files
committed
add automatic build/notarize
1 parent 121490f commit ff0c53a

22 files changed

Lines changed: 44 additions & 6695 deletions
File renamed without changes.
File renamed without changes.
File renamed without changes.

Project/Sources/Classes/_Build.4dm

Lines changed: 35 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Function Compile($options : Object)->$error : Object
1010
End if
1111

1212
Function Build($PathToSettings : Text)->$error : Object
13+
// this function uses LAUNCH EXTERNAL PROCESS and not 4D.SystemWorker to allow v19 LTS to use the class
1314
If (Count parameters:C259>0)
1415
This:C1470._SettingsUsed:=$PathToSettings
1516
Else
@@ -24,29 +25,45 @@ Function Build($PathToSettings : Text)->$error : Object
2425
$error:=New object:C1471("success"; True:C214)
2526
End if
2627

27-
Function Notarize($zipfilepath : Text; $appleUserID : Text; $bundleID)->$error : Object
28+
Function Notarize($zipfilepath : Text)->$error : Object
2829
ASSERT:C1129($zipfilepath#""; "zip file path must not be empty")
29-
ASSERT:C1129($appleUserID#""; "apple ID must not be empty")
30-
ASSERT:C1129($bundleID#""; "bundle ID must not be empty")
3130
$in:=""
3231
$out:=""
3332
$err:=""
34-
$cmd:="xcrun altool --notarize-app --primary-bundle-id "+Char:C90(34)+$bundleID+Char:C90(34)+" --username "+Char:C90(34)+$appleUserID+Char:C90(34)+\
35-
" --password \"@keychain:altool\" --file "+Char:C90(34)+Convert path system to POSIX:C1106($zipfilepath)+Char:C90(34)
33+
$cmd:="xcrun notarytool submit "+Char:C90(34)+Convert path system to POSIX:C1106($zipfilepath)+Char:C90(34)+" --keychain-profile notarytool --wait"
3634
LAUNCH EXTERNAL PROCESS:C811($cmd; $in; $out; $err)
37-
If (($err#"") & ($err#"@CFURLRequestSetHTTPCookieStorageAcceptPolicy@"))
35+
If (($err#"") & ($err#"@Current status: Accepted@"))
3836
$error:=New object:C1471("success"; False:C215; "log"; $err)
3937
Else
40-
If ($out="No errors@")
41-
$col:=Split string:C1554($out; Char:C90(10))
42-
If ($col[1]="RequestUUID = @")
43-
$error:=New object:C1471("success"; True:C214; "uuid"; Substring:C12($col[1]; Length:C16("RequestUUID = ")))
38+
Case of
39+
: ($out="@ status: Accepted@")
40+
$error:=New object:C1471("success"; True:C214)
41+
: ($out="@ status: Invalid@")
42+
$pos:=Position:C15(" id: "; $out)
43+
If ($pos>0)
44+
$id:=Substring:C12($out; $pos+7)
45+
$pos:=Position:C15(Char:C90(10); $id)
46+
$id:=Substring:C12($id; 1; $pos)
47+
$in:=""
48+
$out2:=""
49+
$err:=""
50+
$logpath:=Get 4D folder:C485(Logs folder:K5:19)+"notarizing log.json"
51+
$cmd:="xcrun notarytool log "+$id+" --keychain-profile \"notarytool\" "+Char:C90(34)+Convert path system to POSIX:C1106($logpath)+Char:C90(34)
52+
LAUNCH EXTERNAL PROCESS:C811($cmd; $in; $out2; $err)
53+
If (Test path name:C476($logpath)=Is a document:K24:1)
54+
$logtext:=Document to text:C1236($logpath)
55+
$log:=JSON Parse:C1218($logtext)
56+
Else
57+
$log:=New object:C1471
58+
End if
59+
$error:=New object:C1471("success"; False:C215; "log"; $out; "id"; $id; "invalid"; $log)
60+
Else
61+
$error:=New object:C1471("success"; False:C215; "log"; $out)
62+
End if
4463
Else
4564
$error:=New object:C1471("success"; False:C215; "log"; $out)
46-
End if
47-
Else
48-
$error:=New object:C1471("success"; False:C215; "log"; $out)
49-
End if
65+
End case
66+
5067
End if
5168

5269
Function Zip($sourcepath : Text; $targetpath : Text)->$error : Object
@@ -62,7 +79,7 @@ Function Zip($sourcepath : Text; $targetpath : Text)->$error : Object
6279
: ($value="::@")
6380
// cannot use Folder(fk database folder).parent, as we need to go outside of protected area
6481
$sourcefolder:=Folder:C1567(Get 4D folder:C485(Database folder:K5:14); fk platform path:K87:2)
65-
$sourcefolder:=Folder:C1567($sourcefolder.parent.platformPath+Substring:C12($value; 3)+Folder separator:K24:12+"Components"; fk platform path:K87:2)
82+
$sourcefolder:=Folder:C1567($sourcefolder.parent.platformPath+Substring:C12($value; 3)+"Components"; fk platform path:K87:2)
6683
$sourcefolderfiles:=$sourcefolder.folders()
6784
If ($sourcefolderfiles.length>0)
6885
$source:=$sourcefolderfiles[0].platformPath
@@ -112,88 +129,17 @@ Function Zip($sourcepath : Text; $targetpath : Text)->$error : Object
112129
$error:=New object:C1471("success"; False:C215; "reason"; "source or target path empty")
113130
End if
114131

115-
Function CheckNotarizeResult($uuid : Text; $appleUserID : Text)->$error : Object
116-
ASSERT:C1129($uuid#""; "uuid must not be empty")
117-
ASSERT:C1129($appleUserID#""; "userid must not be empty")
118-
119-
$cmd:="xcrun altool --notarization-info "+$uuid+" -u "+Char:C90(34)+$appleUserID+Char:C90(34)+" -p \"@keychain:altool\""
120-
$in:=""
121-
$out:=""
122-
$err:=""
123-
LAUNCH EXTERNAL PROCESS:C811($cmd; $in; $out; $err)
124-
If (($err#"") & ($err#"@CFURLRequestSetHTTPCookieStorageAcceptPolicy@"))
125-
$error:=New object:C1471("success"; False:C215; "log"; "Notarize check: "+$err)
126-
Else
127-
/* out in form
128-
No errors getting notarization info.
129-
130-
Date: 2020-10-21 09:37:09 +0000
131-
Hash: dbc021eb12665fb13a9a18304214e89c9bb7560246a01b08f97dbae549697bfd
132-
LogFileURL: https://osxapps-ssl.itunes.apple.com/itunes-assets/Enigma124/v4/3f/84/9f/3f849f12-4cd5-0546-4181-a5d93c9cb074/developer_log.json?accessKey=1603467816_2930840265156000602_k5fSZxEZa3Cs89MYH3GfQYEpecMBF1ErZYK2rgbGgY0HoMPs1CgH5nlLAaYQRtEymMK6IsLkdXUgfL2FTG7IfYQe12Zj8wzuirYUB3rQXvfF6a6DrX%2BQxe6Wjc1DkD8kz14lR%2Bqk6VdfVGAOAsy%2B2%2FJ80DgIxv779wR14Jn2a40%3D
133-
RequestUUID: 7ee7da40-ef75-45f4-ba9d-6b8d61c29b67
134-
Status: invalid
135-
Status Code: 2
136-
Status Message: Package Invalid
137-
*/
138-
C_COLLECTION:C1488($lines; $parts)
139-
$lines:=Split string:C1554($out; Char:C90(10); sk trim spaces:K86:2+sk ignore empty strings:K86:1)
140-
$result:=New object:C1471
141-
For each ($line; $lines)
142-
$parts:=Split string:C1554($line; ":"; sk trim spaces:K86:2+sk ignore empty strings:K86:1)
143-
If ($parts.length=2)
144-
$result[$parts[0]]:=$parts[1]
145-
End if
146-
End for each
147-
148-
Case of
149-
: ($result.Status=Null:C1517)
150-
$error:=New object:C1471("success"; False:C215; "log"; "Notarize check error status missing "+$out)
151-
: ($result.Status="invalid")
152-
$error:=New object:C1471("success"; False:C215; "log"; "Notarize check error status invalid "+$out)
153-
: ($result.Status="in progress")
154-
$error:=New object:C1471("success"; True:C214; "status"; "in progress")
155-
: ($result.Status="success")
156-
$error:=New object:C1471("success"; True:C214; "status"; "success")
157-
End case
158-
End if
159132

160-
Function Staple($zipfilepath : Text; )->$error : Object
161-
$cmd:="xcrun stapler staple '"+Convert path system to POSIX:C1106($zipfilepath)+"'"
133+
Function Staple()->$error : Object
134+
$cmd:="xcrun stapler staple '"+Convert path system to POSIX:C1106(This:C1470._Source)+"'"
162135
$in:=""
163136
$out:=""
164137
$err:=""
165138
LAUNCH EXTERNAL PROCESS:C811($cmd; $in; $out; $err)
166-
If (($err#"") & ($err#"@CFURLRequestSetHTTPCookieStorageAcceptPolicy@"))
139+
If ($err#"")
167140
$error:=New object:C1471("success"; False:C215; "log"; "Staple error "+$out)
168141
Else
169142
$source:=This:C1470._Source
170143
$error:=This:C1470.Zip($source)
171144
End if
172-
173-
Function CommitAndPush($message : Text)->$error : Object
174-
$path:=Get 4D folder:C485(Database folder:K5:14; *)
175-
SET ENVIRONMENT VARIABLE:C812("_4D_OPTION_CURRENT_DIRECTORY"; $path)
176-
$in:=""
177-
$out:=""
178-
$err:=""
179-
LAUNCH EXTERNAL PROCESS:C811("git add --all"; $in; $out; $err)
180-
If (($out#"") | ($err#""))
181-
$error:=New object:C1471("success"; False:C215; "Error git add"; $out+" "+$err)
182-
Else
183-
SET ENVIRONMENT VARIABLE:C812("_4D_OPTION_CURRENT_DIRECTORY"; $path)
184-
$command:="git commit -a -q -m "+Char:C90(34)+$message+Char:C90(34)
185-
LAUNCH EXTERNAL PROCESS:C811($command; $in; $out; $err)
186-
If (($out#"") | ($err#""))
187-
$error:=New object:C1471("success"; False:C215; "Error git commit"; $out+" "+$err)
188-
Else
189-
SET ENVIRONMENT VARIABLE:C812("_4D_OPTION_CURRENT_DIRECTORY"; $path)
190-
LAUNCH EXTERNAL PROCESS:C811("git push"; $in; $out; $err)
191-
If ($err#"")
192-
$error:=New object:C1471("success"; False:C215; "Error git push"; $err)
193-
Else
194-
$error:=New object:C1471("success"; True:C214; "git commit"; $out)
195-
End if
196-
End if
197-
End if
198-
199145

Project/Sources/Methods/__buildComponent.4dm

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@ After an XCode/System update another manual run might be necesssary to accept mo
1919
2020
###########
2121
expects that you have installed your password in keychain named "altool" with:
22-
security add-generic-password -a "<apple_id>" -w "<password>" -s "altool"
22+
xcrun altool --list-providers -u "AC_USERNAME" -p secret_2FA_password
2323
Sign in to your Apple ID account page. In the Security section, click the “Generate Password” option below the “App-Specific Passwords” option, enter a password label as requested and click the “Create” button.
24-
If unclear, read blog!
24+
If unclear, read Apple docu above!
2525
2626
########### NOTES
2727
you might need to start Xcode once manually after every macOS update to accept Xcode changes
2828
you might need to start Xcode to accept Apple contract changes or update expired certificates (visit developer.apple.com)
2929
*/
3030

31-
$appleUserID:="Thomas.Maul"+Char:C90(64)+"4D.com" // I don't like my email on github in clear text
32-
$bundleID:="FileTransfer.de.4D.com"
33-
3431
var $builder : cs:C1710._Build
3532

3633
$builder:=cs:C1710._Build.new()
@@ -41,7 +38,7 @@ Progress SET MESSAGE($progress; "Compile...")
4138
$error:=$builder.Compile()
4239
If ($error.success=True:C214)
4340
Progress SET MESSAGE($progress; "Build...")
44-
$error:=$builder.Build()
41+
$error:=$builder.Build() // $1 could be path to settings, if you have other than default ones
4542
End if
4643

4744
If ($error.success=True:C214)
@@ -51,43 +48,14 @@ End if
5148

5249
If ($error.success=True:C214)
5350
$target:=$error.target
54-
Progress SET MESSAGE($progress; "Notarize...")
55-
$error:=$builder.Notarize($target; $appleUserID; $bundleID) // returned by zip
51+
Progress SET MESSAGE($progress; "Notarize and wait for Apple's approval...")
52+
$error:=$builder.Notarize($target) // returned by zip
5653
End if
5754

5855
If ($error.success=True:C214)
59-
$UUID:=$error.uuid
60-
If ($uuid="")
61-
$error:=New object:C1471("success"; False:C215; "log"; "Notarize UUID empty")
62-
Else
63-
// now we need to wait - show progress bar?
64-
65-
$finished:=False:C215
66-
While ((Not:C34($finished)) & (Not:C34(Process aborted:C672)))
67-
Progress SET MESSAGE($progress; "Checking Notarization: "+String:C10(Current time:C178))
68-
DELAY PROCESS:C323(Current process:C322; 30*60) // check twice a minute
69-
$error:=$builder.CheckNotarizeResult($uuid; $appleUserID)
70-
Case of
71-
: ($error.success=False:C215)
72-
$finished:=True:C214
73-
: (($error.success=True:C214) & ($error.status="in progress"))
74-
// nothing, continue loop
75-
: (($error.success=True:C214) & ($error.status="success"))
76-
// finished! Now we can staple and rezip
77-
Progress SET MESSAGE($progress; "Success - now running staple")
78-
$error:=$builder.Staple($target)
79-
$finished:=True:C214
80-
End case
81-
End while
82-
End if
56+
$error:=$builder.Staple($target)
8357
End if
8458

85-
//If ($error.success=True)
86-
//Progress SET MESSAGE($progress; "Push to Git...")
87-
//$message:=Request("Commit message"; Timestamp)
88-
//$error:=$builder.CommitAndPush($message)
89-
//End if
90-
9159
Progress QUIT($progress)
9260

9361

Readme.MD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ $result:=$ftp.download($source; $target)
6464
# Documentation
6565

6666
## cURL (FTP - FTPS - SFTP - HTTP - HTTPS)
67-
[Documentation](ReadMe_curl.MD)
67+
[Documentation](Documentation/ReadMe_curl.MD)
6868

6969
## Dropbox
70-
[Documentation](ReadMe_dropbox.MD)
70+
[Documentation](Documentation/ReadMe_dropbox.MD)
7171

7272
## GDrive
73-
[Documentation](ReadMe_GDrive.MD)
73+
[Documentation](Documentation/ReadMe_GDrive.MD)
7474

7575

0 commit comments

Comments
 (0)