Skip to content

Instantly share code, notes, and snippets.

@everson
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everson/d9c9b08a761b4a3ae3db to your computer and use it in GitHub Desktop.
Save everson/d9c9b08a761b4a3ae3db to your computer and use it in GitHub Desktop.
#!/bin/sh
exec scala "$0" "$@"
!#
/*
* Copyright (c) 2011-15 Miles Sabin
*
* 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.
*/
import scala.io.Source
import scala.util.{Failure, Success, Try}
import sys.process._
import scala.io.StdIn._
object CrossBranchRelease {
def main(args: Array[String]): Unit = {
val result = (for {
_ <- release("master")
_ <- release("scala-2.10.x")
} yield {
"completed"
}) match {
case Success(msg) => msg
case Failure(e) => e.getMessage
}
println(result)
}
def run(cmd: String): Try[String] = Try {
print(cmd + "... ")
cmd.!!
}
def readVersion() = Try {
val str = Source.fromFile("version.sbt").mkString
val VersionR = "version in ThisBuild := \"(.*)\"\\s?".r
str match {
case VersionR(v) => v
}
}
def confirm(question: String) = Try {
println(question)
val answer = readBoolean()
if(!answer)
sys.error("Aborted by user!")
}
def release(branch: String): Try[String] = {
for {
_ <- run(s"git checkout $branch")
v <- readVersion()
a1 <- confirm(s"Do you want to publish version $v from branch $branch? yes/no")
_ <- run("sbt clean compile publish-local")
} yield {
v
}
}
}
CrossBranchRelease.main(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment