Skip to content

Commit

Permalink
Merge pull request #1 from adRise/chunsenwang/plugin-enhance
Browse files Browse the repository at this point in the history
plugin enhancement
  • Loading branch information
chunsenwang authored Feb 22, 2024
2 parents 2724dec + 8339516 commit 67d56d9
Show file tree
Hide file tree
Showing 23 changed files with 542 additions and 252 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set up JDK 11 # it auto caches https://github.com/actions/setup-java#caching-packages-dependencies
uses: actions/setup-java@v3.11.0
with:
java-version: '11'
distribution: 'temurin'
cache: 'sbt'

- name: Run tests
run: SBT_VERSION="${{ matrix.sbt_version }}" make test
run: sbt scalafmtAll scripted
48 changes: 48 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,51 @@ name: Publish

on:
workflow_dispatch:

# can maybe test via https://github.com/nektos/act
# act -s DOCKER_USERNAME=abc -s DOCKER_PASSWORD=xyz --container-architecture linux/arm64 -W .github/workflows/release.yml release
jobs:
release:
runs-on: ubuntu-20.04
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"

- name: Configure git user to push
run: |
git config --global user.email "sbt@tubi.tv"
git config --global user.name "sbt"
- name: Clone and checkout to current branch
uses: actions/checkout@v3.5.2
with:
fetch-depth: 0

- name: Set up JDK 11 # it auto caches https://github.com/actions/setup-java#caching-packages-dependencies
uses: actions/setup-java@v3.11.0
with:
java-version: '11'
distribution: 'temurin'
cache: 'sbt'

- name: Publish
run: ./scripts/github-actions/publish.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}

