Skip to content

Commit

Permalink
Merge pull request #4 from olafurpg/polish
Browse files Browse the repository at this point in the history
Refactor code and docs
  • Loading branch information
olafurpg authored Jun 12, 2018
2 parents 9f2864a + bef95d4 commit 8d83b60
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
18 changes: 6 additions & 12 deletions plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@ object CiReleasePlugin extends AutoPlugin {
def isTravisSecure: Boolean =
System.getenv("TRAVIS_SECURE_ENV_VARS") == "true"

private def env(key: String): String =
Option(System.getenv(key)).getOrElse {
throw new NoSuchElementException(s"""sys.env("$key")""")
}
def setupGpg(): Unit = {
(s"echo ${sys.env("PGP_SECRET")}" #| "base64 --decode" #| "gpg --import").!
}

override def buildSettings: Seq[Def.Setting[_]] = List(
dynverSonatypeSnapshots := true
)

def setupGpg(): Unit = {
println("Setting up gpg")
(s"echo ${env("PGP_SECRET")}" #| "base64 --decode" #| "gpg --import").!
}

override def globalSettings: Seq[Def.Setting[_]] = List(
publishMavenStyle := true,
commands += Command.command("ci-release") { s =>
Expand All @@ -40,9 +34,9 @@ object CiReleasePlugin extends AutoPlugin {
} else {
println(
s"Running ci-release.\n" +
s" TRAVIS_SECURE_ENV_VARS=${env("TRAVIS_SECURE_ENV_VARS")}\n" +
s" TRAVIS_BRANCH=${env("TRAVIS_BRANCH")}\n" +
s" TRAVIS_TAG=${env("TRAVIS_TAG")}"
s" TRAVIS_SECURE_ENV_VARS=${sys.env("TRAVIS_SECURE_ENV_VARS")}\n" +
s" TRAVIS_BRANCH=${sys.env("TRAVIS_BRANCH")}\n" +
s" TRAVIS_TAG=${sys.env("TRAVIS_TAG")}"
)
setupGpg()
if (!isTravisTag) {
Expand Down
25 changes: 24 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ Even if it takes 10 attempts to get it right, it's still worth it because it's
so nice to have automatic CI releases.


## Alternatives

There exist great alternatives to sbt-ci-release that may work better for your setup.

- [sbt-release-early](https://github.com/scalacenter/sbt-release-early): additionally supports publishing to Bintray and
other CI environments than Travis.
- [sbt-rig](https://github.com/Verizon/sbt-rig): additionally supporting publishing code
coverage reports, managing test dependencies and publishing docs.

The biggest difference between these and sbt-ci-release wrt to publishing
is the base64 encoded `PGP_SECRET` variable.
I never managed to get the encrypted files and openssl working.

## FAQ

### How do I publish sbt plugins?
Expand Down Expand Up @@ -216,7 +229,9 @@ coursier fetch com.geirsson:scalafmt-cli_2.12:1.5.0-SNAPSHOT -r sonatype:snapsho

### What about other CIs environments than Travis?

The source code for sbt-ci-release is only ~50 loc, see
You can try [sbt-release-early](https://github.com/scalacenter/sbt-release-early).

Alternatively, the source code for sbt-ci-release is only ~50 loc, see
[CiReleasePlugin.scala](https://github.com/olafurpg/sbt-ci-release/blob/master/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala).
You can copy-paste it to `project/` of your build and tweak the settings for your
environment.
Expand All @@ -240,3 +255,11 @@ NOTE. It doesn't seem possible to define this setting outside of `build.sbt`, I'
overriding `globalSettings` and `buildSettings` in auto-plugins but it doesn't work.
This setting needs to appear in every `build.sbt`.
Let me know if you find a better workaround!

### How do I disable publishing in certain projects?

Add the following to the project settings (works only in sbt 1)

```scala
skip in publish := true
```

0 comments on commit 8d83b60

Please sign in to comment.