Skip to content

Commit ffb5893

Browse files
committed
Setup build, CI, and license.
1 parent 0584aca commit ffb5893

File tree

9 files changed

+473
-0
lines changed

9 files changed

+473
-0
lines changed

.github/workflows/ci.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# This file was automatically generated by sbt-github-actions using the
2+
# githubWorkflowGenerate task. You should add and commit this file to
3+
# your git repository. It goes without saying that you shouldn't edit
4+
# this file by hand! Instead, if you wish to make changes, you should
5+
# change your sbt build configuration to revise the workflow description
6+
# to meet your needs, then regenerate this file.
7+
8+
name: Continuous Integration
9+
10+
on:
11+
pull_request:
12+
branches: [main]
13+
push:
14+
branches: [main]
15+
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
19+
jobs:
20+
build:
21+
name: Build and Test
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
os: [ubuntu-latest]
26+
scala: [2.13.11, 3.3.0]
27+
java: [temurin@8, temurin@11, temurin@17]
28+
runs-on: ${{ matrix.os }}
29+
steps:
30+
- name: Checkout current branch (full)
31+
uses: actions/checkout@v3
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Setup Java (temurin@8)
36+
if: matrix.java == 'temurin@8'
37+
uses: actions/setup-java@v3
38+
with:
39+
distribution: temurin
40+
java-version: 8
41+
cache: sbt
42+
43+
- name: Setup Java (temurin@11)
44+
if: matrix.java == 'temurin@11'
45+
uses: actions/setup-java@v3
46+
with:
47+
distribution: temurin
48+
java-version: 11
49+
cache: sbt
50+
51+
- name: Setup Java (temurin@17)
52+
if: matrix.java == 'temurin@17'
53+
uses: actions/setup-java@v3
54+
with:
55+
distribution: temurin
56+
java-version: 17
57+
cache: sbt
58+
59+
- name: Check that workflows are up to date
60+
run: sbt '++ ${{ matrix.scala }}' githubWorkflowCheck
61+
62+
- name: Build project
63+
run: sbt '++ ${{ matrix.scala }}' test
64+
65+
- name: Check binary compatibility
66+
if: matrix.java == 'temurin@8'
67+
run: sbt '++ ${{ matrix.scala }}' mimaReportBinaryIssues
68+
69+
- name: Build docs
70+
if: matrix.java == 'temurin@8'
71+
run: sbt '++ ${{ matrix.scala }}' docs/mdoc

.github/workflows/clean.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# This file was automatically generated by sbt-github-actions using the
2+
# githubWorkflowGenerate task. You should add and commit this file to
3+
# your git repository. It goes without saying that you shouldn't edit
4+
# this file by hand! Instead, if you wish to make changes, you should
5+
# change your sbt build configuration to revise the workflow description
6+
# to meet your needs, then regenerate this file.
7+
8+
name: Clean
9+
10+
on: push
11+
12+
jobs:
13+
delete-artifacts:
14+
name: Delete Artifacts
15+
runs-on: ubuntu-latest
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
steps:
19+
- name: Delete artifacts
20+
run: |
21+
# Customize those three lines with your repository and credentials:
22+
REPO=${GITHUB_API_URL}/repos/${{ github.repository }}
23+
24+
# A shortcut to call GitHub API.
25+
ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; }
26+
27+
# A temporary file which receives HTTP response headers.
28+
TMPFILE=/tmp/tmp.$$
29+
30+
# An associative array, key: artifact name, value: number of artifacts of that name.
31+
declare -A ARTCOUNT
32+
33+
# Process all artifacts on this repository, loop on returned "pages".
34+
URL=$REPO/actions/artifacts
35+
while [[ -n "$URL" ]]; do
36+
37+
# Get current page, get response headers in a temporary file.
38+
JSON=$(ghapi --dump-header $TMPFILE "$URL")
39+
40+
# Get URL of next page. Will be empty if we are at the last page.
41+
URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*<//' -e 's/>.*//')
42+
rm -f $TMPFILE
43+
44+
# Number of artifacts on this page:
45+
COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') ))
46+
47+
# Loop on all artifacts on this page.
48+
for ((i=0; $i < $COUNT; i++)); do
49+
50+
# Get name of artifact and count instances of this name.
51+
name=$(jq <<<$JSON -r ".artifacts[$i].name?")
52+
ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1))
53+
54+
id=$(jq <<<$JSON -r ".artifacts[$i].id?")
55+
size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") ))
56+
printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size
57+
ghapi -X DELETE $REPO/actions/artifacts/$id
58+
done
59+
done

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.bsp
2+
*.DS_Store
3+
target

.jvmopts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xmx2G

LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2023 BondLink, Inc.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

