Upload apk to Sauce Labs using fastlane.

Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
Igor Mandrigin 2018-08-14 18:24:48 +02:00
parent c99fd733e6
commit 434046fe9d
No known key found for this signature in database
GPG Key ID: 4A0EDDE26E66BC8B
4 changed files with 73 additions and 36 deletions

13
ci/Jenkinsfile vendored
View File

@ -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'
}
}

View File

@ -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
}
}
}

View File

@ -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
}
}

View File

@ -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