Monday, 14 October 2019

How to configure gradle buildTypes to only run if jest test pass?

I am trying to run my react-native jest tests before any type of android build. If the test pass then I allow to build, if not I print an error message. I looked up gradle and couldnt figure out how to configure my different buildtypes to do that. I tried to start to add to my build.gradle file a very simple task :

task runTests {
   println 'runTests before build'
}

and a

tasks.assembleDebug.dependsOn runTests

but that just makes the whole build fails. Here's how my build.gradle looks like:

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 23
    defaultConfig {
        applicationId "com.timeo"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    signingConfigs {
     release {
           if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
             storeFile file(MYAPP_RELEASE_STORE_FILE)
             storePassword MYAPP_RELEASE_STORE_PASSWORD
             keyAlias MYAPP_RELEASE_KEY_ALIAS
             keyPassword MYAPP_RELEASE_KEY_PASSWORD
         }
      }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
        debug {
          debuggable true
        }
        dev {
          initWith debug
        }
        staging {
          initWith debug
          matchingFallbacks = ['debug']
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    implementation project(':react-native-config')
    implementation project(':rn-fetch-blob')
    implementation project(':react-native-file-opener')
    implementation project(':react-native-fs')
    implementation project(':react-native-document-picker')
    implementation project(':react-native-svg')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:23.0.1"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

How can I configure gradle to only build if the jest test (npm run test) pass ?



from How to configure gradle buildTypes to only run if jest test pass?

No comments:

Post a Comment