Skip to content

Commit 0a40b08

Browse files
committed
update things to latest.
1 parent fded7d8 commit 0a40b08

File tree

8 files changed

+80
-45
lines changed

8 files changed

+80
-45
lines changed

.github/workflows/test.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Test workflow
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
name: Test scala
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-java@v4
12+
with:
13+
distribution: 'adopt'
14+
java-version: '21'
15+
- name: Run tests
16+
run: sbt coverage test coverageReport
17+
- uses: codecov/codecov-action@v4
18+
with:
19+
fail_ci_if_error: true
20+
token: ${{ secrets.CODECOV_TOKEN }}

.travis.yml

-10
This file was deleted.

README.md

+37-7
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,55 @@
44

55
## Guide
66

7-
### Travis Setup
7+
### GitHub Actions Setup
8+
You should first get the repository upload token from [codecov](https://docs.codecov.com/docs/quick-start#step-2-get-the-repository-upload-token)
89

9-
Add to your `.travis.yml` file.
10+
Add the following to your `.github/workflows/test.yml` file.
1011
```yml
11-
language: scala
12-
after_success:
13-
- bash <(curl -s https://codecov.io/bash)
12+
name: Test workflow
13+
14+
on: [push, pull_request]
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
name: Test scala
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-java@v4
23+
with:
24+
distribution: 'adopt'
25+
java-version: '21'
26+
- name: Run tests
27+
run: sbt coverage test coverageReport
28+
- uses: codecov/codecov-action@v4
29+
with:
30+
fail_ci_if_error: true
31+
token: ${{ secrets.CODECOV_TOKEN }}
32+
```
33+
34+
Here we frist checkout the code, then setup java, run the tests and generate the coverage report. Finally, we upload the report to codecov using the codecov-action.
35+
36+
When all finished, you could also add a badge on readme like following.
37+
38+
```
39+
[![codecov](https://codecov.io/gh/YOUR_ACCOUNT/YOUR_REPO/branch/YOUR_BRANCH/graph/badge.svg)](https://codecov.io/gh/YOUR_ACCOUNT/YOUR_REPO)
1440
```
1541

1642
### Produce Coverage Reports
1743

1844
1. Add `scoverage` to plugin list
19-
- `addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")` as [seen here](https://github.com/codecov/example-scala/blob/master/project/plugins.sbt#L1)
45+
- `addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11")` as [seen here](https://github.com/codecov/example-scala/blob/master/project/plugins.sbt#L1)
2046
1. Add `coverage` and `coverageReport` to `sbt`
2147
- `sbt clean coverage test coverageReport` as [seen here](https://github.com/codecov/example-scala/blob/master/.travis.yml#L7)
2248

2349
## Caveats
2450
### Private Repo
25-
Repository tokens are required for (a) all private repos, (b) public repos not using Travis-CI, CircleCI or AppVeyor. Find your repository token at Codecov and provide via appending `-t <your upload token>` to you where you upload reports.
51+
Repository tokens are required for
52+
- (a) all private repos,
53+
- (b) public repos not using Travis-CI, CircleCI or AppVeyor.
54+
55+
Find your repository token at Codecov and provide via appending `-t <your upload token>` to you where you upload reports.
2656

2757
## Links
2858
- [Community Boards](https://community.codecov.io)

build.sbt

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
name := "scala"
1+
ThisBuild / version := "0.1.0-SNAPSHOT"
22

3-
version := "0.98.5"
3+
ThisBuild / scalaVersion := "2.13.13"
44

5-
scalaVersion := "2.10.2"
5+
lazy val root = (project in file("."))
6+
.settings(
7+
name := "example-scala",
8+
)
69

7-
crossScalaVersions := Seq("2.10.2", "2.10.3", "2.11.8")
810

911
libraryDependencies ++= Seq(
10-
"junit" % "junit" % "4.5",
11-
"org.scalatest" %% "scalatest" % "3.0.1"
12+
"org.scalatest" %% "scalatest" % "3.2.18" % Test
1213
)

project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.13
1+
sbt.version=1.9.9

project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
1+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11")
+7-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
package com.awesomeness
22

3-
class Awesomeness {
4-
def main(args: Array[String]) {
3+
object Awesome {
4+
def main(args: Array[String]): Unit = {
55
println("Hello, world! " + args.toList)
66
}
7-
def square(x:Int): Int= {
8-
x*x
9-
}
10-
def multiple(x:Int,y:Int): Int= {
11-
x*y
12-
}
13-
}
147

8+
def square(x: Int): Int = {
9+
x * x
10+
}
1511

16-
object HelloWorld {
17-
def main(args: Array[String]) {
18-
println("Hello, world! " + args.toList)
12+
def multiple(x: Int, y: Int): Int = {
13+
x * y
1914
}
2015
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.awesomeness
22

3-
import org.scalatest.junit.JUnitSuite
4-
import junit.framework.Assert._
5-
import org.junit.Test
3+
import org.scalatest.flatspec.AnyFlatSpec
4+
import org.scalatest.matchers.should
65

7-
class TestAwesome extends JUnitSuite {
8-
val awesome = new Awesomeness
6+
class TestAwesome extends AnyFlatSpec with should.Matchers {
97

10-
@ Test def awesomeExample {
11-
assertEquals(1, awesome square 1)
12-
assertEquals(6, awesome multiple (2,3))
8+
"Awesome" should "work" in {
9+
assert(Awesome.square(1) == 1)
10+
assert(Awesome.multiple(2,3) == 6)
1311
}
12+
1413
}

0 commit comments

Comments
 (0)