Skip to content

Commit 3434fe7

Browse files
florentmaitrepaulinea
authored andcommitted
Fix parsing of Netlify deploy output to retrieve deploy preview URL
1 parent 4708ce7 commit 3434fe7

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

buildSrc/src/main/kotlin/netlify.gradle.kts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,34 @@ tasks.register<DefaultTask>("publishDocumentationToNetlify") {
4343
val outputLines = output.orEmpty()
4444
.replace("\\x1B\\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]".toRegex(), "") // Removes ANSI colors from output
4545
.split("\n")
46-
// Output displays "Website draft URL" for draft deployments and "Website URL" for prod deployments
47-
val netlifyDeployPreviewUrl = outputLines.firstNotNullOfOrNull { "^Website (?:draft |)URL:\\s+(.*)$".toRegex().find(it) }
48-
?.groupValues
49-
?.getOrNull(1)
46+
47+
// Output displays "Deployed draft to" for draft deployments and "Unique deploy URL" for prod deployments:
48+
//
49+
// ╭───────────────────────── ⬥ Draft deploy is live ⬥ ──────────────────────────╮
50+
// │ │
51+
// │ Deployed draft to │
52+
// │ https://687672e116cf5a2cbd949f0a--ouds-android.netlify.app │
53+
// │ │
54+
// ╰───────────────────────────────────────────────────────────────────────────────╯
55+
//
56+
// ╭──────────────── ⬥ Production deploy is live ⬥ ─────────────────╮
57+
// │ │
58+
// │ Deployed to production URL: https://ouds-android.netlify.app │
59+
// │ │
60+
// │ Unique deploy URL: │
61+
// │ https://687673f72c25433090a8bc6e--ouds-android.netlify.app │
62+
// │ │
63+
// ╰──────────────────────────────────────────────────────────────────╯
64+
val netlifyDeployPreviewUrl = outputLines.indexOfFirst { it.contains("Deployed draft to") || it.contains("Unique deploy URL") }
65+
.takeIf { it != -1 }
66+
?.plus(1) // Deploy preview URL is displayed on the next line
67+
?.let { index ->
68+
"(https:\\/\\/.*--ouds-android\\.netlify\\.app)".toRegex()
69+
.find(outputLines[index])
70+
?.groupValues
71+
?.getOrNull(1)
72+
}
73+
5074
val netlifyDeployLogUrl = outputLines.firstNotNullOfOrNull { "^Build logs:\\s+(.*)$".toRegex().find(it) }
5175
?.groupValues
5276
?.getOrNull(1)

0 commit comments

Comments
 (0)