From 6f7befa40242cd3ccac598ca9e91dfc136995d84 Mon Sep 17 00:00:00 2001
From: Nico <nico.hex6@gmail.com>
Date: Thu, 18 Apr 2024 10:16:50 +0200
Subject: [PATCH] Updated build scripts

---
 .github/FUNDING.yml           |  3 +++
 .github/workflows/publish.yml | 46 +++++++++++++++++++++++++++++++++++
 .github/workflows/test.yml    | 15 ++++++++++++
 build.sbt                     | 40 +++++++++++++++++++++++++++---
 4 files changed, 100 insertions(+), 4 deletions(-)
 create mode 100644 .github/FUNDING.yml
 create mode 100644 .github/workflows/publish.yml
 create mode 100644 .github/workflows/test.yml

diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..bdb62a1
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,3 @@
+github: [HexagonNico]
+ko_fi: HexagonNico
+custom: ["https://paypal.me/hexagonnico"]
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
new file mode 100644
index 0000000..d0dcce3
--- /dev/null
+++ b/.github/workflows/publish.yml
@@ -0,0 +1,46 @@
+name: Publish
+on:
+  push:
+    tags:
+      - 'v*'
+  workflow_dispatch:
+jobs:
+  test:
+    uses: ./.github/workflows/test.yml
+  publish:
+    needs: test
+    environment: production
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+      - name: Setup JDK
+        uses: actions/setup-java@v3
+        with:
+          distribution: oracle
+          java-version: 17
+      - name: Configure GPG Key
+        env:
+          GPG_KEY: ${{ secrets.GPG_KEY }}
+        run: |
+          echo -n "$GPG_KEY" | base64 --decode | gpg --import
+      - name: Prepare environment
+        env:
+          SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
+          SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
+        run: |
+          mkdir -p ~/.sbt/1.0
+          touch ~/.sbt/1.0/sonatype.sbt
+          echo "credentials += Credentials(Path.userHome / \".sbt\" / \"sonatype_credentials\")" > ~/.sbt/1.0/sonatype.sbt
+          touch ~/.sbt/sonatype_credentials
+          echo "realm=Sonatype Nexus Repository Manager" > ~/.sbt/sonatype_credentials
+          echo "host=s01.oss.sonatype.org" >> ~/.sbt/sonatype_credentials
+          echo "user=$SONATYPE_USERNAME" >> ~/.sbt/sonatype_credentials
+          echo "password=$SONATYPE_PASSWORD" >> ~/.sbt/sonatype_credentials
+          mkdir ~/.sbt/1.0/plugins
+          touch ~/.sbt/1.0/plugins/gpg.sbt
+          echo "addSbtPlugin(\"com.github.sbt\" % \"sbt-pgp\" % \"2.1.2\")" > ~/.sbt/1.0/plugins/gpg.sbt
+      - name: Deploy
+        run: sbt publishSigned
+      - name: Message
+        run: echo "Staging repository created at https://s01.oss.sonatype.org/#stagingRepositories"
\ No newline at end of file
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..4c5df9c
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,15 @@
+name: Test
+on: [push, pull_request, workflow_call]
+jobs:
+  test:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+      - name: Setup JDK
+        uses: actions/setup-java@v3
+        with:
+          distribution: oracle
+          java-version: 17
+      - name: Build and Test
+        run: sbt compile test
\ No newline at end of file
diff --git a/build.sbt b/build.sbt
index 0aa7380..7dd84c3 100644
--- a/build.sbt
+++ b/build.sbt
@@ -1,6 +1,9 @@
 // Project info
 name := "ColorLib"
+homepage := Some(url("https://github.com/ScalaMath/ColorLib"))
 organization := "io.github.scalamath"
+organizationName := "ScalaMath"
+organizationHomepage := Some(url("https://github.com/ScalaMath"))
 version := "1.0"
 description := "A Scala library for color math"
 // Project scala version
@@ -13,8 +16,37 @@ libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.18" % Test
 // Junit test dependency
 libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.3" % Test
 
-// Needed to run Java Junit tests
-crossPaths := true
-
 // Show deprecation warnings
-scalacOptions ++= Seq("-unchecked", "-deprecation")
\ No newline at end of file
+scalacOptions ++= Seq("-unchecked", "-deprecation")
+
+// Publish info
+scmInfo := Some(
+  ScmInfo(
+    url("https://github.com/ScalaMath/ColorLib"),
+    "scm:git@github.com:ScalaMath/ColorLib.git"
+  )
+)
+
+// Developer info
+developers := List(
+  Developer(
+    id = "HexagonNico",
+    name = "Nicholas Amigoni",
+    email = "nico.hex6@gmail.com",
+    url = url("https://hexagonnico.github.io")
+  )
+)
+
+// Project license
+licenses := List(
+  "Apache 2" -> new URL("https://www.apache.org/licenses/LICENSE-2.0.txt")
+)
+
+// Maven publishing
+pomIncludeRepository := { _ => false }
+publishTo := {
+  val nexus = "https://s01.oss.sonatype.org/"
+  if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
+  else Some("releases" at nexus + "service/local/staging/deploy/maven2")
+}
+publishMavenStyle := true
\ No newline at end of file