From 581f612aa90280b6ccb03cd1050719031079a740 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Fri, 24 Nov 2023 15:56:40 +0100 Subject: [PATCH 01/17] chore: cleanup code curl to release --- AR-builder.groovy | 31 +++++++++++++++++++++++++++++++ Jenkinsfile | 15 +++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index 5530d9d4566..434f810dcf7 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -15,6 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ +import org.jenkinsci.plugins.pipeline.utility.steps.fs.FileWrapper String shellQuote(String s) { // Quote a string so it's suitable to pass to the shell @@ -42,6 +43,28 @@ def postGithubComment(String changeId, String body) { } +def postApkToGithubRelease(List apks) { + if (apks.isEmpty()) { + return + } + + echo 'Attaching APK to Github Release for tag: ' + env.SOURCE_BRANCH + def fileApk = apks[0] + def filename = fileApk.getName() + + // headers request + def acceptHeader = shellQuote("Accept: application/vnd.github.v3+json") + def contentTypeHeader = shellQuote("Content-Type: application/octet-stream") + def authHeader = shellQuote("Authorization: token ${env.GITHUB_API_TOKEN}") + + // api request + def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android/releases/latest") + def uploadUrl = sh("curl -s ${apiUrl} | jq -r '.upload_url' | cut -d'{' -f1", returnStdout: true).trim() + def sanitizedUploadUrl = shellQuote(uploadUrl + "?name=\$(basename ${filename})") + + sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST --data-binary @${fileApk.getPath()} ${sanitizedUploadUrl}" +} + def defineTrackName(String branchName) { def overwrite = env.CUSTOM_TRACK @@ -527,6 +550,14 @@ pipeline { postGithubComment(params.GITHUB_CHANGE_ID, payload) } + + // if (env.SOURCE_BRANCH ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./) { + if (env.SOURCE_BRANCH ==~ /y\/.*/) { + def apks = findFiles(glob: "app/build/outputs/apk/${params.FLAVOR.toLowerCase()}/${params.BUILD_TYPE.toLowerCase()}/com.wire.android-*.apk") + if (apks.size() > 0) { + postApkToGithubRelease(apks) + } + } } sh './gradlew jacocoReport' diff --git a/Jenkinsfile b/Jenkinsfile index eddfcd9753e..45debb2a48c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,12 +6,14 @@ List defineFlavor() { } def branchName = env.BRANCH_NAME + // def isTagAndValid = env.TAG_NAME ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./ || branchName ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./ + def isTagAndValid = env.BRANCH_NAME ==~ /y\/.*/ if (branchName == "main") { return ['Beta'] } else if (branchName == "develop") { return ['Staging', 'Dev'] - } else if (branchName == "prod") { + } else if (branchName == "prod" || isTagAndValid) { return ['Prod'] } else if (branchName == "internal") { return ['Internal'] @@ -73,6 +75,14 @@ String handleChangeBranch(String changeBranch) { return env.BRANCH_NAME } +/** +* Force in case of a tag to not upload to PlayStore, otherwise it will delegate to the stage resolution. +*/ +String defineUploadToPlayStoreEnabled() { + return env.BRANCH_NAME !=~ /y\/.*/ +// return env.BRANCH_NAME !=~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./ +} + pipeline { agent { node { @@ -99,6 +109,7 @@ pipeline { String buildType = defineBuildType(flavor) String stageName = "Build $flavor$buildType" String definedChangeBranch = handleChangeBranch(env.CHANGE_BRANCH) + Boolean uploadToPlayStoreEnabled = defineUploadToPlayStoreEnabled() dynamicStages[stageName] = { node { stage(stageName) { @@ -110,7 +121,7 @@ pipeline { string(name: 'BUILD_TYPE', value: buildType), string(name: 'FLAVOR', value: flavor), booleanParam(name: 'UPLOAD_TO_S3', value: true), - booleanParam(name: 'UPLOAD_TO_PLAYSTORE_ENABLED', value: true), + booleanParam(name: 'UPLOAD_TO_PLAYSTORE_ENABLED', value: uploadToPlayStoreEnabled), booleanParam(name: 'RUN_UNIT_TEST', value: true), booleanParam(name: 'RUN_ACCEPTANCE_TESTS', value: true), booleanParam(name: 'RUN_STATIC_CODE_ANALYSIS', value: true), From d2f87ae70d1e7a0a97494fa8b4b2b8d817de8111 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Fri, 24 Nov 2023 17:08:30 +0100 Subject: [PATCH 02/17] chore: cleanup code curl to release --- AR-builder.groovy | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index 434f810dcf7..cf994b35ad9 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -555,7 +555,22 @@ pipeline { if (env.SOURCE_BRANCH ==~ /y\/.*/) { def apks = findFiles(glob: "app/build/outputs/apk/${params.FLAVOR.toLowerCase()}/${params.BUILD_TYPE.toLowerCase()}/com.wire.android-*.apk") if (apks.size() > 0) { - postApkToGithubRelease(apks) + // postApkToGithubRelease(apks) + echo 'Attaching APK to Github Release for tag: ' + env.SOURCE_BRANCH + def fileApk = apks[0] + def filename = fileApk.getName() + + // headers request + def acceptHeader = shellQuote("Accept: application/vnd.github.v3+json") + def contentTypeHeader = shellQuote("Content-Type: application/octet-stream") + def authHeader = shellQuote("Authorization: token ${env.GITHUB_API_TOKEN}") + + // api request + def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android/releases/latest") + def uploadUrl = sh("curl -s ${apiUrl} | jq -r '.upload_url' | cut -d'{' -f1", returnStdout: true).trim() + def sanitizedUploadUrl = shellQuote(uploadUrl + "?name=\$(basename ${filename})") + + sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST --data-binary @${fileApk.getPath()} ${sanitizedUploadUrl}" } } } From cd7624cf2c1bb01af9cdbeb6b09099d2fb01180a Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Fri, 24 Nov 2023 17:28:24 +0100 Subject: [PATCH 03/17] chore: cleanup code curl to release --- AR-builder.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index cf994b35ad9..f38ae6546dc 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -567,7 +567,7 @@ pipeline { // api request def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android/releases/latest") - def uploadUrl = sh("curl -s ${apiUrl} | jq -r '.upload_url' | cut -d'{' -f1", returnStdout: true).trim() + def uploadUrl = sh "curl -s ${apiUrl} | jq -r '.upload_url' | cut -d'{' -f1" def sanitizedUploadUrl = shellQuote(uploadUrl + "?name=\$(basename ${filename})") sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST --data-binary @${fileApk.getPath()} ${sanitizedUploadUrl}" From 8440d6649ddd7e777066e033ff7556d9256b317c Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Fri, 24 Nov 2023 20:47:55 +0100 Subject: [PATCH 04/17] chore: parser --- AR-builder.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index f38ae6546dc..39a97a7e061 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -567,7 +567,7 @@ pipeline { // api request def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android/releases/latest") - def uploadUrl = sh "curl -s ${apiUrl} | jq -r '.upload_url' | cut -d'{' -f1" + def uploadUrl = sh "curl -s ${apiUrl} | grep -m 1 \"id.:\" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | cut -d'=' -f2" def sanitizedUploadUrl = shellQuote(uploadUrl + "?name=\$(basename ${filename})") sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST --data-binary @${fileApk.getPath()} ${sanitizedUploadUrl}" From 20339f01b1586ab2a96fcd50b3f3613b352f87b2 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Fri, 24 Nov 2023 21:19:02 +0100 Subject: [PATCH 05/17] chore: parser --- AR-builder.groovy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index 39a97a7e061..a4b8108be69 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -560,6 +560,7 @@ pipeline { def fileApk = apks[0] def filename = fileApk.getName() + echo 'Uploading apk to github release: ' + filename // headers request def acceptHeader = shellQuote("Accept: application/vnd.github.v3+json") def contentTypeHeader = shellQuote("Content-Type: application/octet-stream") @@ -567,8 +568,8 @@ pipeline { // api request def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android/releases/latest") - def uploadUrl = sh "curl -s ${apiUrl} | grep -m 1 \"id.:\" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | cut -d'=' -f2" - def sanitizedUploadUrl = shellQuote(uploadUrl + "?name=\$(basename ${filename})") + def releaseId = sh "curl -s ${apiUrl} | grep -m 1 \"id.:\" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | cut -d'=' -f2" + def sanitizedUploadUrl = shellQuote("https://uploads.github.com/repos/wireapp/wire-android/releases/${releaseId}/assets?name=\$(basename ${filename})") sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST --data-binary @${fileApk.getPath()} ${sanitizedUploadUrl}" } From 29aeb59f63cb03db4714a33f7ed1684f2f6275ce Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Fri, 24 Nov 2023 21:41:44 +0100 Subject: [PATCH 06/17] chore: parser --- AR-builder.groovy | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AR-builder.groovy b/AR-builder.groovy index a4b8108be69..5404dc45076 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -571,6 +571,9 @@ pipeline { def releaseId = sh "curl -s ${apiUrl} | grep -m 1 \"id.:\" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | cut -d'=' -f2" def sanitizedUploadUrl = shellQuote("https://uploads.github.com/repos/wireapp/wire-android/releases/${releaseId}/assets?name=\$(basename ${filename})") + echo 'Uploading apk to github release: ' + sanitizedUploadUrl + + echo 'Preparing send' sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST --data-binary @${fileApk.getPath()} ${sanitizedUploadUrl}" } } From 962b6910222daafbd23dfd0b5355678b76791186 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Fri, 24 Nov 2023 23:34:26 +0100 Subject: [PATCH 07/17] chore: parser and curl fixedx --- AR-builder.groovy | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index 5404dc45076..47edb0e7ff4 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -560,7 +560,6 @@ pipeline { def fileApk = apks[0] def filename = fileApk.getName() - echo 'Uploading apk to github release: ' + filename // headers request def acceptHeader = shellQuote("Accept: application/vnd.github.v3+json") def contentTypeHeader = shellQuote("Content-Type: application/octet-stream") @@ -568,13 +567,11 @@ pipeline { // api request def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android/releases/latest") - def releaseId = sh "curl -s ${apiUrl} | grep -m 1 \"id.:\" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | cut -d'=' -f2" - def sanitizedUploadUrl = shellQuote("https://uploads.github.com/repos/wireapp/wire-android/releases/${releaseId}/assets?name=\$(basename ${filename})") - + def releaseId = sh(script: "curl -s ${apiUrl} | grep -m 1 \"id.:\" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | cut -d'=' -f2", returnStdout: true).trim() + def sanitizedUploadUrl = shellQuote("https://uploads.github.com/repos/wireapp/wire-android/releases/${releaseId}/assets?name=\$(basename '${filename}')") echo 'Uploading apk to github release: ' + sanitizedUploadUrl - echo 'Preparing send' - sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST --data-binary @${fileApk.getPath()} ${sanitizedUploadUrl}" + sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST -T ${fileApk.getPath()} ${sanitizedUploadUrl}" } } } From b21cb6a45f8d34627dd9d2399bf9c75fe9c85f37 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Fri, 24 Nov 2023 23:54:04 +0100 Subject: [PATCH 08/17] chore: parser and curl fixedx --- AR-builder.groovy | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index 47edb0e7ff4..373933ee0ec 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -43,28 +43,6 @@ def postGithubComment(String changeId, String body) { } -def postApkToGithubRelease(List apks) { - if (apks.isEmpty()) { - return - } - - echo 'Attaching APK to Github Release for tag: ' + env.SOURCE_BRANCH - def fileApk = apks[0] - def filename = fileApk.getName() - - // headers request - def acceptHeader = shellQuote("Accept: application/vnd.github.v3+json") - def contentTypeHeader = shellQuote("Content-Type: application/octet-stream") - def authHeader = shellQuote("Authorization: token ${env.GITHUB_API_TOKEN}") - - // api request - def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android/releases/latest") - def uploadUrl = sh("curl -s ${apiUrl} | jq -r '.upload_url' | cut -d'{' -f1", returnStdout: true).trim() - def sanitizedUploadUrl = shellQuote(uploadUrl + "?name=\$(basename ${filename})") - - sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST --data-binary @${fileApk.getPath()} ${sanitizedUploadUrl}" -} - def defineTrackName(String branchName) { def overwrite = env.CUSTOM_TRACK @@ -555,7 +533,6 @@ pipeline { if (env.SOURCE_BRANCH ==~ /y\/.*/) { def apks = findFiles(glob: "app/build/outputs/apk/${params.FLAVOR.toLowerCase()}/${params.BUILD_TYPE.toLowerCase()}/com.wire.android-*.apk") if (apks.size() > 0) { - // postApkToGithubRelease(apks) echo 'Attaching APK to Github Release for tag: ' + env.SOURCE_BRANCH def fileApk = apks[0] def filename = fileApk.getName() @@ -568,8 +545,8 @@ pipeline { // api request def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android/releases/latest") def releaseId = sh(script: "curl -s ${apiUrl} | grep -m 1 \"id.:\" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | cut -d'=' -f2", returnStdout: true).trim() - def sanitizedUploadUrl = shellQuote("https://uploads.github.com/repos/wireapp/wire-android/releases/${releaseId}/assets?name=\$(basename '${filename}')") - echo 'Uploading apk to github release: ' + sanitizedUploadUrl + def sanitizedUploadUrl = "https://uploads.github.com/repos/wireapp/wire-android/releases/${releaseId}/assets?name=\$(basename '${filename}')" + echo 'Uploading APK to Github Release destination: ' + sanitizedUploadUrl sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST -T ${fileApk.getPath()} ${sanitizedUploadUrl}" } From 4aaee0adae9f017330f2db83b1b54f85b0bdd4eb Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Sat, 25 Nov 2023 00:17:40 +0100 Subject: [PATCH 09/17] chore: parser and curl fixed --- AR-builder.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index 373933ee0ec..ff3a60afd6d 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -548,7 +548,7 @@ pipeline { def sanitizedUploadUrl = "https://uploads.github.com/repos/wireapp/wire-android/releases/${releaseId}/assets?name=\$(basename '${filename}')" echo 'Uploading APK to Github Release destination: ' + sanitizedUploadUrl - sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST -T ${fileApk.getPath()} ${sanitizedUploadUrl}" + sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST -T ${fileApk.getPath()} \"${sanitizedUploadUrl}\"" } } } From dad35924bceead2f5411519413fdeb56cef372bb Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Sat, 25 Nov 2023 00:35:46 +0100 Subject: [PATCH 10/17] chore: parser and curl fixed --- AR-builder.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index ff3a60afd6d..3a495b818ef 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -548,7 +548,7 @@ pipeline { def sanitizedUploadUrl = "https://uploads.github.com/repos/wireapp/wire-android/releases/${releaseId}/assets?name=\$(basename '${filename}')" echo 'Uploading APK to Github Release destination: ' + sanitizedUploadUrl - sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST -T ${fileApk.getPath()} \"${sanitizedUploadUrl}\"" + sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST -T ${fileApk.getPath()} '${sanitizedUploadUrl}'" } } } From a5dc0d8fd18542b6aff6c3196be05b5641c6ecb5 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Sun, 26 Nov 2023 11:40:06 +0100 Subject: [PATCH 11/17] chore: parser and curl fixed --- AR-builder.groovy | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index 3a495b818ef..d0cceaef9e4 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -215,9 +215,9 @@ pipeline { last_started = env.STAGE_NAME } - withGradle() { - sh './gradlew compileApp' - } +// withGradle() { +// sh './gradlew compileApp' +// } } } @@ -548,12 +548,11 @@ pipeline { def sanitizedUploadUrl = "https://uploads.github.com/repos/wireapp/wire-android/releases/${releaseId}/assets?name=\$(basename '${filename}')" echo 'Uploading APK to Github Release destination: ' + sanitizedUploadUrl - sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST -T ${fileApk.getPath()} '${sanitizedUploadUrl}'" + sh "curl -v -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST -T '${fileApk.getPath()}' '${sanitizedUploadUrl}'" } } } - sh './gradlew jacocoReport' wireSend(secret: env.WIRE_BOT_SECRET, message: "**[#${BUILD_NUMBER} Link](${BUILD_URL})** [${SOURCE_BRANCH}] - ✅ SUCCESS 🎉" + "\nLast 5 commits:\n```text\n$lastCommits\n```") } From 43d8f7d812c4e00cb57313a00ae423563dc0134c Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Sun, 26 Nov 2023 12:15:01 +0100 Subject: [PATCH 12/17] chore: sanitized name and more logs --- AR-builder.groovy | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index d0cceaef9e4..0dbc3db5ead 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -22,6 +22,11 @@ String shellQuote(String s) { return "'" + s.replaceAll("'", "'\"'\"'") + "'" } +String shellParentheses(String s) { + // Parenthesize a string so it's suitable to pass to the shell + return s.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") +} + def postGithubComment(String changeId, String body) { def authHeader = shellQuote("Authorization: token ${env.GITHUB_API_TOKEN}") def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android-reloaded/issues/${changeId}/comments") @@ -546,9 +551,11 @@ pipeline { def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android/releases/latest") def releaseId = sh(script: "curl -s ${apiUrl} | grep -m 1 \"id.:\" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | cut -d'=' -f2", returnStdout: true).trim() def sanitizedUploadUrl = "https://uploads.github.com/repos/wireapp/wire-android/releases/${releaseId}/assets?name=\$(basename '${filename}')" - echo 'Uploading APK to Github Release destination: ' + sanitizedUploadUrl - sh "curl -v -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST -T '${fileApk.getPath()}' '${sanitizedUploadUrl}'" + def sanitizedPath = shellParentheses(fileApk.getPath()) + echo 'Uploading APK: ' + sanitizedPath + ' to Github Release destination: ' + sanitizedUploadUrl + + sh "curl -v -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST -T ${sanitizedPath} ${sanitizedUploadUrl}" } } } From 815c3789f37a698394d951f55664c1abc700e917 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Sun, 26 Nov 2023 12:49:44 +0100 Subject: [PATCH 13/17] chore: cleanup --- AR-builder.groovy | 48 +++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index 0dbc3db5ead..6a1b83a4d74 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -15,7 +15,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ -import org.jenkinsci.plugins.pipeline.utility.steps.fs.FileWrapper String shellQuote(String s) { // Quote a string so it's suitable to pass to the shell @@ -48,6 +47,31 @@ def postGithubComment(String changeId, String body) { } +def postGithubApkToRelease(String flavor, String buildType) { + def apks = findFiles(glob: "app/build/outputs/apk/${flavor.toLowerCase()}/${buildType.toLowerCase()}/com.wire.android-*.apk") + if (apks.size() > 0) { + echo 'Attaching APK to Github Release for tag: ' + env.SOURCE_BRANCH + def fileApk = apks[0] + def filename = shellParentheses(fileApk.getName()) + + // building headers request + def acceptHeader = shellQuote("Accept: application/vnd.github.v3+json") + def contentTypeHeader = shellQuote("Content-Type: application/octet-stream") + def authHeader = shellQuote("Authorization: token ${env.GITHUB_API_TOKEN}") + + // building gh api request + def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android/releases/latest") + def releaseId = sh(script: "curl -s ${apiUrl} | grep -m 1 \"id.:\" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | cut -d'=' -f2", returnStdout: true).trim() + def sanitizedUploadUrl = "https://uploads.github.com/repos/wireapp/wire-android/releases/${releaseId}/assets?name=\$(basename '${filename}')" + def sanitizedApkPath = shellParentheses(fileApk.getPath()) + echo 'Starting! Upload of APK: ' + sanitizedApkPath + ' to Github Release destination: ' + sanitizedUploadUrl + + sh "curl -s -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST -T ${sanitizedApkPath} ${sanitizedUploadUrl}" + } else { + echo 'No APK found to attach to Github Release for tag: ' + env.SOURCE_BRANCH + } +} + def defineTrackName(String branchName) { def overwrite = env.CUSTOM_TRACK @@ -536,27 +560,7 @@ pipeline { // if (env.SOURCE_BRANCH ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./) { if (env.SOURCE_BRANCH ==~ /y\/.*/) { - def apks = findFiles(glob: "app/build/outputs/apk/${params.FLAVOR.toLowerCase()}/${params.BUILD_TYPE.toLowerCase()}/com.wire.android-*.apk") - if (apks.size() > 0) { - echo 'Attaching APK to Github Release for tag: ' + env.SOURCE_BRANCH - def fileApk = apks[0] - def filename = fileApk.getName() - - // headers request - def acceptHeader = shellQuote("Accept: application/vnd.github.v3+json") - def contentTypeHeader = shellQuote("Content-Type: application/octet-stream") - def authHeader = shellQuote("Authorization: token ${env.GITHUB_API_TOKEN}") - - // api request - def apiUrl = shellQuote("https://api.github.com/repos/wireapp/wire-android/releases/latest") - def releaseId = sh(script: "curl -s ${apiUrl} | grep -m 1 \"id.:\" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | cut -d'=' -f2", returnStdout: true).trim() - def sanitizedUploadUrl = "https://uploads.github.com/repos/wireapp/wire-android/releases/${releaseId}/assets?name=\$(basename '${filename}')" - - def sanitizedPath = shellParentheses(fileApk.getPath()) - echo 'Uploading APK: ' + sanitizedPath + ' to Github Release destination: ' + sanitizedUploadUrl - - sh "curl -v -H ${authHeader} -H ${acceptHeader} -H ${contentTypeHeader} -X POST -T ${sanitizedPath} ${sanitizedUploadUrl}" - } + postGithubApkToRelease(params.FLAVOR, params.BUILD_TYPE) } } From c68d163adf5afcc1dc66697a1e5da75194645e2d Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Sun, 26 Nov 2023 13:29:33 +0100 Subject: [PATCH 14/17] chore: cleanup, and test --- AR-builder.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index 6a1b83a4d74..f5493af2c76 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -52,7 +52,9 @@ def postGithubApkToRelease(String flavor, String buildType) { if (apks.size() > 0) { echo 'Attaching APK to Github Release for tag: ' + env.SOURCE_BRANCH def fileApk = apks[0] - def filename = shellParentheses(fileApk.getName()) + // note: apk name value rename to comply with github releases assets names requirements + // https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#upload-a-release-asset + def filename = fileApk.getName().replaceAll("\\(", "_").replaceAll("\\)", "_") // building headers request def acceptHeader = shellQuote("Accept: application/vnd.github.v3+json") From 97bf17bdcb596db5b23e94d02a1874ff4def5922 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Sun, 26 Nov 2023 13:50:06 +0100 Subject: [PATCH 15/17] chore: cleanup, revert forcing to run in code --- AR-builder.groovy | 3 +-- Jenkinsfile | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index f5493af2c76..2965eb65ec1 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -560,8 +560,7 @@ pipeline { postGithubComment(params.GITHUB_CHANGE_ID, payload) } - // if (env.SOURCE_BRANCH ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./) { - if (env.SOURCE_BRANCH ==~ /y\/.*/) { + if (env.SOURCE_BRANCH ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./) { postGithubApkToRelease(params.FLAVOR, params.BUILD_TYPE) } } diff --git a/Jenkinsfile b/Jenkinsfile index 45debb2a48c..2bb19612242 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,8 +6,7 @@ List defineFlavor() { } def branchName = env.BRANCH_NAME - // def isTagAndValid = env.TAG_NAME ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./ || branchName ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./ - def isTagAndValid = env.BRANCH_NAME ==~ /y\/.*/ + def isTagAndValid = env.TAG_NAME ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./ || branchName ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./ if (branchName == "main") { return ['Beta'] @@ -79,8 +78,7 @@ String handleChangeBranch(String changeBranch) { * Force in case of a tag to not upload to PlayStore, otherwise it will delegate to the stage resolution. */ String defineUploadToPlayStoreEnabled() { - return env.BRANCH_NAME !=~ /y\/.*/ -// return env.BRANCH_NAME !=~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./ + return env.BRANCH_NAME !=~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./ } pipeline { From d28add7444a2305d73102337ed46ad4bec55fb8f Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Sun, 26 Nov 2023 14:02:05 +0100 Subject: [PATCH 16/17] chore: cleanup, revert forcing to run in code --- AR-builder.groovy | 2 +- Jenkinsfile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index 2965eb65ec1..0f7c546ee8b 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -560,7 +560,7 @@ pipeline { postGithubComment(params.GITHUB_CHANGE_ID, payload) } - if (env.SOURCE_BRANCH ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./) { + if (env.SOURCE_BRANCH ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+/) { postGithubApkToRelease(params.FLAVOR, params.BUILD_TYPE) } } diff --git a/Jenkinsfile b/Jenkinsfile index 2bb19612242..a5189b26691 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,7 @@ List defineFlavor() { } def branchName = env.BRANCH_NAME - def isTagAndValid = env.TAG_NAME ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./ || branchName ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./ + def isTagAndValid = env.TAG_NAME ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+/ || branchName ==~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+/ if (branchName == "main") { return ['Beta'] @@ -78,7 +78,7 @@ String handleChangeBranch(String changeBranch) { * Force in case of a tag to not upload to PlayStore, otherwise it will delegate to the stage resolution. */ String defineUploadToPlayStoreEnabled() { - return env.BRANCH_NAME !=~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+./ + return env.BRANCH_NAME !=~ /v[0-9]+.[0-9]+.[0-9A-Za-z-+]+/ } pipeline { From df36a159fd961f37c48485de06881c99acd4daaf Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Sun, 26 Nov 2023 14:06:44 +0100 Subject: [PATCH 17/17] chore: cleanup --- AR-builder.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index 0f7c546ee8b..0ef928e5673 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -246,9 +246,9 @@ pipeline { last_started = env.STAGE_NAME } -// withGradle() { -// sh './gradlew compileApp' -// } + withGradle() { + sh './gradlew compileApp' + } } }