From 434046fe9d12d20f6ba3b98abe99a43aa7036b9e Mon Sep 17 00:00:00 2001 From: Igor Mandrigin Date: Tue, 14 Aug 2018 18:24:48 +0200 Subject: [PATCH] Upload apk to Sauce Labs using fastlane. Signed-off-by: Igor Mandrigin --- ci/Jenkinsfile | 13 ++++------ ci/Jenkinsfile.nightly_fastlane | 27 +++++++++++---------- ci/Jenkinsfile.release | 27 +++++++++++---------- fastlane/Fastfile | 42 ++++++++++++++++++++++++++++++++- 4 files changed, 73 insertions(+), 36 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index bf91de320d..de87da796c 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -112,20 +112,15 @@ timeout(90) { stage('Upload apk for e2e tests') { if (env.CHANGE_ID != null) { - - withCredentials([ - string(credentialsId: 'SAUCE_ACCESS_KEY', variable: 'key'), - string(credentialsId: 'SAUCE_USERNAME', variable: 'username') - ]) { - def apk_name = env.CHANGE_ID + '.apk' - sh('curl -u ' + username+ ':' + key + ' -X POST -H "Content-Type: application/octet-stream" https://saucelabs.com/rest/v1/storage/' + username + '/' + apk_name + '?overwrite=true --data-binary @android/app/build/outputs/apk/release/app-release.apk') - } - + env.SAUCE_LABS_APK = 'im.status.ethereum-e2e-' + env.CHANGE_ID + '.apk' withCredentials([ + string(credentialsId: 'SAUCE_ACCESS_KEY', variable: 'SAUCE_ACCESS_KEY'), + string(credentialsId: 'SAUCE_USERNAME', variable: 'SAUCE_USERNAME'), string(credentialsId: 'diawi-token', variable: 'DIAWI_TOKEN'), string(credentialsId: 'GIT_HUB_TOKEN', variable: 'GITHUB_TOKEN'), string(credentialsId: 'SLACK_JENKINS_WEBHOOK', variable: 'SLACK_URL') ]) { + sh 'fastlane android saucelabs' sh 'fastlane android upload_diawi' } } diff --git a/ci/Jenkinsfile.nightly_fastlane b/ci/Jenkinsfile.nightly_fastlane index d5cf18f0d9..0079f270a3 100644 --- a/ci/Jenkinsfile.nightly_fastlane +++ b/ci/Jenkinsfile.nightly_fastlane @@ -151,18 +151,19 @@ timeout(90) { } stage('Upload apk for e2e tests') { - withCredentials([string(credentialsId: 'SAUCE_ACCESS_KEY', variable: 'key'), string(credentialsId: 'SAUCE_USERNAME', variable: 'username')]){ - apk_name = 'im.status.ethereum-e2e-' + shortCommit + '.apk' - sh('curl -u ' + username+ ':' + key + ' -X POST -H "Content-Type: application/octet-stream" https://saucelabs.com/rest/v1/storage/' + username + '/' + apk_name + '?overwrite=true --data-binary @android/app/build/outputs/apk/release/app-release.apk') - } - - withCredentials([ - string(credentialsId: 'diawi-token', variable: 'DIAWI_TOKEN'), - string(credentialsId: 'GIT_HUB_TOKEN', variable: 'GITHUB_TOKEN'), - string(credentialsId: 'SLACK_JENKINS_WEBHOOK', variable: 'SLACK_URL') - ]) { - sh 'fastlane android upload_diawi' - } + if (env.CHANGE_ID != null) { + env.SAUCE_LABS_APK = 'im.status.ethereum-e2e-' + env.CHANGE_ID + '.apk' + withCredentials([ + string(credentialsId: 'SAUCE_ACCESS_KEY', variable: 'SAUCE_ACCESS_KEY'), + string(credentialsId: 'SAUCE_USERNAME', variable: 'SAUCE_USERNAME'), + string(credentialsId: 'diawi-token', variable: 'DIAWI_TOKEN'), + string(credentialsId: 'GIT_HUB_TOKEN', variable: 'GITHUB_TOKEN'), + string(credentialsId: 'SLACK_JENKINS_WEBHOOK', variable: 'SLACK_URL') + ]) { + sh 'fastlane android saucelabs' + sh 'fastlane android upload_diawi' + } + } } stage('Slack Notification') { @@ -171,7 +172,7 @@ timeout(90) { } stage('Run extended e2e tests') { - build job: 'end-to-end-tests/status-app-nightly', parameters: [string(name: 'apk', value: '--apk=' + apk_name)], wait: false + build job: 'end-to-end-tests/status-app-nightly', parameters: [string(name: 'apk', value: '--apk=' + env.SAUCE_LABS_APK)], wait: false } } } diff --git a/ci/Jenkinsfile.release b/ci/Jenkinsfile.release index 4cf1a217c3..711a149454 100644 --- a/ci/Jenkinsfile.release +++ b/ci/Jenkinsfile.release @@ -133,22 +133,23 @@ timeout(90) { } stage('Upload apk for e2e tests') { - withCredentials([string(credentialsId: 'SAUCE_ACCESS_KEY', variable: 'key'), string(credentialsId: 'SAUCE_USERNAME', variable: 'username')]){ - apk_name = 'release-e2e-' + shortCommit + '.apk' - sh('curl -u ' + username+ ':' + key + ' -X POST -H "Content-Type: application/octet-stream" https://saucelabs.com/rest/v1/storage/' + username + '/' + apk_name + '?overwrite=true --data-binary @android/app/build/outputs/apk/release/app-release.apk') - } - - withCredentials([ - string(credentialsId: 'diawi-token', variable: 'DIAWI_TOKEN'), - string(credentialsId: 'GIT_HUB_TOKEN', variable: 'GITHUB_TOKEN'), - string(credentialsId: 'SLACK_JENKINS_WEBHOOK', variable: 'SLACK_URL') - ]) { - sh 'fastlane android upload_diawi' - } + if (env.CHANGE_ID != null) { + env.SAUCE_LABS_APK = 'im.status.ethereum-e2e-' + env.CHANGE_ID + '.apk' + withCredentials([ + string(credentialsId: 'SAUCE_ACCESS_KEY', variable: 'SAUCE_ACCESS_KEY'), + string(credentialsId: 'SAUCE_USERNAME', variable: 'SAUCE_USERNAME'), + string(credentialsId: 'diawi-token', variable: 'DIAWI_TOKEN'), + string(credentialsId: 'GIT_HUB_TOKEN', variable: 'GITHUB_TOKEN'), + string(credentialsId: 'SLACK_JENKINS_WEBHOOK', variable: 'SLACK_URL') + ]) { + sh 'fastlane android saucelabs' + sh 'fastlane android upload_diawi' + } + } } stage('Run extended e2e tests') { - build job: 'end-to-end-tests/status-app-nightly', parameters: [string(name: 'apk', value: '--apk=' + apk_name)], wait: false + build job: 'end-to-end-tests/status-app-nightly', parameters: [string(name: 'apk', value: '--apk=' + env.SAUCE_LABS_APK)], wait: false } } diff --git a/fastlane/Fastfile b/fastlane/Fastfile index eb0ea067a9..3d370b3fc3 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -22,6 +22,33 @@ def unlock_keychain_if_needed end +# uploads `file` to sauce labs (overwrites if there is anoter file from the +# same commit) +def upload_to_saucelabs(file) + username = ENV["SAUCE_USERNAME"] + key = ENV["SAUCE_ACCESS_KEY"] + unique_name = ENV["SAUCE_LABS_APK"] + + url = "https://saucelabs.com/rest/v1/storage/" + username + '/' + unique_name + "?overwrite=true" + + upload_result = sh( + "curl", + "-u", username + ':' + key, + "-X", "POST", + "-H", "Content-Type: application/octet-stream", + url, + # this command has `status-react/fastlane` as cwd + # so we need to jump outside this folder to get a file + "--data-binary", "@" + "../" + file + ) + + # fail the lane if upload fails + UI.user_error!( + "failed to upload file to saucelabs: " + upload_result + ) unless upload_result.include? "filename" +end + + # builds an ios app with ad-hoc configuration and put it # to "status-adhoc" output folder def build_ios_adhoc @@ -208,7 +235,7 @@ platform :android do ) end - desc "`fastlane android upload-diawi` - upload .ipa to diawi" + desc "`fastlane android upload_diawi` - upload .apk to diawi" desc "also notifies in a GitHub comments and in Slack #jenkins channel" desc "expects to have an .apk prepared: `android/app/build/outputs/apk/release/app-release.apk`" desc "expects to have a diawi token as DIAWI_TOKEN env variable" @@ -220,4 +247,17 @@ platform :android do "android/app/build/outputs/apk/release/app-release.apk" ) end + + desc "`fastlane android saucelabs` - upload .apk to sauce labs" + desc "also notifies in a GitHub comments and in Slack #jenkins channel" + desc "expects to have an .apk prepared: `android/app/build/outputs/apk/release/app-release.apk`" + desc "expects to have a saucelabs access key as SAUCE_ACCESS_KEY env variable" + desc "expects to have a saucelabs username token as SAUCE_USERNAME env variable" + desc "expects to have a saucelabs destination name as SAUCE_LABS_APK env variable" + desc "will fails if file isn't there" + lane :saucelabs do + upload_to_saucelabs( + "android/app/build/outputs/apk/release/app-release.apk" + ) + end end