Skip to content

Commit

Permalink
Use build stages
Browse files Browse the repository at this point in the history
  • Loading branch information
olafurpg committed Jun 11, 2018
1 parent f2d5db1 commit a4088f6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ language: scala
jdk:
- oraclejdk8

stages:
- name: test
- name: release
if: (branch = master AND type = push) OR (tag IS present)

jobs:
include:
- env: TEST="scalafmt"
script: ./bin/scalafmt --test
- env: TEST="compile"
script:
- sbt compile
- stage: release
script: sbt ci-release

cache:
directories:
Expand All @@ -27,6 +34,3 @@ before_cache:

before_install:
- git fetch --tags

after_success:
- sbt ci-release
31 changes: 28 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,38 @@ gpg --armor --export-secret-keys $LONG_ID | base64 | xclip
gpg key.

Next, update `.travis.yml` to trigger `ci-release` on successful merge into master and on tag push.
We use [Travis "build stages"](https://docs.travis-ci.com/user/build-stages/) to implement this.

- define `test` and `release` build stages

```yml
stages:
- name: test
- name: release
if: (branch = master AND type = push) OR (tag IS present)
```
- define your build matrix with `ci-release` at the bottom, for example:
```yml
after_success:
- sbt ci-release
jobs:
include:
# default stage is "test"
- env: TEST="compile"
script: sbt compile
- env: TEST="formatting"
script: ./bin/scalafmt --test
# run ci-release only if all previous stages passed.
- stage: release
script: sbt ci-release
```

You're good to go!
It's not necessary to use build stages.
The reason we use build stages is to prevent that `ci-release` runs multiple times in parallel jobs.
If we use for example `after_success`, we would run `ci-release` after both `TEST="formatting"` and `TEST="compile"`.
As long as you make sure you don't publish the same module multiple times, you can use any Travis configuration you like.

We're all set! Time to manually try out the new setup

- Merge a PR to your project and watch the CI release a -SNAPSHOT for your project.
- Push a tag and watch the CI release a -SNAPSHOT for your project.

Expand Down

0 comments on commit a4088f6

Please sign in to comment.