Skip to content

Commit ff71167

Browse files
authored
Setup sbt-typelevel (#295)
1 parent 9d4cb32 commit ff71167

File tree

10 files changed

+212
-100
lines changed

10 files changed

+212
-100
lines changed

.github/workflows/ci.yml

+109-20
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,116 @@
1-
name: CI
2-
on: [push, pull_request]
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+
tags: [v*]
16+
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
20+
21+
concurrency:
22+
group: ${{ github.workflow }} @ ${{ github.ref }}
23+
cancel-in-progress: true
324

425
jobs:
5-
checks:
6-
runs-on: ubuntu-latest
26+
build:
27+
name: Build and Test
28+
strategy:
29+
matrix:
30+
os: [ubuntu-latest]
31+
scala: [2.13]
32+
java: [corretto@11]
33+
runs-on: ${{ matrix.os }}
34+
timeout-minutes: 60
735
steps:
8-
- uses: actions/checkout@v2
9-
- name: Cache sbt
10-
uses: coursier/cache-action@v5
11-
- name: Java 11 setup
12-
uses: olafurpg/setup-scala@v10
36+
- name: Checkout current branch (full)
37+
uses: actions/checkout@v4
1338
with:
14-
java-version: 1.11.0
15-
- run: sbt scalafmtCheckAll scalafmtSbtCheck
39+
fetch-depth: 0
40+
41+
- name: Setup Java (corretto@11)
42+
id: setup-java-corretto-11
43+
if: matrix.java == 'corretto@11'
44+
uses: actions/setup-java@v4
45+
with:
46+
distribution: corretto
47+
java-version: 11
48+
cache: sbt
49+
50+
- name: sbt update
51+
if: matrix.java == 'corretto@11' && steps.setup-java-corretto-11.outputs.cache-hit == 'false'
52+
run: sbt +update
53+
54+
- name: Check that workflows are up to date
55+
run: sbt githubWorkflowCheck
56+
57+
- name: Test
58+
run: sbt '++ ${{ matrix.scala }}' test runPluginVerifier packageArtifact
59+
60+
- name: Make target directories
61+
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
62+
run: mkdir -p target project/target
1663

17-
test:
18-
runs-on: ubuntu-latest
64+
- name: Compress target directories
65+
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
66+
run: tar cf targets.tar target project/target
67+
68+
- name: Upload target directories
69+
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}
73+
path: targets.tar
74+
75+
publish:
76+
name: Publish Artifacts
77+
needs: [build]
78+
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
79+
strategy:
80+
matrix:
81+
os: [ubuntu-latest]
82+
java: [corretto@11]
83+
runs-on: ${{ matrix.os }}
1984
steps:
20-
- uses: actions/checkout@v2
21-
- name: Cache sbt
22-
uses: coursier/cache-action@v5
23-
- name: Java 11 setup
24-
uses: olafurpg/setup-scala@v10
85+
- name: Checkout current branch (full)
86+
uses: actions/checkout@v4
87+
with:
88+
fetch-depth: 0
89+
90+
- name: Setup Java (corretto@11)
91+
id: setup-java-corretto-11
92+
if: matrix.java == 'corretto@11'
93+
uses: actions/setup-java@v4
2594
with:
26-
java-version: 1.11.0
27-
- run: sbt test packageArtifact
95+
distribution: corretto
96+
java-version: 11
97+
cache: sbt
98+
99+
- name: sbt update
100+
if: matrix.java == 'corretto@11' && steps.setup-java-corretto-11.outputs.cache-hit == 'false'
101+
run: sbt +update
102+
103+
- name: Download target directories (2.13)
104+
uses: actions/download-artifact@v4
105+
with:
106+
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13
107+
108+
- name: Inflate target directories (2.13)
109+
run: |
110+
tar xf targets.tar
111+
rm targets.tar
112+
113+
- name: Publish
114+
env:
115+
IJ_PLUGIN_REPO_TOKEN: ${{ secrets.IJ_PLUGIN_TOKEN }}
116+
run: sbt packageArtifactZip publishPlugin

