Skip to content

Commit

Permalink
Merge 316441d into c3730ad
Browse files Browse the repository at this point in the history
  • Loading branch information
rpalcolea committed Sep 13, 2019
2 parents c3730ad + 316441d commit 263def6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Expand Up @@ -23,7 +23,7 @@ class ReleasePluginConfiguredVersionIntegrationSpec extends GitVersioningIntegra
addSubproject('test-release-common', '// hello')
addSubproject('test-release-client', '''\
dependencies {
compile project(':test-release-common')
implementation project(':test-release-common')
}
'''.stripIndent())

Expand Down
17 changes: 9 additions & 8 deletions src/main/groovy/nebula/plugin/release/ReleaseCheck.groovy
Expand Up @@ -15,42 +15,43 @@
*/
package nebula.plugin.release

import org.ajoberstar.grgit.Grgit
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction

class ReleaseCheck extends DefaultTask {
Grgit grgit
@Input
String branchName
@Input
ReleaseExtension patterns
@Input
boolean isSnapshotRelease

@TaskAction
void check() {
if (patterns.allowReleaseFromDetached) {
return
}
String branchName = grgit.branch.current.name

boolean includeMatch = patterns.releaseBranchPatterns.isEmpty()

patterns.releaseBranchPatterns.each { String pattern ->
if (branchName ==~ pattern) includeMatch = true
if (getBranchName() ==~ pattern) includeMatch = true
}

boolean excludeMatch = false
patterns.excludeBranchPatterns.each { String pattern ->
if (branchName ==~ pattern) excludeMatch = true
if (getBranchName() ==~ pattern) excludeMatch = true
}

if (!includeMatch && !isSnapshotRelease) {
String message = "Branch ${branchName} does not match one of the included patterns: ${patterns.releaseBranchPatterns}"
String message = "Branch ${getBranchName()} does not match one of the included patterns: ${patterns.releaseBranchPatterns}"
logger.error(message)
throw new GradleException(message)
}

if (excludeMatch) {
String message = "Branch ${branchName} matched an excluded pattern: ${patterns.excludeBranchPatterns}"
String message = "Branch ${getBranchName()} matched an excluded pattern: ${patterns.excludeBranchPatterns}"
logger.error(message)
throw new GradleException(message)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy
Expand Up @@ -119,7 +119,7 @@ class ReleasePlugin implements Plugin<Project> {

def releaseCheck = project.tasks.create(RELEASE_CHECK_TASK_NAME, ReleaseCheck)
releaseCheck.group = GROUP
releaseCheck.grgit = releaseExtension.grgit
releaseCheck.branchName = releaseExtension.grgit.branch.current().name
releaseCheck.patterns = nebulaReleaseExtension

def postReleaseTask = project.task(POST_RELEASE_TASK_NAME)
Expand Down

0 comments on commit 263def6

Please sign in to comment.