Skip to content

Commit

Permalink
Use notarytool instead of altool (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson authored Oct 18, 2023
1 parent 8818503 commit ed8ba8b
Showing 1 changed file with 5 additions and 60 deletions.
65 changes: 5 additions & 60 deletions automation/macos_notarization.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,17 @@ ext.notarize = { File application, String id, String username, String password -

// Step 2: submit application for notarization.
println "Submitting application to notarization service..."
def stdout = new ByteArrayOutputStream()
def result = exec {
commandLine "xcrun", "altool", "--output-format", "json", "--notarize-app", "-f", "/tmp/archive.zip",
"--primary-bundle-id", id, "-u", username, "-p", password
standardOutput = stdout
commandLine "xcrun", "notarytool", "submit", "/tmp/archive.zip", "--wait",
"--apple-id", username, "--password", password
ignoreExitValue(true)
}

if (result.exitValue != 0) {
println stdout.toString()
return
throw new GradleException("The notarization failed!")
}

// Step 3: process the request UUID.
def parser = new JsonSlurper()
def object = parser.parseText(stdout.toString())
def uuid = object["notarization-upload"]["RequestUUID"] as String
println "Submitted application with UUID: $uuid"

// Step 4: wait until notarization is complete.
def success = false
String[] args = ["xcrun", "altool", "--output-format", "json", "--notarization-info", uuid,
"-u", username, "-p", password]

for (int i = 0; i < 40; i++) {
stdout = new ByteArrayOutputStream()
result = exec {
commandLine args
standardOutput = stdout
ignoreExitValue(true)
}

if (result.exitValue != 0) {
println stdout.toString()
return
}

def response = parser.parseText(stdout.toString())["notarization-info"]
def exit = false

switch (response["Status"] as String) {
case "in progress":
println "Notarization is in progress..."
break
case "invalid":
exit = true
println "Notarization was invalid: ${response["Status Message"] as String}"
break
case "success":
exit = true
success = true
println "Notarization succeeded!"
break
default:
exit = true
println "Unknown status"
break
}

if (exit) break
Thread.sleep(30000)
}

if (!success) throw new GradleException("The notarization failed!")

// Step 5: staple the notarization ticket.
// Step 3: staple the notarization ticket.
println "Stapling notarization ticket..."
exec { commandLine "xcrun", "stapler", "staple", "-v", application.getAbsolutePath() }
}
}

0 comments on commit ed8ba8b

Please sign in to comment.