Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Commit

Permalink
Script Runnable Items Enhancements (#233)
Browse files Browse the repository at this point in the history
* Releasing new path version
* Bumps plugin version. Upgrades scala versions
* Adds some minor bug fixes
* Brings the ability to provide generic runnable items
* Upgrades scalaVersion at scripted tests
* Bumps some library versions
* Replaces scala versions literals by its val
* Reapplies setting based on sbtrelease.ReleaseStateTransformations.reapply
* Improves default settings for orgScriptTaskListSetting
* Releases 0.4.13
  • Loading branch information
juanpedromoreno authored Apr 20, 2017
1 parent 27f98cf commit 25e5004
Show file tree
Hide file tree
Showing 23 changed files with 197 additions and 88 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

## Installation

[comment]: # (Start Replace)
Add the following line to `project/plugins.sbt`:

```scala
addSbtPlugin("com.47deg" % "sbt-org-policies" % "0.4.4")
```

[comment]: # (End Replace)

[comment]: # (Start Copyright)
# Copyright

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/sbtorgpolicies/libraries.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object libraries {
"akka-http" -> "10.0.5",
"algebra" -> "0.7.0",
"alleycats" -> "0.1.9",
"aws-sdk" -> "1.11.120",
"aws-sdk" -> "1.11.121",
"base64" -> "0.2.3",
"catalysts" -> "0.0.5",
"catbird" -> "0.13.0",
Expand Down Expand Up @@ -73,7 +73,7 @@ object libraries {
"scalacheck" -> "1.13.5",
"scheckShapeless" -> "1.1.5",
"scalaj" -> "2.3.0",
"scalatest" -> "3.0.2",
"scalatest" -> "3.0.3",
"scalaz" -> "7.2.11",
"scalazspecs2" -> "0.5.0",
"scanamo" -> "0.9.2",
Expand Down
20 changes: 3 additions & 17 deletions core/src/main/scala/sbtorgpolicies/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package sbtorgpolicies

import net.jcazevedo.moultingyaml._
import sbt.Append.Value
import sbt.{url, Append, TaskKey, URL}
import sbt.{url, Append, URL}

object model {

Expand Down Expand Up @@ -119,25 +119,11 @@ object model {
</developer>
}

case class RunnableCITask(
task: TaskKey[Unit],
allModulesScope: Boolean = false,
crossScalaVersionsScope: Boolean = false)

implicit class AfterSuccessTaskOps(taskKey: TaskKey[Unit]) {

def toOrgTask: RunnableCITask = toOrgTask(allModulesScope = false, crossScalaVersionsScope = false)

def toOrgTask(allModulesScope: Boolean, crossScalaVersionsScope: Boolean): RunnableCITask =
RunnableCITask(taskKey, allModulesScope, crossScalaVersionsScope)

}

object scalac {

val `2.10`: String = "2.10.6"
val `2.11`: String = "2.11.8"
val `2.12`: String = "2.12.1"
val `2.11`: String = "2.11.11"
val `2.12`: String = "2.12.2"

val latestScalaVersion: String = `2.12`

Expand Down
34 changes: 34 additions & 0 deletions core/src/main/scala/sbtorgpolicies/runnable/model.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2017 47 Degrees, LLC. <http://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package sbtorgpolicies.runnable

import sbt._

case class RunnableItemConfigScope[T](
item: RunnableItem[T],
allModulesScope: Boolean = false,
crossScalaVersionsScope: Boolean = false)

case class SetSetting[T](setting: SettingKey[T], value: T)

sealed trait RunnableItem[T]

case class RunnableTask[T](task: TaskKey[T]) extends RunnableItem[T]

case class RunnableSetSetting[T](setSetting: SetSetting[T]) extends RunnableItem[T]

case class RunnableProcess(process: String) extends RunnableItem[Unit]
61 changes: 61 additions & 0 deletions core/src/main/scala/sbtorgpolicies/runnable/syntax.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2017 47 Degrees, LLC. <http://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package sbtorgpolicies.runnable

import sbt.TaskKey

import scala.language.implicitConversions

object syntax {

implicit def runnableTaskOpsSyntax[T](taskKey: TaskKey[T]): RunnableTaskOps[T] =
new RunnableTaskOps[T](taskKey)

implicit def runnableSetSettingOpsSyntax[T](setSetting: SetSetting[T]): RunnableSetSettingOps[T] =
new RunnableSetSettingOps[T](setSetting)

final class RunnableTaskOps[T](taskKey: TaskKey[T]) {

def asRunnableItem: RunnableItemConfigScope[T] =
asRunnableItem(allModulesScope = false, crossScalaVersionsScope = false)

def asRunnableItem(allModulesScope: Boolean, crossScalaVersionsScope: Boolean): RunnableItemConfigScope[T] =
RunnableItemConfigScope(RunnableTask(taskKey), allModulesScope, crossScalaVersionsScope)

}

final class RunnableSetSettingOps[T](setSetting: SetSetting[T]) {

def asRunnableItem: RunnableItemConfigScope[T] =
asRunnableItem(allModulesScope = false, crossScalaVersionsScope = false)

def asRunnableItem(allModulesScope: Boolean, crossScalaVersionsScope: Boolean): RunnableItemConfigScope[T] =
RunnableItemConfigScope(RunnableSetSetting(setSetting), allModulesScope, crossScalaVersionsScope)

}

final class RunnableCommandOps(command: String) {

def asRunnableItem: RunnableItemConfigScope[Unit] =
asRunnableItem(allModulesScope = false, crossScalaVersionsScope = false)

def asRunnableItem(allModulesScope: Boolean, crossScalaVersionsScope: Boolean): RunnableItemConfigScope[Unit] =
RunnableItemConfigScope(RunnableProcess(command), allModulesScope, crossScalaVersionsScope)

}

}
2 changes: 1 addition & 1 deletion project/ProjectPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object ProjectPlugin extends AutoPlugin {
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.0"),
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.15"),
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "1.8.0"),
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.6.1"),
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0"),
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.6.8"),
addSbtPlugin("com.47deg" % "sbt-dependencies" % "0.1.0"),
addSbtPlugin("com.47deg" % "sbt-microsites" % "0.5.3")
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("com.47deg" % "sbt-org-policies" % "0.4.10")
addSbtPlugin("com.47deg" % "sbt-org-policies" % "0.4.12")
libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value
9 changes: 5 additions & 4 deletions src/main/scala/sbtorgpolicies/OrgPoliciesKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package sbtorgpolicies
import sbt._
import sbtorgpolicies.github.GitHubOps
import sbtorgpolicies.model._
import sbtorgpolicies.runnable._
import sbtorgpolicies.rules.Validation
import sbtorgpolicies.templates.FileType
import sbtorgpolicies.templates.badges.BadgeBuilder
Expand All @@ -35,8 +36,8 @@ sealed trait OrgPoliciesSettingsKeys {
settingKey[Boolean](
"Defines the condition that the orgAfterCISuccess command will check before running the orgAfterCISuccessTaskListSetting list.")

val orgAfterCISuccessTaskListSetting: SettingKey[List[RunnableCITask]] =
settingKey[List[RunnableCITask]](
val orgAfterCISuccessTaskListSetting: SettingKey[List[RunnableItemConfigScope[_]]] =
settingKey[List[RunnableItemConfigScope[_]]](
"Defines the list of tasks that should be executed once the Continuous integration build has finished successfully.")

val orgBadgeListSetting: SettingKey[List[BadgeBuilder]] =
Expand Down Expand Up @@ -73,8 +74,8 @@ sealed trait OrgPoliciesSettingsKeys {
val orgProjectName: SettingKey[String] =
settingKey[String]("Name that will be used in docs. By default, the module name will be used.")

val orgScriptTaskListSetting: SettingKey[List[RunnableCITask]] =
settingKey[List[RunnableCITask]](
val orgScriptTaskListSetting: SettingKey[List[RunnableItemConfigScope[_]]] =
settingKey[List[RunnableItemConfigScope[_]]](
"Defines the list of tasks that should be executed to figure out whether the build is correct. " +
"By default, it'd be something like this: 'sbt clean coverage compile test coverageReport'")

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/sbtorgpolicies/settings/AllSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ trait AllSettings
homepage := Option(orgGithubSetting.value.homePage),
organizationHomepage := Option(orgGithubSetting.value.organizationHomePage),
startYear := Some(currentYear),
scalaOrganization := "org.typelevel",
scalaOrganization := "org.scala-lang",
scalaVersion := scalac.`2.12`,
crossScalaVersions := scalac.crossScalaVersions,
scalacOptions ++= scalacAllOptions
Expand Down
25 changes: 15 additions & 10 deletions src/main/scala/sbtorgpolicies/settings/DefaultSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ import de.heikoseeberger.sbtheader.HeaderKey.headers
import de.heikoseeberger.sbtheader.license.Apache2_0
import dependencies.DependenciesPlugin.autoImport._
import scoverage.ScoverageKeys
import scoverage.ScoverageKeys.coverageEnabled
import sbt.Keys._
import sbt._
import sbtorgpolicies.github.GitHubOps
import sbtorgpolicies.model._
import sbtorgpolicies.runnable.syntax._
import sbtorgpolicies.OrgPoliciesKeys._
import sbtorgpolicies.runnable.SetSetting
import sbtorgpolicies.templates._
import sbtorgpolicies.templates.badges._

Expand Down Expand Up @@ -83,7 +86,7 @@ trait DefaultSettings extends AllSettings {
LicenseBadge.apply(_),
GitterBadge.apply(_),
GitHubIssuesBadge.apply(_)
) ++ guard(sbtPlugin.value)(ScalaLangBadge.apply(_)),
) ++ guard(!sbtPlugin.value)(ScalaLangBadge.apply(_)),
orgEnforcedFilesSetting := List(
LicenseFileType(orgGithubSetting.value, orgLicenseSetting.value, startYear.value),
ContributingFileType(orgProjectName.value, orgGithubSetting.value),
Expand Down Expand Up @@ -115,17 +118,19 @@ trait DefaultSettings extends AllSettings {
getEnvVarOrElse("TRAVIS_PULL_REQUEST") == "false"
},
orgAfterCISuccessTaskListSetting := List(
orgCreateFiles.toOrgTask,
orgUpdateDocFiles.toOrgTask,
depUpdateDependencyIssues.toOrgTask,
orgPublishReleaseTask.toOrgTask(allModulesScope = true, crossScalaVersionsScope = true)
orgCreateFiles.asRunnableItem,
orgUpdateDocFiles.asRunnableItem,
depUpdateDependencyIssues.asRunnableItem,
orgPublishReleaseTask.asRunnableItem(allModulesScope = true, crossScalaVersionsScope = true)
),
orgScriptTaskListSetting := List(
orgValidateFiles.toOrgTask,
orgCheckSettings.toOrgTask,
(orgCompile in ThisBuild).toOrgTask(allModulesScope = true, crossScalaVersionsScope = true),
(test in Test).toOrgTask(allModulesScope = true, crossScalaVersionsScope = true),
ScoverageKeys.coverageReport.toOrgTask
orgValidateFiles.asRunnableItem,
orgCheckSettings.asRunnableItem,
(clean in Global).asRunnableItem(allModulesScope = true, crossScalaVersionsScope = true),
SetSetting(coverageEnabled in Global, true).asRunnableItem,
(compile in Compile).asRunnableItem(allModulesScope = true, crossScalaVersionsScope = true),
(test in Test).asRunnableItem(allModulesScope = true, crossScalaVersionsScope = true),
(ScoverageKeys.coverageReport in Test).asRunnableItem(allModulesScope = true, crossScalaVersionsScope = true)
)
)
}
84 changes: 51 additions & 33 deletions src/main/scala/sbtorgpolicies/settings/bash.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import sbt.Keys._
import sbt._
import sbt.complete.DefaultParsers.OptNotSpace
import sbtorgpolicies.OrgPoliciesKeys._
import sbtorgpolicies.model.{Dev, RunnableCITask}
import sbtorgpolicies.model.Dev
import sbtorgpolicies.runnable._
import sbtorgpolicies.utils._
import sbtrelease.ReleaseStateTransformations.reapply
import scoverage.ScoverageKeys

trait bash {

Expand Down Expand Up @@ -66,9 +66,9 @@ trait bash {
case (false, true) =>
st.log.info("Release Version detected, starting the release process...")

s"git checkout $orgBranch" ::
"git reset --hard HEAD" ::
"git reset --hard HEAD" ::
"git clean -f" ::
s"git checkout $orgBranch" ::
"git pull origin master" ::
"release" ::
st
Expand Down Expand Up @@ -116,7 +116,7 @@ trait bash {

private[this] def runTaskListCommand(
commandName: String,
taskListSettingKey: SettingKey[List[RunnableCITask]],
runnableItemListSettingKey: SettingKey[List[RunnableItemConfigScope[_]]],
st: State,
stateToState: (State) => State = st => st): State = {

Expand All @@ -130,46 +130,64 @@ trait bash {
val isLastScalaV = crossV.lastOption.exists(_ == scalaV)
val isRootModule = baseDir.getAbsolutePath == rootDir.getAbsolutePath

val taskList = extracted.get(taskListSettingKey)
val runnableItemList: List[RunnableItemConfigScope[_]] =
extracted
.get(runnableItemListSettingKey)
.filter { runnableItem =>
(isLastScalaV || runnableItem.crossScalaVersionsScope) && (isRootModule || runnableItem.allModulesScope)
}

val executableTasks = taskList.filter { tsk =>
(isLastScalaV || tsk.crossScalaVersionsScope) &&
(isRootModule || tsk.allModulesScope)
} map (_.task)

if (executableTasks.nonEmpty) {
if (runnableItemList.nonEmpty) {

val stateToStateResult = stateToState(st)

val newState =
if (executableTasks.exists(_.key == ScoverageKeys.coverageReport.key))
extracted
.runTask(
clean,
Project
.extract(stateToStateResult)
.append(Seq(ScoverageKeys.coverageEnabled := true), stateToStateResult))
._1
else
stateToStateResult

newState.log.info(s"[$commandName] Initiating with this set of tasks: ${toStringListTask(executableTasks)}")

executableTasks.foldLeft(newState) { (st, task) =>
Project.extract(st).runTask(task, st)._1
stateToStateResult.log.info(
s"[$commandName] Initiating with this set of items: ${toStringListRunnableItems(runnableItemList)}")

runnableItemList.foldLeft(stateToStateResult) { (currentState, item) =>
val extractedRunnable: Extracted = Project.extract(currentState)

item match {
case RunnableItemConfigScope(RunnableTask(task), true, _) =>
val ref: Reference = extractedRunnable.get(thisProjectRef)
extractedRunnable.runAggregated(task in ref, currentState)

case RunnableItemConfigScope(RunnableTask(task), _, _) =>
extractedRunnable.runTask(task, currentState)._1

case RunnableItemConfigScope(RunnableSetSetting(setSetting), _, _) =>
reapply(Seq[Setting[_]](setSetting.setting := setSetting.value), currentState)

case RunnableItemConfigScope(RunnableProcess(process), _, _) =>
process.!
currentState
}
}
} else {
st.log.info(s"[$commandName] No tasks to execute")
st.log.info(s"[$commandName] No runnable items to execute")
st
}
}

private[this] def toStringListTask[T](taskList: List[TaskKey[T]]): String =
private[this] def toStringListRunnableItems(list: List[RunnableItemConfigScope[_]]): String =
s"""
|${taskList.map(toStringTask).mkString("\n")}
|${list.map(toStringRunnableItem).mkString("\n")}
|
|""".stripMargin

private[this] def toStringTask[T](task: TaskKey[T]): String =
s"* ${task.key.label}${task.key.description map (d => s": $d") getOrElse ""}"
private[this] def toStringRunnableItem(runnableItem: RunnableItemConfigScope[_]): String = {
val (label: String, description: Option[String]) = runnableItem match {

case RunnableItemConfigScope(RunnableTask(task), _, _) =>
(task.key.label, task.key.description)

case RunnableItemConfigScope(RunnableSetSetting(setSetting), _, _) =>
(s"Setting ${setSetting.setting.key.label} to ${setSetting.value}", setSetting.setting.key.description)

case RunnableItemConfigScope(RunnableProcess(process), _, _) =>
(s"Running process $process", None)
}

s"* $label${description map (d => s": $d") getOrElse ""}"
}
}
Loading

0 comments on commit 25e5004

Please sign in to comment.