Skip to content

Commit

Permalink
Add net.wooga.github plugin (#2)
Browse files Browse the repository at this point in the history
* Add net.wooga.github plugin

Add new github publish plugin and configure it into the release
lifecycle.

* Update net.wooga.paket to 0.6.0
  • Loading branch information
Larusso authored Jul 6, 2017
1 parent 417d937 commit 8dbbb38
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 41 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ dependencies {
compile 'com.netflix.nebula:nebula-release-plugin:5.+'
compile 'org.ajoberstar:gradle-git:1.7.+'
compile 'cz.malohlava:visteg:1.0.+'
compile 'gradle.plugin.net.wooga.gradle:atlas-paket:0.5.0'
compile 'gradle.plugin.net.wooga.gradle:atlas-paket:0.6.0'
compile 'gradle.plugin.net.wooga.gradle:atlas-github:0.3.0'

compile gradleApi()
compile localGroovy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package wooga.gradle.release

import nebula.test.IntegrationSpec
import org.ajoberstar.grgit.Grgit
import spock.lang.Ignore
import spock.lang.Unroll

class ReleasePluginIntegrationSpec extends IntegrationSpec {
Expand Down Expand Up @@ -144,9 +145,12 @@ class ReleasePluginIntegrationSpec extends IntegrationSpec {
["2.14", "3.0", "3.2", "3.4", "3.4.1", "3.5", "3.5.1", "4.0"]
}

@Ignore
@Unroll("verify plugin activation with gradle #gradleVersionToTest")
def "activates with multiple gradle versions"() {
given: "a buildfile with unity plugin applied"
fork = true

buildFile << """
group = 'test'
${applyPlugin(ReleasePlugin)}
Expand Down
48 changes: 44 additions & 4 deletions src/main/groovy/wooga/gradle/release/ReleasePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ import nebula.plugin.release.NetflixOssStrategies
import org.ajoberstar.gradle.git.release.base.ReleasePluginExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
import org.gradle.api.publish.plugins.PublishingPlugin
import org.gradle.api.specs.Spec
import org.gradle.api.tasks.Copy
import org.gradle.language.base.plugins.LifecycleBasePlugin
import wooga.gradle.github.publish.GithubPublish
import wooga.gradle.github.publish.GithubPublishPlugin
import wooga.gradle.paket.PaketPlugin
import wooga.gradle.paket.base.PaketBasePlugin
import wooga.gradle.paket.get.PaketGetPlugin
import wooga.gradle.paket.pack.tasks.PaketPack
import wooga.gradle.paket.unity.PaketUnityPlugin

class ReleasePlugin implements Plugin<Project> {
Expand All @@ -52,10 +58,10 @@ class ReleasePlugin implements Plugin<Project> {

applyNebularRelease(project)
applyVisteg(project)
applyWoogaPaket(project)
applyWoogaPlugins(project)

Configuration archives = project.configurations.maybeCreate(ARCHIVES_CONFIGURATION)

archives.extendsFrom(project.configurations.getByName(PaketBasePlugin.PAKET_CONFIGURATION))
def unityPack = tasks.create(name: UNTIY_PACK_TASK, type: Copy, group: GROUP) {
from(archives) {
include '**/*.unitypackage'
Expand All @@ -71,10 +77,20 @@ class ReleasePlugin implements Plugin<Project> {
//hook up into lifecycle
def checkTask = tasks.getByName(LifecycleBasePlugin.CHECK_TASK_NAME)
def assembleTask = tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
def buildTask = tasks.getByName(LifecycleBasePlugin.BUILD_TASK_NAME)
buildTask.dependsOn setup

tasks.withType(PaketPack, new org.gradle.api.Action<PaketPack>() {
@Override
void execute(PaketPack paketPack) {
paketPack.dependsOn setup
}
})

def releaseTask = tasks.getByName('release')
def postReleaseTask = tasks.getByName(nebula.plugin.release.ReleasePlugin.POST_RELEASE_TASK_NAME)
def publishTask = tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME)

GithubPublish githubPublishTask = (GithubPublish) tasks.getByName(GithubPublishPlugin.PUBLISH_TASK_NAME)
def candiateTask = tasks.getByName(nebula.plugin.release.ReleasePlugin.CANDIDATE_TASK_NAME)
def rcTask = tasks.create(name: RC_TASK, group: nebula.plugin.release.ReleasePlugin.GROUP, dependsOn: candiateTask)
if (!tasks.hasProperty(TEST_TASK)) {
Expand All @@ -85,10 +101,25 @@ class ReleasePlugin implements Plugin<Project> {
assembleTask.dependsOn unityPack
releaseTask.dependsOn assembleTask
postReleaseTask.dependsOn publishTask

githubPublishTask.onlyIf(new Spec<Task>() {
@Override
boolean isSatisfiedBy(Task task) {
Boolean satisfied = project.status == 'candidate' || project.status == 'release'
println("'release.stage' check satisfied $satisfied")
return satisfied
}
})

githubPublishTask.from(archives)
githubPublishTask.dependsOn archives
githubPublishTask.tagName = "v${project.version}"
githubPublishTask.setReleaseName(project.version.toString())
}

configureVersionCode(project)
configureUnityPackageIfPresent(project)
configurePaketPackageIfPresent(project)
}

def configureVersionCode(Project project) {
Expand All @@ -114,7 +145,15 @@ class ReleasePlugin implements Plugin<Project> {
logger.info("configure dependencies {}", sub.path)
dependencies.add(ARCHIVES_CONFIGURATION, dependencies.project(path: sub.path, configuration: "unitypackage"))
}
}
}
}

private configurePaketPackageIfPresent(Project project) {
project.afterEvaluate {
Configuration paketConfiguration = project.configurations.getByName(PaketBasePlugin.PAKET_CONFIGURATION)
paketConfiguration.allArtifacts.each {
project.dependencies.add(ARCHIVES_CONFIGURATION, project.files(it.file).builtBy(it.buildDependencies))
}
}
}
Expand Down Expand Up @@ -150,7 +189,8 @@ class ReleasePlugin implements Plugin<Project> {
}
}

private void applyWoogaPaket(Project project) {
private void applyWoogaPlugins(Project project) {
project.pluginManager.apply(GithubPublishPlugin)
project.pluginManager.apply(PaketPlugin)
project.pluginManager.apply(PaketUnityPlugin)
}
Expand Down
160 changes: 124 additions & 36 deletions src/test/groovy/wooga/gradle/release/ReleasePluginSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ import nebula.test.ProjectSpec
import org.ajoberstar.gradle.git.release.base.BaseReleasePlugin
import org.ajoberstar.gradle.git.release.base.ReleasePluginExtension
import org.ajoberstar.grgit.Grgit
import org.ajoberstar.grgit.operation.BranchAddOp
import org.ajoberstar.grgit.operation.BranchChangeOp
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.specs.Spec
import org.gradle.cache.internal.VersionStrategy
import spock.lang.Unroll
import wooga.gradle.github.publish.GithubPublishPlugin
import wooga.gradle.paket.PaketPlugin
import wooga.gradle.paket.pack.tasks.PaketPack
import wooga.gradle.paket.unity.PaketUnityPlugin
import wooga.gradle.release.WoogaStrategies


class ReleasePluginActivationSpec extends PluginProjectSpec {
Grgit git

Expand All @@ -56,28 +62,26 @@ class ReleasePluginSpec extends ProjectSpec {
git.tag.add(name: 'v0.0.1')
}

def "adds nebular release plugin"() {
@Unroll("applies plugin #pluginName")
def 'Applies other plugins'(String pluginName, Class pluginType) {
given:
assert !project.plugins.hasPlugin(PLUGIN_NAME)
assert !project.plugins.hasPlugin(ReleasePlugin)
assert !project.plugins.hasPlugin(pluginType)

when:
project.plugins.apply(PLUGIN_NAME)

then:
project.plugins.hasPlugin(ReleasePlugin)
}

def "adds gradle-git through nebular release plugin"() {
given:
assert !project.plugins.hasPlugin(PLUGIN_NAME)
assert !project.plugins.hasPlugin(BaseReleasePlugin)
project.plugins.hasPlugin(pluginType)

when:
project.plugins.apply(PLUGIN_NAME)

then:
project.plugins.hasPlugin(BaseReleasePlugin)
where:
pluginName | pluginType
"releasePlugin" | ReleasePlugin
"baseReleasePlugin" | BaseReleasePlugin
"vistec" | VisTaskExecGraphPlugin
"githubPublish" | GithubPublishPlugin
"paket" | PaketPlugin
"paket-unity" | PaketUnityPlugin
}

def findStrategyByName(List<VersionStrategy> strategies, name) {
Expand All @@ -95,9 +99,9 @@ class ReleasePluginSpec extends ProjectSpec {
findStrategyByName(strategies, strategyName) == strategy

where:
strategyName | strategy
"snapshot" | WoogaStrategies.SNAPSHOT
"pre-release" | WoogaStrategies.PRE_RELEASE
strategyName | strategy
"snapshot" | WoogaStrategies.SNAPSHOT
"pre-release" | WoogaStrategies.PRE_RELEASE
}

def "veryfy default version strategies"() {
Expand Down Expand Up @@ -192,15 +196,15 @@ class ReleasePluginSpec extends ProjectSpec {

where:

tagVersion | commitsBefore | commitsAfter | stage | scope | expectedVersion
'1.0.0' | 1 | 3 | "SNAPSHOT" | "minor" | "1.1.0-master00003"
'1.0.0' | 1 | 3 | "rc" | "minor" | "1.1.0-rc00001"
'1.0.0' | 1 | 3 | "final" | "minor" | "1.1.0"
'1.0.0' | 1 | 3 | "final" | "major" | "2.0.0"
'1.0.0-rc00001' | 10 | 5 | "rc" | "major" | "1.0.0-rc00002"
'1.0.0-rc00022' | 0 | 1 | "rc" | "major" | "1.0.0-rc00023"
'0.1.0-rc00002' | 22 | 5 | "final" | "minor" | "0.1.0"
'0.1.0' | 3 | 5 | "SNAPSHOT" | "patch" | "0.1.1-master00005"
tagVersion | commitsBefore | commitsAfter | stage | scope | expectedVersion
'1.0.0' | 1 | 3 | "SNAPSHOT" | "minor" | "1.1.0-master00003"
'1.0.0' | 1 | 3 | "rc" | "minor" | "1.1.0-rc00001"
'1.0.0' | 1 | 3 | "final" | "minor" | "1.1.0"
'1.0.0' | 1 | 3 | "final" | "major" | "2.0.0"
'1.0.0-rc00001' | 10 | 5 | "rc" | "major" | "1.0.0-rc00002"
'1.0.0-rc00022' | 0 | 1 | "rc" | "major" | "1.0.0-rc00023"
'0.1.0-rc00002' | 22 | 5 | "final" | "minor" | "0.1.0"
'0.1.0' | 3 | 5 | "SNAPSHOT" | "patch" | "0.1.1-master00005"
}

@Unroll('verify version branch rename for branch #branchName')
Expand All @@ -212,7 +216,7 @@ class ReleasePluginSpec extends ProjectSpec {

and: "a history"

if(branchName != "master") {
if (branchName != "master") {
git.checkout(branch: "$branchName", startPoint: 'master', createBranch: true)
}

Expand All @@ -226,12 +230,96 @@ class ReleasePluginSpec extends ProjectSpec {
project.version.toString() == expectedVersion

where:
branchName | expectedVersion
"master" | "1.1.0-master00001"
"with/slash" | "1.1.0-branchWithSlash00001"
"numbers0123456789" | "1.1.0-branchNumbersZeroOneTwoThreeFourFiveSixSevenEightNine00001"
"with/slash" | "1.1.0-branchWithSlash00001"
"with_underscore" | "1.1.0-branchWithUnderscore00001"
"with-dash" | "1.1.0-branchWithDash00001"
branchName | expectedVersion
"master" | "1.1.0-master00001"
"with/slash" | "1.1.0-branchWithSlash00001"
"numbers0123456789" | "1.1.0-branchNumbersZeroOneTwoThreeFourFiveSixSevenEightNine00001"
"with/slash" | "1.1.0-branchWithSlash00001"
"with_underscore" | "1.1.0-branchWithUnderscore00001"
"with-dash" | "1.1.0-branchWithDash00001"
}

def createFile(String fileName, File directory) {
directory.mkdirs()
return new File(directory, fileName)
}

File createMockPaketTemplate(String id, File directory) {
def f = createFile("paket.template", directory)
f << """
type file
id $id
author wooga
""".stripIndent()
return f
}

def "configures paketPack tasks dependsOn if available"() {
given: "multiple paket.template file"
createMockPaketTemplate("Wooga.Test1", new File(projectDir, "sub1"))
createMockPaketTemplate("Wooga.Test2", new File(projectDir, "sub2"))
createMockPaketTemplate("Wooga.Test3", new File(projectDir, "sub3"))

and: "no paket pack tasks"
assert !project.tasks.withType(PaketPack)

when:
project.plugins.apply(PLUGIN_NAME)

then:
def paketPackTasks = project.tasks.withType(PaketPack)
paketPackTasks.size() == 3
paketPackTasks.every {
it.dependsOn.contains(project.tasks.getByName(wooga.gradle.release.ReleasePlugin.SETUP_TASK))
}
}

def "configures paketPack artifacts as local dependencies"() {
given: "multiple paket.template file"
createMockPaketTemplate("Wooga.Test1", new File(projectDir, "sub1"))
createMockPaketTemplate("Wooga.Test2", new File(projectDir, "sub2"))
createMockPaketTemplate("Wooga.Test3", new File(projectDir, "sub3"))

when:
project.plugins.apply(PLUGIN_NAME)
project.evaluate()

then:
Configuration archive = project.configurations.getByName(wooga.gradle.release.ReleasePlugin.ARCHIVES_CONFIGURATION)
def artifacts = archive.allArtifacts
artifacts.size() == 3
artifacts.every { it.name.contains("Wooga.Test") }
artifacts.every { it.extension == "nupkg" }
}

@Unroll
def "verify githubPublish onlyIf spec when project.status:#testState and github repository #repository"() {
given: "gradle project with plugin applied and evaluated"
project.plugins.apply(PLUGIN_NAME)
project.evaluate()

and: "configured repository branch"
if (repository) {
project.github.repository = repository
}

when:
project.status = testState

then:
def githubPublishTask = project.tasks.getByName(GithubPublishPlugin.PUBLISH_TASK_NAME)
Spec<? super Task> testSpec = githubPublishTask.getOnlyIf()
testSpec.isSatisfiedBy(githubPublishTask) == expectedResult

where:
testState | repository | expectedResult
'release' | "wooga/testRepo" | true
'release' | null | false
'candidate' | "wooga/testRepo" | true
'candidate' | null | false
'snapshot' | "wooga/testRepo" | false
'snapshot' | null | false
'random value' | "wooga/testRepo" | false
'random value' | null | false
}
}

0 comments on commit 8dbbb38

Please sign in to comment.