Skip to content

Commit

Permalink
Upload apk to Sauce Labs using fastlane.
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
  • Loading branch information
mandrigin committed Aug 14, 2018
1 parent c99fd73 commit 434046f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 36 deletions.
13 changes: 4 additions & 9 deletions ci/Jenkinsfile
Expand Up @@ -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'
}
}
Expand Down
27 changes: 14 additions & 13 deletions ci/Jenkinsfile.nightly_fastlane
Expand Up @@ -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') {
Expand All @@ -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
}
}
}
27 changes: 14 additions & 13 deletions ci/Jenkinsfile.release
Expand Up @@ -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
}

}
Expand Down
42 changes: 41 additions & 1 deletion fastlane/Fastfile
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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

0 comments on commit 434046f

Please sign in to comment.