Skip to content

Commit 9a89e66

Browse files
authored
Scala 3 or 2.13 options (#2)
1 parent 8a96ec2 commit 9a89e66

File tree

8 files changed

+182
-8
lines changed

8 files changed

+182
-8
lines changed

.github/workflows/ci-scala-213.yml

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: CI (Scala 2.13)
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
workflow_dispatch: # enable manual execution
9+
10+
env:
11+
G8_PARAM_GITHUB_ORG: "octo-org"
12+
G8_PARAM_REPO_NAME: "simple-scala-cli"
13+
G8_PARAM_DEFAULT_BRANCH: "master"
14+
15+
concurrency:
16+
group: ${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
21+
generate-project:
22+
name: Generate project
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 5
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Generate project
28+
run: |
29+
sbt new file://../simple-scala-cli.g8 \
30+
--use_scala_3=false \
31+
--name="${G8_PARAM_REPO_NAME}" \
32+
--github_org="${G8_PARAM_GITHUB_ORG}" \
33+
--default_branch="${G8_PARAM_DEFAULT_BRANCH}"
34+
- name: Cache generated project
35+
uses: actions/cache@v4
36+
with:
37+
path: ${{ env.G8_PARAM_REPO_NAME }}
38+
key: ${{ github.sha }}
39+
40+
gh-workflows-check:
41+
name: GitHub workflows check
42+
needs: generate-project
43+
runs-on: ubuntu-latest
44+
timeout-minutes: 2
45+
steps:
46+
- uses: actions/checkout@v4
47+
- name: Get cached generated project
48+
uses: actions/cache@v4
49+
with:
50+
path: ${{ env.G8_PARAM_REPO_NAME }}
51+
key: ${{ github.sha }}
52+
- name: Setup act
53+
uses: actionsflow/setup-act@v1
54+
- name: GitHub workflows check
55+
env:
56+
ACT_PLATFORM: "ubuntu-latest=catthehacker/ubuntu:act-latest"
57+
run: |
58+
cd "${G8_PARAM_REPO_NAME}"
59+
ls ".github/workflows" | \
60+
xargs -n 1 -I ^ act --dryrun --platform "${ACT_PLATFORM}" -W ".github/workflows/^"
61+
62+
scalafmt-check:
63+
name: Scalafmt check
64+
needs: generate-project
65+
runs-on: ubuntu-latest
66+
timeout-minutes: 1
67+
steps:
68+
- name: Get cached generated project
69+
uses: actions/cache@v4
70+
with:
71+
path: ${{ env.G8_PARAM_REPO_NAME }}
72+
key: ${{ github.sha }}
73+
- uses: coursier/cache-action@v6
74+
- uses: VirtusLab/scala-cli-setup@v1
75+
- name: Scalafmt check
76+
run: |
77+
cd "${G8_PARAM_REPO_NAME}"
78+
scala-cli fmt --check . || (
79+
echo "To format code run"
80+
echo " scala-cli fmt ."
81+
exit 1
82+
)
83+
84+
scala-cli-tests:
85+
name: Run tests
86+
needs: generate-project
87+
runs-on: ubuntu-latest
88+
timeout-minutes: 2
89+
steps:
90+
- name: Get cached generated project
91+
uses: actions/cache@v4
92+
with:
93+
path: ${{ env.G8_PARAM_REPO_NAME }}
94+
key: ${{ github.sha }}
95+
- uses: coursier/cache-action@v6
96+
- uses: VirtusLab/scala-cli-setup@v1
97+
- name: Run tests
98+
run: |
99+
cd "${G8_PARAM_REPO_NAME}"
100+
scala-cli test .
101+
102+
upload-generated-project:
103+
name: Upload generated project
104+
if: github.ref == 'refs/heads/master'
105+
needs: [ gh-workflows-check, scalafmt-check, scala-cli-tests ]
106+
runs-on: ubuntu-latest
107+
timeout-minutes: 1
108+
steps:
109+
- name: Get cached generated project
110+
uses: actions/cache@v4
111+
with:
112+
path: ${{ env.G8_PARAM_REPO_NAME }}
113+
key: ${{ github.sha }}
114+
- name: Upload generated project
115+
uses: actions/upload-artifact@v4
116+
with:
117+
name: ${{ env.G8_PARAM_REPO_NAME }}-scala213
118+
path: |
119+
${{ env.G8_PARAM_REPO_NAME }}/
120+
!${{ env.G8_PARAM_REPO_NAME }}/.bsp
121+
!${{ env.G8_PARAM_REPO_NAME }}/.scala-build
122+
if-no-files-found: error
123+
retention-days: 5

.github/workflows/ci.yml .github/workflows/ci-scala-3.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: CI (Scala 3)
22

33
on:
44
push:
@@ -27,6 +27,7 @@ jobs:
2727
- name: Generate project
2828
run: |
2929
sbt new file://../simple-scala-cli.g8 \
30+
--use_scala_3=true \
3031
--name="${G8_PARAM_REPO_NAME}" \
3132
--github_org="${G8_PARAM_GITHUB_ORG}" \
3233
--default_branch="${G8_PARAM_DEFAULT_BRANCH}"
@@ -113,7 +114,7 @@ jobs:
113114
- name: Upload generated project
114115
uses: actions/upload-artifact@v4
115116
with:
116-
name: ${{ env.G8_PARAM_REPO_NAME }}
117+
name: ${{ env.G8_PARAM_REPO_NAME }}-scala3
117118
path: |
118119
${{ env.G8_PARAM_REPO_NAME }}/
119120
!${{ env.G8_PARAM_REPO_NAME }}/.bsp

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Simple Scala-CLI template
22

3-
[![CI](https://github.com/horothesun/simple-scala-cli.g8/actions/workflows/ci.yml/badge.svg)](https://github.com/horothesun/simple-scala-cli.g8/actions/workflows/ci.yml)
4-
[![Scala](https://img.shields.io/badge/Scala-3-%23DC322F?style=flat&labelColor=%23383838&logo=Scala&logoColor=%23DC322F&logoWidth=12&cacheSeconds=3600)](https://www.scala-lang.org/)
3+
[![CI (Scala 3)](https://github.com/horothesun/simple-scala-cli.g8/actions/workflows/ci-scala-3.yml/badge.svg)](https://github.com/horothesun/simple-scala-cli.g8/actions/workflows/ci-scala-3.yml)
4+
[![CI (Scala 2.13)](https://github.com/horothesun/simple-scala-cli.g8/actions/workflows/ci-scala-213.yml/badge.svg)](https://github.com/horothesun/simple-scala-cli.g8/actions/workflows/ci-scala-213.yml)
5+
[![Scala](https://img.shields.io/badge/Scala-3%20%2F%202.13-%23DC322F?style=flat&labelColor=%23383838&logo=Scala&logoColor=%23DC322F&logoWidth=12&cacheSeconds=3600)](https://www.scala-lang.org/)
56
[![CE3](https://img.shields.io/badge/Cats%20Effect-3-%23DC322F?style=flat&labelColor=%23383838&logo=Scala&logoColor=%23DC322F&logoWidth=12&cacheSeconds=3600)](https://typelevel.org/cats-effect/)
67

78
Giter8 template to generate a simple Scala-CLI project.

src/main/g8/.scalafmt.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
version = 3.8.2
2-
runner.dialect = scala3
2+
runner.dialect = scala$if(use_scala_3.truthy)$3$else$213$endif$
33
align.preset = some
44
align.arrowEnumeratorGenerator = true
55
align.openParenCallSite = true

src/main/g8/Main.scala

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
$if(use_scala_3.truthy)$
12
//> using scala 3.4.2
3+
$else$
4+
//> using scala 2.13.14
5+
$endif$
26
//> using jvm temurin:21
37

48
//> using dep org.typelevel::cats-core:2.12.0
@@ -15,7 +19,15 @@
1519
//> using test.dep org.typelevel::cats-effect-testkit:3.5.4
1620
//> using test.dep org.typelevel::discipline-munit:2.0.0
1721

22+
$if(use_scala_3.truthy)$
1823
import cats.effect.*
1924

2025
object Main extends IOApp.Simple:
2126
def run: IO[Unit] = IO.println("Hello!")
27+
$else$
28+
import cats.effect._
29+
30+
object Main extends IOApp.Simple {
31+
def run: IO[Unit] = IO.println("Hello!")
32+
}
33+
$endif$

src/main/g8/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# $name$
22

33
[![CI](https://github.com/$github_org$/$repo_name$/actions/workflows/ci.yml/badge.svg)](https://github.com/$github_org$/$repo_name$/actions/workflows/ci.yml)
4-
[![Scala](https://img.shields.io/badge/Scala-3-%23DC322F?style=flat&labelColor=%23383838&logo=Scala&logoColor=%23DC322F&logoWidth=12&cacheSeconds=3600)](https://www.scala-lang.org/)
4+
[![Scala](https://img.shields.io/badge/Scala-$if(use_scala_3.truthy)$3$else$2.13$endif$-%23DC322F?style=flat&labelColor=%23383838&logo=Scala&logoColor=%23DC322F&logoWidth=12&cacheSeconds=3600)](https://www.scala-lang.org/)
55

66
## Setup
77

src/main/g8/Unit.test.scala

+38-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
1-
import munit.FunSuite
1+
$if(use_scala_3.truthy)$
2+
import UnitSuite.*
3+
import munit.ScalaCheckSuite
4+
import org.scalacheck.Gen
5+
import org.scalacheck.Prop.forAll
26

3-
class UnitSuite extends FunSuite:
7+
class UnitSuite extends ScalaCheckSuite:
48

59
test("1+1 is 2") {
610
assertEquals(1 + 1, 2)
711
}
12+
13+
property("lists always have >= 0 elements") {
14+
forAll(listGen(Gen.alphaChar))(cs => assert(cs.length >= 0))
15+
}
16+
17+
object UnitSuite:
18+
19+
def listGen[A](aGen: Gen[A]): Gen[List[A]] = Gen.listOf(aGen)
20+
$else$
21+
import UnitSuite._
22+
import munit.ScalaCheckSuite
23+
import org.scalacheck.Gen
24+
import org.scalacheck.Prop.forAll
25+
26+
class UnitSuite extends ScalaCheckSuite {
27+
28+
test("1+1 is 2") {
29+
assertEquals(1 + 1, 2)
30+
}
31+
32+
property("lists always have >= 0 elements") {
33+
forAll(listGen(Gen.alphaChar))(cs => assert(cs.length >= 0))
34+
}
35+
36+
}
37+
38+
object UnitSuite {
39+
40+
def listGen[A](aGen: Gen[A]): Gen[List[A]] = Gen.listOf(aGen)
41+
42+
}
43+
$endif$

src/main/g8/default.properties

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use_scala_3=true
12
name=Simple Scala CLI
23
description=Simple Scala CLI Giter8 template.
34
github_org=octo-org

0 commit comments

Comments
 (0)