# - name: notify build status
# if: always()
# uses: slackapi/slack-github-action@v1.23.0
# with:
# # Slack channel id, channel name, or user id to post message.
# # See also: https://api.slack.com/methods/chat.postMessage#channels
# # You can pass in multiple channels to post to by providing a comma-delimited list of channel IDs.
# channel-id: ${{ github.event.repository.name }}-cicd
# # For posting a simple plain text message, no md just for link shortening
# slack-message: "${{ steps.build_info.outputs.tubi-project-name }}-v${{ steps.build_info.outputs.tubi-project-version }} release ${{ job.status }}: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
# env:
# SLACK_BOT_TOKEN: ${{ secrets.BUILD_NOTIFY_SLACK_APP_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/project/project/
/project/target/
/target/
/.idea/
/.bsp/
11 changes: 11 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version = "3.4.3"
runner.dialect = scala213
preset = IntelliJ
maxColumn = 120
docstrings.style = SpaceAsterisk
docstrings.wrap = "no"
newlines.beforeCurlyLambdaParams = multiline
rewrite.rules = [Imports]
rewrite.imports.sort = scalastyle
rewrite.imports.groups = [["sbt\\..*"], ["java\\..*", "javax\\..*"], ["scala\\..*"]]
rewrite.trailingCommas.style = keep
16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/tototoshi/sbt-slick-codegen/actions/workflows/ci.yml/badge.svg)](https://github.com/tototoshi/sbt-slick-codegen/actions/workflows/ci.yml)

slick-codegen compile hook for sbt
slick-codegen plugin, forked from [sbt-slick-codegen](https://github.com/tototoshi/sbt-slick-codegen), which aims to generate code specially for Postgres

## Install

Expand Down
69 changes: 14 additions & 55 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,69 +1,28 @@
import scalariform.formatter.preferences._
import scala.collection.JavaConverters._
import java.lang.management.ManagementFactory

enablePlugins(SbtPlugin)
import scala.collection.JavaConverters.*
//import scalariform.formatter.preferences.*

scalariformPreferences := scalariformPreferences.value
.setPreference(AlignSingleLineCaseStatements, true)
.setPreference(DoubleIndentConstructorArguments, true)
.setPreference(DanglingCloseParenthesis, Preserve)
enablePlugins(SbtPlugin)

sbtPlugin := true

name := """sbt-slick-codegen"""

organization := "com.github.tototoshi"

version := "2.0.0"

crossSbtVersions := Seq("1.8.0")

val slickVersion = SettingKey[String]("slickVersion")

slickVersion := "3.3.3"
organization := "com.tubitv"

libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % slickVersion.value,
"com.typesafe.slick" %% "slick-codegen" % slickVersion.value
"com.typesafe.slick" %% "slick" % Versions.slick,
"com.typesafe.slick" %% "slick-codegen" % Versions.slick,
"org.postgresql" % "postgresql" % Versions.postgresql,
"com.github.docker-java" % "docker-java" % Versions.dockerJava,
)
addSbtPlugin("io.github.davidmweber" % "flyway-sbt" % Versions.flywaySbt)

publishMavenStyle := true

publishTo := {
val nexus = "https://oss.sonatype.org/"
if (version.value.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
}

publishTo := Some(if (isSnapshot.value) Repo.Jfrog.Tubins.sbtDev else Repo.Jfrog.Tubins.sbtRelease)
ThisBuild / versionScheme := Some("early-semver")
Test / publishArtifact := false

pomExtra :=
<url>https://github.com/tototoshi/sbt-slick-codegen</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>git@github.com:tototoshi/sbt-slick-codegen</url>
<connection>scm:git:git@github.com:tototoshi/sbt-slick-codegen.git</connection>
</scm>
<developers>
<developer>
<id>tototoshi</id>
<name>Toshiyuki Takahashi</name>
<url>https://tototoshi.github.io</url>
</developer>
</developers>

scriptedBufferLog := false
scriptedLaunchOpts ++= ManagementFactory.getRuntimeMXBean.getInputArguments.asScala.toList.filter(a =>
Seq("-Xmx", "-Xms", "-XX", "-Dsbt.log.noformat").exists(a.startsWith)
)
scriptedLaunchOpts ++= Seq(
"-Dplugin.version=" + version.value,
"-Dslick.version=" + slickVersion.value
scriptedLaunchOpts ++= ManagementFactory.getRuntimeMXBean.getInputArguments.asScala.toList.filter(
a => Seq("-Xmx", "-Xms", "-XX", "-Dsbt.log.noformat").exists(a.startsWith)
)
scriptedLaunchOpts ++= Seq("-Dplugin.version=" + version.value, "-Dslick.version=" + Versions.slick)
17 changes: 0 additions & 17 deletions docker-compose.yml

This file was deleted.

22 changes: 22 additions & 0 deletions project/Repo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sbt.*

object Repo {

object Jfrog {
private val domain = "tubins.jfrog.io"
private val jFrogRoot = s"https://$domain"

object Tubins {
private val pathPrefix = "tubins"

lazy val sbtDev: MavenRepository = "sbt-dev" at s"$jFrogRoot/$pathPrefix/sbt-dev"

lazy val sbtRelease: MavenRepository = "sbt-release" at s"$jFrogRoot/$pathPrefix/sbt-release"

lazy val jvmSnapshot: MavenRepository = "jvm-snapshot" at s"$jFrogRoot/$pathPrefix/jvm-snapshots"

lazy val jvm: MavenRepository = "jvm-release" at s"$jFrogRoot/$pathPrefix/jvm"
}
}

}
6 changes: 6 additions & 0 deletions project/Versions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object Versions {
val slick = "3.4.0"
val postgresql = "42.6.0"
val dockerJava = "3.3.4"
val flywaySbt = "7.4.0"
}
23 changes: 23 additions & 0 deletions project/artifactory.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ThisBuild / credentials ++= {
val logger = streams.value.log
if (sys.env.contains("ARTIFACTORY_USERNAME")) {
logger.info("spotted credential in env, will add to credentials")
Some(
Credentials(
"Artifactory Realm",
"tubins.jfrog.io",
sys.env.getOrElse("ARTIFACTORY_USERNAME", ""),
sys.env.getOrElse("ARTIFACTORY_PASSWORD", "")
)
)
} else {
Credentials.loadCredentials(Path.userHome / ".artifactory" / "credentials") match {
case Right(credentials: DirectCredentials) =>
logger.info(s"Using credentials found in the home directory for host ${credentials.host}")
Some(credentials)
case Left(err: String) =>
logger.warn(s"Could not find artifactory credentials in home directory: $err")
None
}
}
}
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.18")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")

Loading

0 comments on commit 67d56d9

Please sign in to comment.