diff --git a/.travis.yml b/.travis.yml index eb6e4b6279..17669d2150 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,15 @@ before_install: - "cp -r stub-runner/stub-runner-spring/src/test/resources/m2repo/repository/io/codearte/accurest/stubs $HOME/.m2/repository/io/codearte/accurest/" jdk: - - oraclejdk7 - oraclejdk8 install: ./gradlew assemble -s -script: ./gradlew check funcTest install -s --continue && jdk_switcher use oraclejdk8 && ./scripts/runTests.sh +script: ./gradlew check funcTest install -s --continue && jdk_switcher use oraclejdk8 && ./scripts/runTests.sh && jdk_switcher use $TRAVIS_JDK_VERSION && ./gradlew uploadSnapshotArchives -s + +matrix: + include: + # Automatic snapshot release only in Java 7 build + - jdk: oraclejdk7 + env: + - DO_RELEASE=true + diff --git a/build.gradle b/build.gradle index 73d3214e83..9cc73475f1 100644 --- a/build.gradle +++ b/build.gradle @@ -36,6 +36,8 @@ nexusStaging { stagingProfileId = '93c08fdebde1ff' } +apply from: "$rootDir/gradle/releaseRoot.gradle" + subprojects { apply plugin: 'groovy' apply from: "$rootDir/gradle/release.gradle" @@ -211,4 +213,5 @@ buildscript { } } -apply plugin: "com.palantir.idea-test-fix" \ No newline at end of file +apply plugin: "com.palantir.idea-test-fix" + diff --git a/gradle/release.gradle b/gradle/release.gradle index e3f5159bb1..e1c6fb4494 100644 --- a/gradle/release.gradle +++ b/gradle/release.gradle @@ -38,3 +38,22 @@ modifyPom { uploadArchives.dependsOn { check } + +task uploadSnapshotArchives { + if (shouldUploadSnapshotArchives) { + dependsOn { uploadArchives } + } + onlyIf { shouldUploadSnapshotArchives } +} + +//for Travis to leverage secure variables +project.ext { + if (!hasProperty('nexusUsername') && System.env.NEXUS_USERNAME) { + nexusUsername = System.env.NEXUS_USERNAME + } + if (!hasProperty('nexusPassword') && System.env.NEXUS_PASSWORD) { + nexusPassword = System.env.NEXUS_PASSWORD + } +} + + diff --git a/gradle/releaseRoot.gradle b/gradle/releaseRoot.gradle new file mode 100644 index 0000000000..667dcbcb82 --- /dev/null +++ b/gradle/releaseRoot.gradle @@ -0,0 +1,16 @@ +assert project == rootProject + +project.ext { + isSnapshot = project.version.endsWith("-SNAPSHOT") + currentBranch = System.env.TRAVIS_BRANCH + isPr = !isNullOrFalse(System.env.TRAVIS_PULL_REQUEST) + doRelease = !isNullOrFalse(System.env.DO_RELEASE) + shouldUploadSnapshotArchives = isSnapshot && currentBranch == 'master' && !isPr && doRelease +} + +logger.lifecycle("Automatic snapshot release: {} (isSnapshot: {}, currentBranch: {}, isPr: {}, doRelease: {})", shouldUploadSnapshotArchives, isSnapshot, currentBranch, isPr, doRelease) + +private boolean isNullOrFalse(def env) { + env == null || env == "false" || (env instanceof Boolean && !env) +} +