Skip to content

Commit

Permalink
Merge pull request #1 from winitzki/feature/add_ci
Browse files Browse the repository at this point in the history
add git workflows
  • Loading branch information
winitzki authored Nov 22, 2023
2 parents 1c90593 + 6e50588 commit 000da9b
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 37 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
jobs:
build:
name: Build
needs:
- checks
runs-on: ubuntu-latest
steps:
- uses: "actions/checkout@v2"
with:
submodules: 'true'
- name: "~/.sbt\n\"~/.cache/coursier\"\n cache"
uses: "actions/cache@v3"
with:
key: "${{ runner.os }}-sbt-${{ hashFiles('build.sbt', 'project/plugins.sbt', 'project/build.properties') }}"
path: |
~/.sbt
"~/.cache/coursier"
restore-keys: |
${{ runner.os }}-sbt
- name: "java ${{ matrix.java}} setup"
uses: "actions/[email protected]"
with:
architecture: x64
java-package: jdk
java-version: "${{ matrix.java}}"
- run: "sbt -DJDK_VERSION=${{ matrix.java}} \"++${{ matrix.scala}} test\""
strategy:
matrix:
java:
- '8.0.382'
- '11.0.21'
- '17.0.9'
scala:
- '2.13.11'
checks:
name: Check formatting
runs-on: ubuntu-latest
steps:
- uses: "actions/checkout@v2"
with:
submodules: 'true'
- name: "~/.sbt\n\"~/.cache/coursier\"\n cache"
uses: "actions/cache@v3"
with:
key: "${{ runner.os }}-sbt-${{ hashFiles('build.sbt', 'project/plugins.sbt', 'project/build.properties') }}"
path: |
~/.sbt
"~/.cache/coursier"
restore-keys: |
${{ runner.os }}-sbt
- name: java 17 setup
uses: "actions/[email protected]"
with:
architecture: x64
java-package: jdk
java-version: '17'
- run: sbt scalafmtCheckAll scalafmtSbtCheck
name: scall_build_and_test
on:
push: {}
18 changes: 18 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://scalameta.org/scalafmt/docs/configuration.html
version=3.7.17 # This is the version of the scalafmt formatter core.
runner.dialect=scala213 # May need to override this for some files.
preset=IntelliJ
maxColumn = 160
align.preset=most
rewrite.trailingCommas.style = multiple
rewrite.trailingCommas.allowFolding = true
verticalMultiline.arityThreshold = 5
verticalMultiline.newlineAfterOpenParen = true
rewriteTokens = {
"⇒": "=>"
"→": "->"
"←": "<-"
}
importSelectors = singleLine
optIn.breakChainOnFirstMethodDot = false
optIn.breaksInsideChains = true
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
# sofp-solutions

Solutions for exercises in the book "Science of functional programming"

Solutions for each chapter is a submodule in this project.

Common code may be put into the `common` submodule.

# Code formatting

The GitHub job will verify that all code is properly formatted.

To reformat code, run the script:

`bash reformat_all_code.sh`

36 changes: 12 additions & 24 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ val scalaV = scala2V
val munitTest = "org.scalameta" %% "munit" % "0.7.29" % Test
def munitFramework = new TestFramework("munit.Framework")


val assertVerboseTest = "com.eed3si9n.expecty" %% "expecty" % "0.16.0" % Test

val assertVerboseTest = "com.eed3si9n.expecty" %% "expecty" % "0.16.0" % Test

lazy val root = (project in file("."))
.settings(scalaVersion := scalaV, crossScalaVersions := Seq(scalaV), name := "sofp-solutions-root")
Expand All @@ -21,10 +19,7 @@ lazy val chapter01 = (project in file("chapter01"))
Test / fork := false,
scalafmtFailOnErrors := false,
testFrameworks += munitFramework,
libraryDependencies ++= Seq(
munitTest,
assertVerboseTest,
),
libraryDependencies ++= Seq(munitTest, assertVerboseTest),
).dependsOn(common)

