Skip to content

Commit 27a9e19

Browse files
authored
Improve MAS process (#24)
1 parent d2b089f commit 27a9e19

File tree

2 files changed

+92
-71
lines changed

2 files changed

+92
-71
lines changed

.github/workflows/create-release-windows.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ jobs:
2525
steps:
2626
- uses: msys2/setup-msys2@v2
2727
with:
28+
# ucrt64 is for modern windows.
29+
msystem: UCRT64
2830
update: true
31+
# gcc is not the same as mingw-w64-ucrt-x86_64-gcc and is not for building a linked dll.
2932
install: >-
3033
curl
3134
git
32-
gcc
35+
mingw-w64-ucrt-x86_64-gcc
3336
unzip
3437
- uses: actions/setup-node@v4
3538
with:

build.gradle.kts

Lines changed: 88 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,28 @@ val macDeveloperApplicationCertName = if (isNotarizing) {
4646
} else {
4747
"3rd Party Mac Developer Application: Tanin Na Nakorn (S6482XAL5E)"
4848
}
49-
val appleEmail = if (System.getenv("APPLE_EMAIL") != null) {
50-
System.getenv("APPLE_EMAIL")
51-
} else {
52-
try {
53-
project.file("./secret/APPLE_EMAIL").readText().trim()
54-
} catch (e: Exception) {
55-
"The-apple-email-is-not-specified"
49+
50+
fun getSecret(envKey: String, filePath: String): String? {
51+
if (System.getenv(envKey) != null) {
52+
return System.getenv(envKey)
5653
}
57-
}
58-
val appleAppSpecificPassword = if (System.getenv("APPLE_APP_SPECIFIC_PASSWORD") != null) {
59-
System.getenv("APPLE_APP_SPECIFIC_PASSWORD")
60-
} else {
54+
6155
try {
62-
project.file("./secret/APPLE_APP_SPECIFIC_PASSWORD").readText().trim()
56+
return project.file(filePath).readText().trim()
6357
} catch (e: Exception) {
64-
"The-apple-app-specific-password-is-not-specified"
58+
return null
6559
}
6660
}
61+
62+
val appleEmail = getSecret("APPLE_EMAIL", "./secret/APPLE_EMAIL")
63+
val appleAppSpecificPassword = getSecret("APPLE_APP_SPECIFIC_PASSWORD","./secret/APPLE_APP_SPECIFIC_PASSWORD")
6764
val appleTeamId = "S6482XAL5E"
6865

6966
group = "tanin.javaelectron"
7067
val appName = "JavaElectron"
7168
val packageIdentifier = "tanin.javaelectron.macos.app"
7269
version = "1.1"
73-
val internalVersion = "1.1.0"
70+
val internalVersion = "1.1.1"
7471

7572
description = "Build cross-platform desktop apps with Java, JavaScript, HTML, and CSS"
7673

@@ -301,24 +298,34 @@ private fun runCmd(vararg args: String): String {
301298
return runCmd(layout.projectDirectory.asFile, *args)
302299
}
303300

304-
private fun codesign(file: File, useRuntimeEntitlement: Boolean = false) {
301+
enum class EntitlementType {
302+
NoEntitlement,
303+
MainEntitlement,
304+
RuntimeEntitlement
305+
}
306+
307+
308+
private fun codesign(file: File, entitlementType: EntitlementType = EntitlementType.NoEntitlement) {
305309
if (currentOS == OS.MAC) {
310+
val entitlementArgs = when (entitlementType) {
311+
EntitlementType.NoEntitlement -> emptyList()
312+
EntitlementType.MainEntitlement -> listOf("--entitlements", "entitlements.plist")
313+
EntitlementType.RuntimeEntitlement -> listOf("--entitlements", "runtime-entitlements.plist")
314+
}
315+
306316
runCmd(
307-
"codesign",
308-
"-vvvv",
309-
"--options",
310-
"runtime",
311-
"--entitlements",
312-
if (useRuntimeEntitlement) {
313-
"runtime-entitlements.plist"
314-
} else {
315-
"entitlements.plist"
316-
},
317-
"--timestamp",
318-
"--force",
319-
"--sign",
320-
macDeveloperApplicationCertName,
321-
file.absolutePath,
317+
*(listOf(
318+
"codesign",
319+
"-vvvv",
320+
"--options",
321+
"runtime",
322+
) + entitlementArgs + listOf(
323+
"--timestamp",
324+
"--force",
325+
"--sign",
326+
macDeveloperApplicationCertName,
327+
file.absolutePath,
328+
)).toTypedArray()
322329
)
323330
}
324331
}
@@ -359,10 +366,9 @@ private fun codesignInJar(jarFile: File, nativeLibPath: File) {
359366
tmpDir.walk()
360367
.filter { it.isFile && isCodesignable(it) }
361368
.forEach { libFile ->
369+
codesign(libFile)
362370

363371
if (isValidLibFile(libFile)) {
364-
println("")
365-
codesign(libFile)
366372
runCmd("cp", libFile.absolutePath, nativeLibPath.absolutePath)
367373
}
368374

@@ -402,11 +408,11 @@ tasks.register("codesignLibsInJars") {
402408
}
403409
}
404410

405-
private fun codesignDir(dir: File, useRuntimeEntitlement: Boolean = false) {
411+
private fun codesignDir(dir: File) {
406412
dir.walk()
407413
.filter { it.isFile && isCodesignable(it) }
408414
.forEach { libFile ->
409-
codesign(libFile, useRuntimeEntitlement)
415+
codesign(libFile, EntitlementType.NoEntitlement)
410416
}
411417
}
412418

@@ -423,7 +429,7 @@ tasks.register("macosCodesignProvisionprofile") {
423429
codesign(provisionprofileDir.file("embedded.provisionprofile").asFile)
424430

425431
removeQuarantine(provisionprofileDir.file("runtime.provisionprofile").asFile)
426-
codesign(provisionprofileDir.file("runtime.provisionprofile").asFile, useRuntimeEntitlement = true)
432+
codesign(provisionprofileDir.file("runtime.provisionprofile").asFile)
427433
}
428434
}
429435

@@ -580,10 +586,14 @@ tasks.register("jpackageForMac") {
580586
outputAppFile.resolve("Contents/runtime/Contents/embedded.provisionprofile").toPath()
581587
)
582588

583-
codesignDir(outputAppFile.resolve("Contents/runtime"), useRuntimeEntitlement = true)
589+
codesignDir(outputAppFile.resolve("Contents/runtime"))
584590

585-
codesign(outputAppFile.resolve("Contents/runtime"), useRuntimeEntitlement = true)
586-
codesign(outputAppFile)
591+
codesign(
592+
outputAppFile.resolve("Contents/runtime/Contents/Home/lib/jspawnhelper"),
593+
EntitlementType.RuntimeEntitlement
594+
)
595+
codesign(outputAppFile.resolve("Contents/runtime"))
596+
codesign(outputAppFile, EntitlementType.MainEntitlement)
587597

588598
outputDmgDir.deleteRecursively()
589599
outputDmgDir.mkdirs()
@@ -626,7 +636,7 @@ tasks.register("jpackageForWindows") {
626636
"sign",
627637
"-input_file_path=${inputs.files.singleFile.absolutePath}",
628638
"-output_dir_path=${outputAppDir.absolutePath}",
629-
"-program_name=JavaElectron",
639+
"-program_name=${appName}",
630640
"-username=${System.getenv("SSL_COM_USERNAME")}",
631641
"-password=${System.getenv("SSL_COM_PASSWORD")}",
632642
"-totp_secret=${System.getenv("SSL_COM_TOTP_SECRET")}",
@@ -641,21 +651,23 @@ tasks.register("jpackage") {
641651
dependsOn("bareJpackage", "jpackageForMac", "jpackageForWindows")
642652
}
643653

644-
tasks.register<Exec>("notarize") {
654+
tasks.register("notarize") {
645655
dependsOn("jpackageForMac")
646656

647657
inputs.file(tasks.named("jpackageForMac").get().outputs.files.filter { it.extension == "dmg" }.first())
648658

649-
commandLine(
650-
"/usr/bin/xcrun",
651-
"notarytool",
652-
"submit",
653-
"--wait",
654-
"--apple-id", appleEmail,
655-
"--password", appleAppSpecificPassword,
656-
"--team-id", appleTeamId,
657-
inputs.files.singleFile.absolutePath,
658-
)
659+
doLast {
660+
runCmd(
661+
"/usr/bin/xcrun",
662+
"notarytool",
663+
"submit",
664+
"--wait",
665+
"--apple-id", appleEmail!!,
666+
"--password", appleAppSpecificPassword!!,
667+
"--team-id", appleTeamId,
668+
inputs.files.singleFile.absolutePath,
669+
)
670+
}
659671
}
660672

661673

@@ -687,31 +699,37 @@ tasks.register<Exec>("convertToPkg") {
687699
)
688700
}
689701

690-
tasks.register<Exec>("validatePkg") {
702+
tasks.register("validatePkg") {
691703
dependsOn("convertToPkg")
692704
inputs.file(tasks.named("convertToPkg").get().outputs.files.singleFile)
693-
commandLine(
694-
"/usr/bin/xcrun",
695-
"altool",
696-
"--validate-app",
697-
"-f", inputs.files.singleFile.absolutePath,
698-
"-t", "osx",
699-
"-u", appleEmail,
700-
"-p", appleAppSpecificPassword
701-
)
705+
706+
doLast {
707+
runCmd(
708+
"/usr/bin/xcrun",
709+
"altool",
710+
"--validate-app",
711+
"-f", inputs.files.singleFile.absolutePath,
712+
"-t", "osx",
713+
"-u", appleEmail!!,
714+
"-p", appleAppSpecificPassword!!
715+
)
716+
}
702717
}
703718

704719

705-
tasks.register<Exec>("uploadPkgToAppStore") {
720+
tasks.register("uploadPkgToAppStore") {
706721
dependsOn("validatePkg")
707722
inputs.file(tasks.named("convertToPkg").get().outputs.files.singleFile)
708-
commandLine(
709-
"/usr/bin/xcrun",
710-
"altool",
711-
"--upload-app",
712-
"-f", inputs.files.singleFile.absolutePath,
713-
"-t", "osx",
714-
"-u", appleEmail,
715-
"-p", appleAppSpecificPassword
716-
)
723+
724+
doLast {
725+
runCmd(
726+
"/usr/bin/xcrun",
727+
"altool",
728+
"--upload-app",
729+
"-f", inputs.files.singleFile.absolutePath,
730+
"-t", "osx",
731+
"-u", appleEmail!!,
732+
"-p", appleAppSpecificPassword!!
733+
)
734+
}
717735
}

0 commit comments

Comments
 (0)