.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

.github/workflows/release.yml

-29
This file was deleted.

RELEASE.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
Scio-idea-plugin uses [sbt-idea-plugin](https://github.com/JetBrains/sbt-idea-plugin) to publish plugin updates to JetBrains.
44

5-
1. Bump the version in `version.sbt` and `src/main/resources/META-INF/plugin.xml`, and push to main.
6-
2. Push a new tag with the updated version:
5+
1. Push a new tag with the updated version:
76
```shell
87
git tag -a X.Y.Z -m "X.Y.Z"
98

109
git push origin X.Y.Z
1110
```
12-
3. GitHub actions will verify and publish to JetBrains. Verify that your plugin was updated [here](https://plugins.jetbrains.com/plugin/8596-scio-idea/versions).
13-
4. Create a release from the new tag at https://github.com/spotify/scio-idea-plugin/tags.
11+
2. GitHub actions will verify and publish to JetBrains. Verify that your plugin was updated [here](https://plugins.jetbrains.com/plugin/8596-scio-idea/versions).
12+
3. Create a release from the new tag at https://github.com/spotify/scio-idea-plugin/tags.

build.sbt

+37-38
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,58 @@
1515
* under the License.
1616
*/
1717

18+
disablePlugins(TypelevelCiSigningPlugin)
19+
1820
lazy val Guava = "com.google.guava" % "guava" % "32.1.3-jre"
1921
lazy val Scalatest = "org.scalatest" %% "scalatest" % "3.2.18"
2022

21-
lazy val commonSettings = Def.settings(
22-
scalaVersion := "2.13.12",
23-
scalacOptions ++= Seq(
24-
"-deprecation",
25-
"-encoding",
26-
"utf-8",
27-
"-explaintypes",
28-
"-feature",
29-
"-Xcheckinit",
30-
"-Xfatal-warnings",
31-
"-Xlint:adapted-args",
32-
"-Xlint:constant",
33-
"-Xlint:delayedinit-select",
34-
"-Xlint:doc-detached",
35-
"-Xlint:inaccessible",
36-
"-Xlint:infer-any",
37-
"-Xlint:missing-interpolator",
38-
"-Xlint:nullary-unit",
39-
"-Xlint:option-implicit",
40-
"-Xlint:package-object-classes",
41-
"-Xlint:poly-implicit-overload",
42-
"-Xlint:private-shadow",
43-
"-Xlint:stars-align",
44-
"-Xlint:type-parameter-shadow"
23+
24+
// project
25+
ThisBuild / tlBaseVersion := "0.1"
26+
ThisBuild / scalaVersion := "2.13.12"
27+
ThisBuild / githubWorkflowTargetBranches := Seq("main")
28+
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.corretto("11"))
29+
ThisBuild / tlJdkRelease := Some(8)
30+
ThisBuild / tlFatalWarnings := true
31+
ThisBuild / tlCiHeaderCheck := true
32+
ThisBuild / tlCiScalafmtCheck := true
33+
ThisBuild / tlCiDocCheck := false
34+
ThisBuild / tlCiMimaBinaryIssueCheck := false
35+
ThisBuild / tlCiDependencyGraphJob := false
36+
ThisBuild / githubWorkflowBuild := Seq(
37+
WorkflowStep.Sbt(
38+
name = Some("Test"),
39+
commands = List("test", "runPluginVerifier", "packageArtifact")
40+
),
41+
)
42+
ThisBuild / githubWorkflowPublish := Seq(
43+
WorkflowStep.Sbt(
44+
name = Some("Publish"),
45+
commands = List("packageArtifactZip", "publishPlugin"),
46+
env = Map("IJ_PLUGIN_REPO_TOKEN" -> "${{ secrets.IJ_PLUGIN_TOKEN }}")
4547
)
4648
)
4749

50+
// idea settings
51+
ThisBuild / intellijPluginName := "scio-idea"
52+
ThisBuild / intellijPlatform := IntelliJPlatform.IdeaCommunity
53+
ThisBuild / intellijBuild := "232.10072.27"
54+
4855
// Avoid racing doPatchPluginXml against packageMappings
4956
packageArtifact := {
5057
packageArtifact dependsOn Def.sequential(packageMappings, doPatchPluginXml)
5158
}.value
5259

53-
lazy val ideaSettings = Def.settings(
54-
ThisBuild / intellijPluginName := "scio-idea",
55-
ThisBuild / intellijPlatform := IntelliJPlatform.IdeaCommunity,
56-
ThisBuild / intellijBuild := "232.10072.27",
57-
intellijPlugins += "org.intellij.scala".toPlugin,
58-
patchPluginXml := pluginXmlOptions { xml =>
59-
xml.version = version.value
60-
}
61-
)
62-
6360
lazy val scioIdeaPlugin: Project = project
6461
.in(file("."))
65-
.settings(commonSettings)
66-
.settings(ideaSettings)
62+
.enablePlugins(SbtIdeaPlugin)
6763
.settings(
6864
libraryDependencies ++= Seq(
6965
Guava,
7066
Scalatest % Test
71-
)
67+
),
68+
intellijPlugins += "org.intellij.scala".toPlugin,
69+
patchPluginXml := pluginXmlOptions { xml =>
70+
xml.version = version.value
71+
}
7272
)
73-
.enablePlugins(SbtIdeaPlugin)

project/plugins.sbt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
addSbtPlugin("org.jetbrains" % "sbt-idea-plugin" % "3.20.6")
22
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
3+
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.6.5")

src/main/scala/com/spotify/scio/AnnotationTypeInjector.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ package com.spotify.scio
1919

2020
import java.io.File
2121
import java.nio.charset.Charset
22-
import java.nio.file.{Files => JFiles, Paths}
23-
22+
import java.nio.file.{Paths, Files as JFiles}
2423
import com.google.common.base.Charsets
2524
import com.google.common.hash.Hashing
2625
import com.google.common.io.Files
@@ -30,6 +29,7 @@ import com.intellij.psi.PsiElement
3029
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass
3130
import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.SyntheticMembersInjector
3231

32+
import scala.annotation.nowarn
3333
import scala.collection.mutable
3434

3535
object AnnotationTypeInjector {
@@ -42,7 +42,7 @@ object AnnotationTypeInjector {
4242
getConstructorProps(caseClasses).props
4343

4444
def getConstructorProps(caseClasses: String): ConstructorProps = {
45-
val CaseClassArgs(params) = caseClasses
45+
val CaseClassArgs(params) = caseClasses: @nowarn
4646
ConstructorProps(TypeArg.findAllIn(params).toSeq)
4747
}
4848

src/main/scala/com/spotify/scio/AvroTypeInjector.scala

-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717

1818
package com.spotify.scio
1919

20-
import com.intellij.openapi.diagnostic.Logger
2120
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScTypeDefinition}
2221

2322
object AvroTypeInjector {
24-
private val Log = Logger.getInstance(classOf[AvroTypeInjector])
25-
2623
private val AvroTNamespace = "AvroType"
2724
private val AvroAnnotations = Seq(
2825
s"$AvroTNamespace.fromSchema",

src/main/scala/com/spotify/scio/BigQueryTypeInjector.scala

-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ package com.spotify.scio
1919

2020
import com.intellij.openapi.diagnostic.Logger
2121
import org.jetbrains.plugins.scala.lang.psi.api.base.ScLiteral
22-
import org.jetbrains.plugins.scala.lang.psi.api.base.literals.{ScBooleanLiteral, ScIntegerLiteral}
2322
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScTypeDefinition}
24-
import org.jetbrains.plugins.scala.lang.psi.impl.base.literals.ScIntegerLiteralImpl
2523

2624
object BigQueryTypeInjector {
2725
private val Log = Logger.getInstance(classOf[BigQueryTypeInjector])

version.sbt

-1
This file was deleted.

0 commit comments

Comments
 (0)