Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GitHub Actions #68

Merged
merged 1 commit into from
Sep 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/main.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: ci
on: [push]
name: CI
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: olafurpg/setup-scala@v2
- name: Compile
run: ./bin/sbt compile


run: csbt compile
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Release
on:
push:
branches: [master]
tags:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: olafurpg/setup-scala@v2
- name: Publish
run: csbt ci-release
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

11 changes: 0 additions & 11 deletions bin/install-java.sh

This file was deleted.

7 changes: 4 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ inThisBuild(
"olafurpg@gmail.com",
url("https://geirsson.com")
)
),
resolvers += Resolver.sonatypeRepo("releases"),
scalaVersion := "2.12.8"
)
)
)

onLoadMessage := s"Welcome to sbt-ci-release ${version.value}"

skip in publish := true // don't publish the root project

lazy val plugin = project
.settings(
moduleName := "sbt-ci-release",
sbtPlugin := true,
sbtVersion in pluginCrossBuild := "1.0.4",
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.0.0"),
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0"),
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.7"),
Expand Down
22 changes: 13 additions & 9 deletions plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,29 @@ object CiReleasePlugin extends AutoPlugin {
override def requires =
JvmPlugin && SbtPgp && DynVerPlugin && GitPlugin && Sonatype

def isTravisSecure: Boolean =
System.getenv("TRAVIS_SECURE_ENV_VARS") == "true" ||
System.getenv("BUILD_REASON") == "IndividualCI" ||
System.getenv("PGP_SECRET") != null
def isTravisTag: Boolean =
Option(System.getenv("TRAVIS_TAG")).exists(_.nonEmpty) ||
Option(System.getenv("BUILD_SOURCEBRANCH"))
.orElse(Option(System.getenv("GITHUB_REF")))
.exists(_.startsWith("refs/tags"))
def isTravisSecure: Boolean =
System.getenv("TRAVIS_SECURE_ENV_VARS") == "true" ||
System.getenv("BUILD_REASON") == "IndividualCI"
def travisTag: String =
Option(System.getenv("TRAVIS_TAG"))
.orElse(Option(System.getenv("BUILD_SOURCEBRANCH")))
.orElse(Option(System.getenv("GITHUB_REF")))
.getOrElse("<unknown>")
def travisBranch: String =
Option(System.getenv("TRAVIS_BRANCH"))
.orElse(Option(System.getenv("BUILD_SOURCEBRANCH")))
.orElse(Option(System.getenv("GITHUB_REF")))
.getOrElse("<unknown>")
def isAzure: Boolean =
System.getenv("TF_BUILD") == "True"
def isGithub: Boolean =
System.getenv("GITHUB_ACTION") != null

def setupGpg(): Unit = {
val secret = sys.env("PGP_SECRET")
Expand All @@ -53,12 +59,12 @@ object CiReleasePlugin extends AutoPlugin {
}
}

override def buildSettings: Seq[Def.Setting[_]] = List(
override lazy val buildSettings: Seq[Def.Setting[_]] = List(
dynverSonatypeSnapshots := true,
pgpPassphrase := sys.env.get("PGP_PASSPHRASE").map(_.toCharArray())
)

override def globalSettings: Seq[Def.Setting[_]] = List(
override lazy val globalSettings: Seq[Def.Setting[_]] = List(
publishArtifact.in(Test) := false,
publishMavenStyle := true,
commands += Command.command("ci-release") { currentState =>
Expand All @@ -68,9 +74,7 @@ object CiReleasePlugin extends AutoPlugin {
} else {
println(
s"Running ci-release.\n" +
s" TRAVIS_SECURE_ENV_VARS=$isTravisSecure\n" +
s" TRAVIS_BRANCH=$travisBranch\n" +
s" TRAVIS_TAG=$travisTag"
s" branch=$travisBranch"
)
setupGpg()
// https://github.com/olafurpg/sbt-ci-release/issues/64
Expand Down Expand Up @@ -101,7 +105,7 @@ object CiReleasePlugin extends AutoPlugin {
}
)

override def projectSettings: Seq[Def.Setting[_]] = List(
override lazy val projectSettings: Seq[Def.Setting[_]] = List(
publishConfiguration :=
publishConfiguration.value.withOverwrite(true),
publishLocalConfiguration :=
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.2.8
sbt.version=1.3.2
7 changes: 0 additions & 7 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
unmanagedSourceDirectories.in(Compile) +=
baseDirectory.in(ThisBuild).value.getParentFile /
"plugin" / "src" / "main" / "scala"
addSbtPlugin(
"io.get-coursier" % "sbt-coursier" % coursier.util.Properties.version
)
addSbtPlugin(
"io.get-coursier" % "sbt-shading" % coursier.util.Properties.version
)
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.0.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.7")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
1 change: 0 additions & 1 deletion project/project/plugins.sbt

This file was deleted.

57 changes: 35 additions & 22 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ It's my GitHub account https://github.com/olafurpg/

### Optional: create user tokens

If you prefer not to save your actual username and password in the Travis CI settings below, generate your user tokens:
If you prefer not to save your actual username and password in the Travis CI
settings below, generate your user tokens:

- login to https://oss.sonatype.org,
- click your username in the top right, then profiles,
- in the tab that was opened, click on the top left dropdown, and select "User Token",
- click "Access User Token", and save the name and password parts of the token somewhere safe.
- in the tab that was opened, click on the top left dropdown, and select "User
Token",
- click "Access User Token", and save the name and password parts of the token
somewhere safe.

## sbt

Expand Down Expand Up @@ -109,7 +113,7 @@ this project.
gpg --gen-key
```

- For real name, use "$PROJECT_NAME bot". For example, in Scalafmt I use
- For real name, use "\$PROJECT_NAME bot". For example, in Scalafmt I use
"Scalafmt bot"
- For email, use your own email address
- For passphrase, generate a random password with a password manager
Expand All @@ -124,7 +128,9 @@ uid $PROJECT_NAME bot <$EMAIL>

Take note of `$LONG_ID`, make sure to replace this ID from the code examples
below. The ID will look something like (a)
`6E8ED79B03AD527F1B281169D28FC818985732D9` or something like (b) `A4C9 75D9 9C05 E4C7 2163 4BBD ACA8 EB32 0BFE FE2C` (in which case delete the spaces to make it look like (a)). A command like this one should do:
`6E8ED79B03AD527F1B281169D28FC818985732D9` or something like (b)
`A4C9 75D9 9C05 E4C7 2163 4BBD ACA8 EB32 0BFE FE2C` (in which case delete the
spaces to make it look like (a)). A command like this one should do:

```bash
LONG_ID=6E8ED79B03AD527F1B281169D28FC818985732D9
Expand All @@ -141,15 +147,20 @@ gpg --armor --export $LONG_ID | xclip

and post the signature to a keyserver: http://keyserver.ubuntu.com:11371/

![Ubuntu Keyserver](https://user-images.githubusercontent.com/1408093/47999702-ac7fac80-e103-11e8-95f5-868e934f90c0.png)
1. Select "Submit Key"
2. Paste in the exported public key
3. Click on "Submit
Public Key".

![Ubuntu Keyserver](https://i.imgur.com/njvOpmq.png)

## Travis

Next, open the "Settings" panel for your project on Travis CI, for example
https://travis-ci.org/scalameta/sbt-scalafmt/settings.

Make sure that "Build pushed branches" setting is enabled.
Define four secret variables
Make sure that "Build pushed branches" setting is enabled. Define four secret
variables

![](https://user-images.githubusercontent.com/1408093/41207402-bbb3970a-6d15-11e8-8772-000cc194ee92.png)

Expand All @@ -170,17 +181,21 @@ gpg --armor --export-secret-keys $LONG_ID | base64 | xclip
```

- `SONATYPE_PASSWORD`: The password you use to log into
https://oss.sonatype.org/. Alternatively, the password part of the user token if you generated one above.
If the password contains bash special characters,
https://oss.sonatype.org/. Alternatively, the password part of the user token
if you generated one above. If the password contains bash special characters,
make sure to escape it by wrapping it in single quotes `'my?pa$$word'`, see
[Travis Environment Variables](https://docs.travis-ci.com/user/environment-variables/#defining-variables-in-repository-settings).
- `SONATYPE_USERNAME`: The username you use to log into https://oss.sonatype.org/.
Alternatively, the name part of the user token if you generated one above.
- `SONATYPE_USERNAME`: The username you use to log into
https://oss.sonatype.org/. Alternatively, the name part of the user token if
you generated one above.
- (optional) `CI_RELEASE`: the command to publish all artifacts for stable
releases. Defaults to `+publishSigned` if not provided.
- (optional) `CI_SNAPSHOT_RELEASE`: the command to publish all artifacts for a
SNAPSHOT releases. Defaults to `+publish` if not provided.
- (optional) `CI_SONATYPE_RELEASE`: the command called to close and promote the staged repository. Useful when, for example, also dealing with non-sbt projects to change to `sonatypeReleaseAll`. Defaults to `sonatypeBundleRelease` if not provided.
- (optional) `CI_SONATYPE_RELEASE`: the command called to close and promote the
staged repository. Useful when, for example, also dealing with non-sbt
projects to change to `sonatypeReleaseAll`. Defaults to
`sonatypeBundleRelease` if not provided.

### .travis.yml

Expand Down Expand Up @@ -213,11 +228,9 @@ stages:
jobs:
include:
# stage="test" if no stage is specified
-
name: compile
- name: compile
script: sbt compile
-
name: formatting
- name: formatting
script: ./bin/scalafmt --test
# run ci-release only if previous stages passed
- stage: release
Expand All @@ -229,9 +242,9 @@ Notes:
- for a complete example of the Travis configuration, see the
[.travis.yml in this repository](https://github.com/olafurpg/sbt-ci-release/blob/master/.travis.yml)
- if we use `after_success` instead of build stages, we would run `ci-release`
after both `formatting` and `compile`. As long as you make sure
you don't publish the same module multiple times, you can use any Travis
configuration you like
after both `formatting` and `compile`. As long as you make sure you don't
publish the same module multiple times, you can use any Travis configuration
you like
- the `name: compile` part is optional but it makes it easy to distinguish
different jobs in the Travis UI

Expand Down Expand Up @@ -369,8 +382,8 @@ and drop the failing repository from the web UI. Alternatively, you can run
## Adopters

Below is a non-exhaustive list of projects using sbt-ci-release. Don't see your
project? [Add it in a
PR!](https://github.com/olafurpg/sbt-ci-release/edit/master/readme.md)
project?
[Add it in a PR!](https://github.com/olafurpg/sbt-ci-release/edit/master/readme.md)

- [almond-sh/almond](https://github.com/almond-sh/almond/)
- [coursier/coursier](https://github.com/coursier/coursier/)
Expand Down