build.sbt

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import formless._
2+
3+
Global / onChangedBuildSource := ReloadOnSourceChanges
4+
5+
lazy val scala213 = "2.13.11"
6+
lazy val scala3 = "3.3.0"
7+
8+
ThisBuild / crossScalaVersions := Seq(scala213, scala3)
9+
ThisBuild / scalaVersion := scala3
10+
11+
// GitHub Actions config
12+
val javaVersions = Seq(8, 11, 17).map(v => JavaSpec.temurin(v.toString))
13+
14+
ThisBuild / githubWorkflowJavaVersions := javaVersions
15+
ThisBuild / githubWorkflowArtifactUpload := false
16+
ThisBuild / githubWorkflowBuildMatrixFailFast := Some(false)
17+
ThisBuild / githubWorkflowTargetBranches := Seq("main")
18+
19+
val isJava8 = s"matrix.java == '${javaVersions.find(_.version == "8").get.render}'"
20+
21+
ThisBuild / githubWorkflowBuild ++= Seq(
22+
WorkflowStep.Sbt(List("mimaReportBinaryIssues"), name = Some("Check binary compatibility"), cond = Some(isJava8)),
23+
WorkflowStep.Sbt(List("docs/mdoc"), name = Some("Build docs"), cond = Some(isJava8)),
24+
)
25+
26+
ThisBuild / githubWorkflowPublishTargetBranches := Seq()
27+
28+
def foldScalaV[A](scalaVersion: String)(_213: => A, _3: => A): A =
29+
CrossVersion.partialVersion(scalaVersion) match {
30+
case Some((2, 13)) => _213
31+
case Some((3, _)) => _3
32+
}
33+
34+
lazy val baseSettings = Seq(
35+
scalaVersion := scala3,
36+
crossScalaVersions := Seq(scala213, scala3),
37+
organization := "com.bondlink",
38+
version := "0.1.0-SNAPSHOT",
39+
resolvers += "bondlink-maven-repo" at "https://raw.githubusercontent.com/mblink/maven-repo/main",
40+
mimaPreviousArtifacts := Set(),
41+
libraryDependencies ++= foldScalaV(scalaVersion.value)(
42+
Seq(compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.2" cross CrossVersion.patch)),
43+
Seq(),
44+
),
45+
scalacOptions ++= foldScalaV(scalaVersion.value)(
46+
Seq("-Vimplicits-verbose-tree"),
47+
Seq(
48+
"-no-indent",
49+
"-Wunused:unsafe-warn-patvars",
50+
),
51+
),
52+
scalacOptions --= Seq(
53+
"-language:existentials",
54+
"-language:experimental.macros",
55+
"-language:implicitConversions"
56+
),
57+
licenses += License.Apache2,
58+
gitPublishDir := file("/src/maven-repo")
59+
)
60+
61+
lazy val noPublishSettings = Seq(
62+
publish := {},
63+
publishLocal := {},
64+
gitRelease := {},
65+
)
66+
67+
lazy val munit = Def.setting("org.scalameta" %% "munit" % "1.0.0-M8" % Test)
68+
lazy val shapeless = Def.setting("com.chuusai" %%% "shapeless" % "2.3.10")
69+
lazy val scalacheck = Def.setting("org.scalacheck" %%% "scalacheck" % "1.17.0" % Test)
70+
71+
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform).in(file("core"))
72+
.settings(baseSettings)
73+
.settings(
74+
name := "formless-core",
75+
libraryDependencies ++= Seq(munit.value, scalacheck.value),
76+
libraryDependencies ++= foldScalaV(scalaVersion.value)(
77+
Seq(
78+
shapeless.value,
79+
scalaOrganization.value % "scala-compiler" % scalaVersion.value % "provided",
80+
),
81+
Seq(),
82+
),
83+
Test / sourceGenerators += Def.task {
84+
val srcManaged = (Test / sourceManaged).value / "generated"
85+
86+
def gen(scalaF: String, generator: SourceGenerator) = {
87+
println(s"Generating ${srcManaged / scalaF} with $generator")
88+
IO.write(srcManaged / scalaF, generator())
89+
srcManaged / scalaF
90+
}
91+
92+
Seq(
93+
gen("Util.scala", SourceGenerator.Util),
94+
gen("TupleSelectorTest.scala", SourceGenerator.TupleSelectorTest),
95+
gen("RecordSelectorTest.scala", SourceGenerator.RecordSelectorTest),
96+
gen("UpdaterTest.scala", SourceGenerator.UpdaterTest),
97+
gen("ModifierTest.scala", SourceGenerator.ModifierTest),
98+
gen("RenamerTest.scala", SourceGenerator.RenamerTest),
99+
gen("RemoverTest.scala", SourceGenerator.RemoverTest),
100+
)
101+
}
102+
)
103+
104+
lazy val docs = project.in(file("formless-docs"))
105+
.settings(baseSettings)
106+
.settings(noPublishSettings)
107+
.settings(
108+
mdocOut := file("."),
109+
scalacOptions -= "-Xfatal-warnings",
110+
)
111+
.dependsOn(core.jvm)
112+
.enablePlugins(MdocPlugin)
113+
.disablePlugins(MimaPlugin)

0 commit comments

Comments
 (0)