refactor nix_sh to give it optional Map arguments

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-05-10 17:33:54 +02:00
parent c59f372ef3
commit 0e8e5a51ba
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
17 changed files with 212 additions and 142 deletions

View File

@ -22,13 +22,13 @@ pipeline {
}
environment {
LANG = "en_US.UTF-8"
LC_ALL = "en_US.UTF-8"
LANGUAGE = "en_US.UTF-8"
TARGET_OS = 'android'
LANG = 'en_US.UTF-8'
LANGUAGE = 'en_US.UTF-8'
LC_ALL = 'en_US.UTF-8'
NIX_CONF_DIR = "${env.WORKSPACE}/nix"
FASTLANE_DISABLE_COLORS = 1
REALM_DISABLE_ANALYTICS = 1
CI_ENVIRONMENT = 'jenkins'
/* since we are mounting it we need to specify location */
STATUS_RELEASE_STORE_FILE = '/home/jenkins/status-im.keystore'
/* We use EXECUTOR_NUMBER to avoid multiple instances clashing */
@ -54,17 +54,17 @@ pipeline {
}
stage('Lint') {
steps {
script { cmn.utils.nix_sh('lein cljfmt check') }
script { cmn.nix.shell('lein cljfmt check') }
}
}
stage('Tests') {
steps {
script { cmn.utils.nix_sh('lein test-cljs') }
script { cmn.nix.shell('lein test-cljs') }
}
}
stage('Build') {
steps {
script { cmn.utils.nix_sh('lein prod-build-android') }
script { cmn.nix.shell('lein prod-build-android') }
}
}
stage('Bundle') {

View File

@ -6,7 +6,6 @@ pipeline {
LANGUAGE = "en_US.UTF-8"
LC_ALL = "en_US.UTF-8"
FASTLANE_DISABLE_COLORS = 1
REALM_DISABLE_ANALYTICS = 1
}
options {

View File

@ -22,15 +22,18 @@ pipeline {
}
environment {
LANG = "en_US.UTF-8"
LC_ALL = "en_US.UTF-8"
LANGUAGE = "en_US.UTF-8"
TARGET_OS = 'ios'
CI_ENVIRONMENT = 'jenkins'
LANG = 'en_US.UTF-8'
LANGUAGE = 'en_US.UTF-8'
LC_ALL = 'en_US.UTF-8'
NIX_CONF_DIR = "${env.WORKSPACE}/nix"
FASTLANE_DISABLE_COLORS=1
REALM_DISABLE_ANALYTICS=1
FASTLANE_DISABLE_COLORS = 1
REALM_DISABLE_ANALYTICS = 1
BUNDLE_PATH = "${HOME}/.bundle"
/* We use EXECUTOR_NUMBER to avoid multiple instances clashing */
LEIN_HOME = "/var/tmp/lein-${EXECUTOR_NUMBER}"
YARN_CACHE_FOLDER = "/var/tmp/yarn-${EXECUTOR_NUMBER}"
GRADLE_USER_HOME = "/var/tmp/gradle-${EXECUTOR_NUMBER}"
}
stages {
@ -50,17 +53,17 @@ pipeline {
}
stage('Lint') {
steps {
script { cmn.utils.nix_sh('lein cljfmt check') }
script { cmn.nix.shell('lein cljfmt check') }
}
}
stage('Tests') {
steps {
script { cmn.utils.nix_sh('lein test-cljs') }
script { cmn.nix.shell('lein test-cljs') }
}
}
stage('Build') {
steps {
script { cmn.utils.nix_sh('lein prod-build-ios') }
script { cmn.nix.shell('lein prod-build-ios') }
}
}
stage('Bundle') {

View File

@ -26,15 +26,16 @@ pipeline {
* https://issues.jenkins-ci.org/browse/JENKINS-49076
**/
environment {
LANG = "en_US.UTF-8"
LC_ALL = "en_US.UTF-8"
LANGUAGE = "en_US.UTF-8"
TARGET_OS = 'linux'
LANG = 'en_US.UTF-8'
LANGUAGE = 'en_US.UTF-8'
LC_ALL = 'en_US.UTF-8'
NPM_CONFIG_CACHE = '/var/tmp/npm'
CI_ENVIRONMENT = 'jenkins'
LEIN_HOME = '/var/tmp/lein'
NIX_CONF_DIR = "${env.WORKSPACE}/nix"
VERBOSE_LEVEL = '3'
/* We use EXECUTOR_NUMBER to avoid multiple instances clashing */
LEIN_HOME = "/var/tmp/lein-${EXECUTOR_NUMBER}"
YARN_CACHE_FOLDER = "/var/tmp/yarn-${EXECUTOR_NUMBER}"
GRADLE_USER_HOME = "/var/tmp/gradle-${EXECUTOR_NUMBER}"
}
stages {
@ -54,12 +55,12 @@ pipeline {
}
stage('Lint') {
steps {
script { cmn.utils.nix_sh('lein cljfmt check') }
script { cmn.nix.shell('lein cljfmt check') }
}
}
stage('Tests') {
steps {
script { cmn.utils.nix_sh('lein test-cljs') }
script { cmn.nix.shell('lein test-cljs') }
}
}
stage('Build') {

View File

@ -22,13 +22,16 @@ pipeline {
}
environment {
LANG = "en_US.UTF-8"
LC_ALL = "en_US.UTF-8"
LANGUAGE = "en_US.UTF-8"
TARGET_OS = 'macos'
CI_ENVIRONMENT = 'jenkins'
LANG = 'en_US.UTF-8'
LANGUAGE = 'en_US.UTF-8'
LC_ALL = 'en_US.UTF-8'
NIX_CONF_DIR = "${env.WORKSPACE}/nix"
VERBOSE_LEVEL = '3'
/* We use EXECUTOR_NUMBER to avoid multiple instances clashing */
LEIN_HOME = "/var/tmp/lein-${EXECUTOR_NUMBER}"
YARN_CACHE_FOLDER = "/var/tmp/yarn-${EXECUTOR_NUMBER}"
GRADLE_USER_HOME = "/var/tmp/gradle-${EXECUTOR_NUMBER}"
}
stages {
@ -48,12 +51,12 @@ pipeline {
}
stage('Lint') {
steps {
script { cmn.utils.nix_sh('lein cljfmt check') }
script { cmn.nix.shell('lein cljfmt check') }
}
}
stage('Tests') {
steps {
script { cmn.utils.nix_sh('lein test-cljs') }
script { cmn.nix.shell('lein test-cljs') }
}
}
stage('Build') {

View File

@ -2,7 +2,6 @@ pipeline {
agent { label params.AGENT_LABEL }
environment {
CI_ENVIRONMENT = 'jenkins'
/* we source .bash_profile to be able to use nix-store */
NIX_SSHOPTS = "-o StrictHostKeyChecking=no source .bash_profile;"
/* where our /nix/store is hosted */

View File

@ -26,18 +26,20 @@ pipeline {
* https://issues.jenkins-ci.org/browse/JENKINS-49076
**/
environment {
LANG = "en_US.UTF-8"
LC_ALL = "en_US.UTF-8"
LANGUAGE = "en_US.UTF-8"
TARGET_OS = 'windows'
CI_ENVIRONMENT = 'jenkins'
LANG = 'en_US.UTF-8'
LANGUAGE = 'en_US.UTF-8'
LC_ALL = 'en_US.UTF-8'
NPM_CONFIG_CACHE = '/var/tmp/npm'
LEIN_HOME = '/var/tmp/lein'
NIX_CONF_DIR = "${env.WORKSPACE}/nix"
VERBOSE_LEVEL = '3'
/* Conan settings */
CONAN_PRINT_RUN_COMMANDS = '1'
CONAN_SYSREQUIRES_MODE = 'disabled'
CONAN_SYSREQUIRES_SUDO = '0'
VERBOSE_LEVEL = '3'
/* We use EXECUTOR_NUMBER to avoid multiple instances clashing */
LEIN_HOME = "/var/tmp/lein-${EXECUTOR_NUMBER}"
YARN_CACHE_FOLDER = "/var/tmp/yarn-${EXECUTOR_NUMBER}"
GRADLE_USER_HOME = "/var/tmp/gradle-${EXECUTOR_NUMBER}"
}
stages {
@ -57,12 +59,12 @@ pipeline {
}
stage('Lint') {
steps {
script { cmn.utils.nix_sh('lein cljfmt check') }
script { cmn.nix.shell('lein cljfmt check') }
}
}
stage('Tests') {
steps {
script { cmn.utils.nix_sh('lein test-cljs') }
script { cmn.nix.shell('lein test-cljs') }
}
}
stage('Build') {

View File

@ -1,3 +1,4 @@
nix = load 'ci/nix.groovy'
utils = load 'ci/utils.groovy'
def bundle() {
@ -24,7 +25,14 @@ def bundle() {
passwordVariable: 'STATUS_RELEASE_KEY_PASSWORD'
)
]) {
utils.nix_sh "./gradlew assemble${target.capitalize()} ${gradleOpt}"
nix.shell(
"./gradlew assemble${target.capitalize()} ${gradleOpt}",
keep: [
'REALM_DISABLE_ANALYTICS',
'STATUS_RELEASE_STORE_FILE', 'STATUS_RELEASE_STORE_PASSWORD',
'STATUS_RELEASE_KEY_ALIAS', 'STATUS_RELEASE_KEY_PASSWORD'
]
)
}
}
sh 'find android/app/build/outputs/apk'
@ -34,7 +42,6 @@ def bundle() {
sh "cp ${outApk} ${pkg}"
/* necessary for Fastlane */
env.APK_PATH = pkg
env.DIAWI_APK = pkg
return pkg
}
@ -42,7 +49,10 @@ def uploadToPlayStore(type = 'nightly') {
withCredentials([
string(credentialsId: "SUPPLY_JSON_KEY_DATA", variable: 'GOOGLE_PLAY_JSON_KEY'),
]) {
utils.nix_fastlane_sh "android ${type}"
nix.shell(
"fastlane android ${type}",
keep: ['FASTLANE_DISABLE_COLORS', 'GOOGLE_PLAY_JSON_KEY']
)
}
}
@ -58,7 +68,13 @@ def uploadToSauceLabs() {
string(credentialsId: 'SAUCE_ACCESS_KEY', variable: 'SAUCE_ACCESS_KEY'),
string(credentialsId: 'SAUCE_USERNAME', variable: 'SAUCE_USERNAME'),
]) {
utils.nix_fastlane_sh 'android saucelabs'
nix.shell(
'fastlane android saucelabs',
keep: [
'FASTLANE_DISABLE_COLORS', 'APK_PATH',
'SAUCE_ACCESS_KEY', 'SAUCE_USERNAME', 'SAUCE_LABS_NAME'
]
)
}
return env.SAUCE_LABS_NAME
}
@ -68,7 +84,10 @@ def uploadToDiawi() {
withCredentials([
string(credentialsId: 'diawi-token', variable: 'DIAWI_TOKEN'),
]) {
utils.nix_fastlane_sh 'android upload_diawi'
nix.shell(
'fastlane android upload_diawi',
keep: ['FASTLANE_DISABLE_COLORS', 'APK_PATH', 'DIAWI_TOKEN']
)
}
diawiUrl = readFile "${env.WORKSPACE}/fastlane/diawi.out"
return diawiUrl

View File

@ -1,8 +1,11 @@
import groovy.json.JsonBuilder
/* Libraries -----------------------------------------------------------------*/
gh = load 'ci/github.groovy'
ci = load 'ci/jenkins.groovy'
gh = load 'ci/github.groovy'
nix = load 'ci/nix.groovy'
utils = load 'ci/utils.groovy'
ghcmgr = load 'ci/ghcmgr.groovy'
@ -42,19 +45,9 @@ def notifyPR(success) {
}
}
def prepNixEnvironment() {
if (env.TARGET_OS == 'linux' || env.TARGET_OS == 'windows' || env.TARGET_OS == 'android') {
def glibcLocales = sh(
returnStdout: true,
script: ". ~/.nix-profile/etc/profile.d/nix.sh && nix-build --no-out-link '<nixpkgs>' -A glibcLocales"
).trim()
env.LOCALE_ARCHIVE_2_27 = "${glibcLocales}/lib/locale/locale-archive"
}
}
def prep(type = 'nightly') {
/* build/downloads all nix deps in advance */
prepNixEnvironment()
nix.prepEnv()
/* rebase unless this is a release build */
utils.doGitRebase()
/* ensure that we start from a known state */
@ -69,7 +62,7 @@ def prep(type = 'nightly') {
if (env.TARGET_OS == 'ios') {
/* install ruby dependencies */
utils.nix_sh 'bundle install --gemfile=fastlane/Gemfile --quiet'
nix.shell 'bundle install --gemfile=fastlane/Gemfile --quiet'
}
def prepareTarget=env.TARGET_OS
@ -77,7 +70,7 @@ def prep(type = 'nightly') {
prepareTarget='desktop'
}
/* node deps, pods, and status-go download */
utils.nix_impure_sh "scripts/prepare-for-platform.sh ${prepareTarget}"
utils.nix.shell("scripts/prepare-for-platform.sh ${prepareTarget}", pure: false)
}
return this

View File

@ -1,20 +1,24 @@
utils = load 'ci/utils.groovy'
nix = load 'ci/nix.groovy'
cmn = load 'ci/common.groovy'
utils = load 'ci/utils.groovy'
packageFolder = './StatusImPackage'
def cleanupAndDeps() {
sh 'make clean'
sh 'cp .env.jenkins .env'
utils.nix_sh 'lein deps'
nix.shell 'lein deps'
utils.installJSDeps('desktop')
}
def buildClojureScript() {
utils.nix_sh '''
make prod-build-desktop && \
./scripts/build-desktop.sh buildClojureScript
'''
nix.shell(
'''
make prod-build-desktop && \
./scripts/build-desktop.sh buildClojureScript
''',
keep: ['VERBOSE_LEVEL']
)
}
def uploadArtifact(filename) {
@ -51,13 +55,19 @@ def compile() {
if (env.QT_PATH) {
env.PATH = "${env.QT_PATH}:${env.PATH}"
}
utils.nix_sh './scripts/build-desktop.sh compile'
nix.shell(
'./scripts/build-desktop.sh compile',
keep: ['VERBOSE_LEVEL']
)
}
def bundleWindows(type = 'nightly') {
def pkg
utils.nix_sh './scripts/build-desktop.sh bundle'
nix.shell(
'./scripts/build-desktop.sh bundle',
keep: ['VERBOSE_LEVEL']
)
dir(packageFolder) {
pkg = utils.pkgFilename(type, 'exe')
sh "mv ../Status-x86_64-setup.exe ${pkg}"
@ -67,7 +77,10 @@ def bundleWindows(type = 'nightly') {
def bundleLinux(type = 'nightly') {
def pkg
utils.nix_sh './scripts/build-desktop.sh bundle'
nix.shell(
'./scripts/build-desktop.sh bundle',
keep: ['VERBOSE_LEVEL']
)
dir(packageFolder) {
pkg = utils.pkgFilename(type, 'AppImage')
sh "mv ../Status-x86_64.AppImage ${pkg}"
@ -77,18 +90,25 @@ def bundleLinux(type = 'nightly') {
def bundleMacOS(type = 'nightly') {
def pkg = utils.pkgFilename(type, 'dmg')
utils.nix_sh './scripts/build-desktop.sh bundle'
nix.shell(
'./scripts/build-desktop.sh bundle',
keep: ['VERBOSE_LEVEL']
)
dir(packageFolder) {
withCredentials([
string(credentialsId: 'desktop-gpg-outer-pass', variable: 'GPG_PASS_OUTER'),
string(credentialsId: 'desktop-gpg-inner-pass', variable: 'GPG_PASS_INNER'),
string(credentialsId: 'desktop-keychain-pass', variable: 'KEYCHAIN_PASS')
]) {
utils.nix_impure_sh """
nix.shell(
"""
../scripts/sign-macos-pkg.sh Status.app ../deployment/macos/macos-developer-id.keychain-db.gpg && \
../node_modules/appdmg/bin/appdmg.js ../deployment/macos/status-dmg.json ${pkg} && \
../scripts/sign-macos-pkg.sh ${pkg} ../deployment/macos/macos-developer-id.keychain-db.gpg
"""
""",
pure: false,
keep: ['GPG_PASS_OUTER', 'GPG_PASS_INNER', 'KEYCHAIN_PASS']
)
}
}
return "${packageFolder}/${pkg}".drop(2)

View File

@ -1,3 +1,4 @@
nix = load('ci/nix.groovy')
utils = load('ci/utils.groovy')
def plutil(name, value) {
@ -16,7 +17,7 @@ def bundle() {
default: target = 'nightly';
}
/* configure build metadata */
utils.nix_sh(
nix.shell(
plutil('CFBundleShortVersionString', utils.getVersion('mobile_files')) +
plutil('CFBundleVersion', utils.genBuildNumber()) +
plutil('CFBundleBuildUrl', currentBuild.absoluteUrl)
@ -33,7 +34,14 @@ def bundle() {
passwordVariable: 'FASTLANE_PASSWORD'
),
]) {
utils.nix_sh "bundle exec --gemfile=fastlane/Gemfile fastlane ios ${target}"
nix.shell(
"bundle exec --gemfile=fastlane/Gemfile fastlane ios ${target}",
keep: [
'FASTLANE_DISABLE_COLORS',
'FASTLANE_PASSWORD', 'KEYCHAIN_PASSWORD',
'MATCH_PASSWORD', 'FASTLANE_APPLE_ID',
]
)
}
/* rename built file for uploads and archivization */
def pkg = ''
@ -56,7 +64,10 @@ def uploadToDiawi() {
withCredentials([
string(credentialsId: 'diawi-token', variable: 'DIAWI_TOKEN'),
]) {
utils.nix_sh 'bundle exec --gemfile=fastlane/Gemfile fastlane ios upload_diawi'
nix.shell(
'bundle exec --gemfile=fastlane/Gemfile fastlane ios upload_diawi',
keep: ['FASTLANE_DISABLE_COLORS', 'DIAWI_TOKEN']
)
}
diawiUrl = readFile "${env.WORKSPACE}/fastlane/diawi.out"
return diawiUrl
@ -73,7 +84,10 @@ def uploadToSauceLabs() {
string(credentialsId: 'SAUCE_ACCESS_KEY', variable: 'SAUCE_ACCESS_KEY'),
string(credentialsId: 'SAUCE_USERNAME', variable: 'SAUCE_USERNAME'),
]) {
utils.nix_sh 'bundle exec --gemfile=fastlane/Gemfile fastlane ios saucelabs'
nix.shell(
'bundle exec --gemfile=fastlane/Gemfile fastlane ios saucelabs',
keep: ['FASTLANE_DISABLE_COLORS', 'SAUCE_ACCESS_KEY', 'SAUCE_USERNAME']
)
}
return env.SAUCE_LABS_NAME
}

53
ci/nix.groovy Normal file
View File

@ -0,0 +1,53 @@
/**
* Arguments:
* - pure - Use --pure mode with Nix for more deterministic behaviour
* - keep - List of env variables to keep even in pure mode
* - args - Map of arguments to provide to --argstr
**/
def shell(Map opts = [:], String cmd) {
def defaults = [
pure: true,
args: ['target-os': env.TARGET_OS],
keep: ['LOCALE_ARCHIVE_2_27'],
]
/* merge defaults with received opts */
opts = defaults + opts
/* Previous merge overwrites the array */
opts.keep = (opts.keep + defaults.keep).unique()
def isPure = opts.pure && env.TARGET_OS != 'windows' && env.TARGET_OS != 'ios'
def keepFlags = opts.keep.collect { var -> "--keep ${var} " }
def argsFlags = opts.args.collect { key,val -> "--argstr ${key} \'${val}\'" }
sh """
set +x
. ~/.nix-profile/etc/profile.d/nix.sh
set -x
nix-shell \\
${isPure ? "--pure" : ""} \\
${keepFlags.join(" ")} \\
${argsFlags.join(" ")} \\
--run \'${cmd}\' \\
\'${env.WORKSPACE}/shell.nix\'
"""
}
def prepEnv() {
if (env.TARGET_OS in ['linux', 'windows', 'android']) {
def glibcLocales = sh(
returnStdout: true,
script: """
. ~/.nix-profile/etc/profile.d/nix.sh && \\
nix-build --no-out-link '<nixpkgs>' -A glibcLocales
"""
).trim()
/**
* This is a hack to fix missing locale errors.
* See:
* - https://github.com/NixOS/nixpkgs/issues/38991
* - https://qiita.com/kimagure/items/4449ceb0bda5c10ca50f
**/
env.LOCALE_ARCHIVE_2_27 = "${glibcLocales}/lib/locale/locale-archive"
}
}
return this

View File

@ -1,3 +1,5 @@
nix = load 'ci/nix.groovy'
def getVersion(type = null) {
/* if type is undefined we get VERSION from repo root */
def path = "${env.WORKSPACE}/VERSION"
@ -15,42 +17,6 @@ def getToolVersion(name) {
return version
}
def nix_impure_sh(cmd) {
_nix_sh(cmd, true)
}
def nix_sh(cmd) {
_nix_sh(cmd, false)
}
def _nix_sh(cmd, forceImpure) {
def isPure = !forceImpure && env.TARGET_OS != 'windows' && env.TARGET_OS != 'ios'
def pureFlag = isPure ? '--pure --keep LOCALE_ARCHIVE_2_27 --keep REALM_DISABLE_ANALYTICS --keep STATUS_RELEASE_STORE_FILE --keep STATUS_RELEASE_STORE_PASSWORD --keep STATUS_RELEASE_KEY_ALIAS --keep STATUS_RELEASE_KEY_PASSWORD --keep GPG_PASS_OUTER --keep GPG_PASS_INNER --keep KEYCHAIN_PASS --keep VERBOSE_LEVEL' : ''
sh """
set +x
. ~/.nix-profile/etc/profile.d/nix.sh
set -x
nix-shell --argstr target-os \'${env.TARGET_OS}\' \\
${pureFlag} --run \'${cmd}\' \\
\'${env.WORKSPACE}/shell.nix\'
"""
}
def nix_fastlane_sh(cmd) {
def isPure = env.TARGET_OS != 'ios'
def pureFlag = isPure ? '--pure --keep LANG --keep LANGUAGE --keep LC_ALL --keep DIAWI_TOKEN --keep DIAWI_IPA --keep APK_PATH --keep GOOGLE_PLAY_JSON_KEY --keep SAUCE_LABS_NAME --keep SAUCE_USERNAME --keep SAUCE_ACCESS_KEY --keep FASTLANE_DISABLE_COLORS --keep FASTLANE_APPLE_ID --keep FASTLANE_PASSWORD --keep KEYCHAIN_PASSWORD --keep MATCH_PASSWORD --keep REALM_DISABLE_ANALYTICS --keep STATUS_RELEASE_STORE_FILE --keep GRADLE_USER_HOME' : ''
sh """
set +x
. ~/.nix-profile/etc/profile.d/nix.sh
set -x
nix-shell --argstr target-os \'${env.TARGET_OS}\' \\
${pureFlag} --run \'fastlane ${cmd}\' \\
\'${env.WORKSPACE}/shell.nix\'
"""
}
def branchName() {
return env.GIT_BRANCH.replaceAll(/.*origin\//, '')
}
@ -136,10 +102,10 @@ def installJSDeps(platform) {
def maxAttempts = 10
def installed = false
/* prepare environment for specific platform build */
nix_sh "scripts/prepare-for-platform.sh ${platform}"
nix.shell "scripts/prepare-for-platform.sh ${platform}"
while (!installed && attempt <= maxAttempts) {
println "#${attempt} attempt to install npm deps"
nix_sh 'yarn install --frozen-lockfile'
nix.shell 'yarn install --frozen-lockfile'
installed = fileExists('node_modules/web3/index.js')
attemp = attempt + 1
}

View File

@ -23,42 +23,43 @@ def unlock_keychain_if_needed
end
end
def curl_upload(url, file, user, conn_timeout=5, timeout=60, retries=3)
begin
return sh(
"curl",
"--fail",
"--silent",
"--user", user,
"--request", "POST",
"--header", "Content-Type: application/octet-stream",
"--data-binary", "@../#{file}", # `fastlane` is the cwd so we go one folder up
# we retry few times if upload doesn't succeed in sensible time
"--retry-connrefused", # consider ECONNREFUSED as error too retry
"--connect-timeout", conn_timeout.to_s, # max time in sec. for establishing connection
"--max-time", timeout.to_s, # max time in sec. for whole transfer to take
"--retry", retries.to_s, # number of retries to attempt
"--retry-max-time", timeout.to_s, # same as --max-time but for retries
"--retry-delay", "0", # an exponential backoff algorithm in sec.
url
)
rescue => error
UI.error "Error: #{error}"
raise
def curl_upload(url, file, auth, conn_timeout=5, timeout=60, retries=3)
rval = sh(
"curl",
"--silent",
"--user", auth,
"--write-out", "\nHTTP_CODE:%{http_code}",
"--request", "POST",
"--header", "Content-Type: application/octet-stream",
"--data-binary", "@../#{file}", # `fastlane` is the cwd so we go one folder up
# we retry few times if upload doesn't succeed in sensible time
"--retry-connrefused", # consider ECONNREFUSED as error too retry
"--connect-timeout", conn_timeout.to_s, # max time in sec. for establishing connection
"--max-time", timeout.to_s, # max time in sec. for whole transfer to take
"--retry", retries.to_s, # number of retries to attempt
"--retry-max-time", timeout.to_s, # same as --max-time but for retries
"--retry-delay", "0", # an exponential backoff algorithm in sec.
url
)
# We're not using --fail because it suppresses server response
if not rval.include? "HTTP_CODE:200"
raise "Error:\n#{rval}"
end
return rval
end
def retry_curl_upload(url, file, user, conn_timeout=5, timeout=60, retries=3)
def retry_curl_upload(url, file, auth, conn_timeout=5, timeout=60, retries=3)
# since curl doesn't retry on connection and operation timeouts we roll our own
try = 0
begin
return curl_upload(url, file, user, conn_timeout, timeout, retries)
return curl_upload(url, file, auth, conn_timeout, timeout, retries)
rescue => error
try += 1
if try <= retries
UI.important "Warning: Retrying cURL upload! (attempt #{try}/#{retries})"
retry
else
UI.error "Error:\n#{error}"
raise
end
end

View File

@ -19,7 +19,6 @@ function exit_unless_os_supported() {
cecho "@red[[This install script is not supported in a pure Nix shell]]"
echo
exit 1
fi
@ -28,9 +27,7 @@ function exit_unless_os_supported() {
via apt. To manually install, please visit the docs for more information:]]
@blue[[https://status.im/build_status]]"
echo
exit 1
fi
}

View File

@ -28,7 +28,7 @@ if [ $_need_curl -eq 1 ] && ! program_exists "curl"; then
exit 1
fi
if is_linux && [ -z "$CI_ENVIRONMENT" ]; then
if is_linux && [ -z "$JENKINS_URL" ]; then
watches=$(cat /proc/sys/fs/inotify/max_user_watches)
required_watches=524288
if [ $watches -lt $required_watches ]; then

View File

@ -48,4 +48,4 @@ in mkShell' {
fi
set +e
'';
}
}