lazy val chapter02 = (project in file("chapter02"))
Expand All @@ -35,22 +30,15 @@ lazy val chapter02 = (project in file("chapter02"))
Test / fork := false,
scalafmtFailOnErrors := false,
testFrameworks += munitFramework,
libraryDependencies ++= Seq(
munitTest,
assertVerboseTest,
),
libraryDependencies ++= Seq(munitTest, assertVerboseTest),
).dependsOn(common)

lazy val common = (project in file("common"))
.settings(
scalaVersion := scalaV,
crossScalaVersions := Seq(scala2V, scala3V),
Test / parallelExecution := true,
Test / fork := false,
scalafmtFailOnErrors := false,
testFrameworks += munitFramework,
libraryDependencies ++= Seq(
munitTest,
assertVerboseTest,
),
)
lazy val common = (project in file("common")).settings(
scalaVersion := scalaV,
crossScalaVersions := Seq(scala2V, scala3V),
Test / parallelExecution := true,
Test / fork := false,
scalafmtFailOnErrors := false,
testFrameworks += munitFramework,
libraryDependencies ++= Seq(munitTest, assertVerboseTest),
)
13 changes: 0 additions & 13 deletions chapter01/src/test/scala/sofp/unit/Exercise1.1.scala

This file was deleted.

17 changes: 17 additions & 0 deletions chapter01/src/test/scala/sofp/unit/Exercises_1_6_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package sofp.unit

import com.eed3si9n.expecty.Expecty.expect

import munit.FunSuite

class Exercises_1_6_1 extends FunSuite {

test("exercise 1.6.1.1") {

def staggeredFactorial(n: Int): Int = (n to 1 by -2).product

expect(staggeredFactorial(8) == 384)
expect(staggeredFactorial(9) == 945)
}

}
56 changes: 56 additions & 0 deletions github-scala-build-and-test.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
let GithubActions =
https://regadas.dev/github-actions-dhall/package.dhall
sha256:71df44892a17abca817cfb35e2612d117f7fceec55114a6eb76b65a7eea4e6f4

let matrix =
toMap { java = [ "8.0.382", "11.0.21", "17.0.9" ], scala = [ "2.13.11" ] }

let setup =
[ GithubActions.steps.actions/checkout // { `with` = Some (toMap { submodules = "true" }) }
, GithubActions.steps.actions/cache
{ path =
''
~/.sbt
"~/.cache/coursier"
''
, key = "sbt"
, hashFiles =
[ "build.sbt"
, "project/plugins.sbt"
, "project/build.properties"
]
}
]

in GithubActions.Workflow::{
, name = "scall_build_and_test"
, on = GithubActions.On::{
, push = Some GithubActions.Push::{=}
--, pull_request = Some GithubActions.PullRequest::{=}
}
, jobs = toMap
{ checks = GithubActions.Job::{
, name = Some "Check formatting"
, runs-on = GithubActions.types.RunsOn.ubuntu-latest
, steps =
setup
# [ GithubActions.steps.actions/setup-java { java-version = "17" }
, GithubActions.steps.run
{ run = "sbt scalafmtCheckAll scalafmtSbtCheck" }
]
}
, build = GithubActions.Job::{
, name = Some "Build"
, needs = Some [ "checks" ]
, strategy = Some GithubActions.Strategy::{ matrix }
, runs-on = GithubActions.types.RunsOn.ubuntu-latest
, steps =
setup
# [ GithubActions.steps.actions/setup-java
{ java-version = "\${{ matrix.java}}" }
, GithubActions.steps.run
{ run = "sbt -DJDK_VERSION=\${{ matrix.java}} \"++\${{ matrix.scala}} test\"" }
]
}
}
}
1 change: 1 addition & 0 deletions reformat_all_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt scalafmtAll scalafmtSbt
1 change: 1 addition & 0 deletions update_github_actions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dhall-to-yaml --file github-scala-build-and-test.dhall > .github/workflows/build-and-test.yml

0 comments on commit 000da9b

Please sign in to comment.