Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions .github/workflows/native.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
name: Native
on:
push:
branches: ["main"]
tags: ["v*"]
pull_request:
branches: ["*"]

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
macos_build:
name: MacOS (${{ matrix.OS }})
strategy:
fail-fast: true
matrix:
OS: ["macos-15", "macos-15-intel"]
runs-on: ${{ matrix.OS }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin

- uses: sbt/setup-sbt@v1

- uses: coursier/cache-action@v6

- name: Build the binary
run: |
sbt buildBinaryPlatformRelease

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
path: out/release/*
name: ${{ matrix.os }}-binaries
if-no-files-found: error

linux_build:
name: Linux (${{ matrix.OS }})
strategy:
fail-fast: true
matrix:
OS: ["ubuntu-22.04", "ubuntu-22.04-arm"]
runs-on: ${{ matrix.OS }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "21"

- uses: sbt/setup-sbt@v1

- uses: coursier/cache-action@v6

- name: Build the binary
run: |
sudo apt-get install libcurl4-openssl-dev libidn2-dev
sbt buildBinaryPlatformRelease

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
path: out/release/*
name: ${{ matrix.os }}-binaries
if-no-files-found: error

windows_build:
name: Windows
strategy:
fail-fast: false
runs-on: windows-2022
env:
LLVM_BIN: 'C:\Program Files\LLVM\bin'
LLVM_VERSION: "20.1.0"
steps:
# This step is important to make sure scalafmt
# checks don't fail
- name: Setup git config
run: git config --global core.autocrlf false

# - uses: actions/checkout@v4

# - uses: actions/setup-java@v4
# with:
# distribution: "temurin"
# java-version: "21"

# - uses: coursier/cache-action@v6

# - uses: sbt/setup-sbt@v1

# - name: Cache SBT
# uses: actions/cache@v5
# with:
# path: |
# %LocalAppData%\sbt\v2
# key: ${{ runner.os }}-sbt2

# - name: Build the binary
# run: |
# sbt buildBinaryPlatformRelease

# - name: Upload artifacts
# uses: actions/upload-artifact@v4
# with:
# path: out/release/*
# name: windows-binaries
# if-no-files-found: error
#
publish:
if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main'
needs: [linux_build]
name: Publish to Maven Central
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin

- uses: sbt/setup-sbt@v1

- uses: coursier/cache-action@v6

- name: Publish to Maven
run: sbt ci-release
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}

release:
if: startsWith(github.ref, 'refs/tags/v')
needs: [linux_build, windows_build, macos_build]
name: Upload binaries to release
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download binaries
uses: actions/download-artifact@v4
id: download
with:
path: binaries

- name: List downloaded binaries
run: ls -R binaries

- name: Upload release binaries
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: "${{steps.download.outputs.download-path}}/**/*"

mergify-build-checkpoint:
runs-on: ubuntu-latest
needs: [linux_build, windows_build, macos_build]
steps:
- name: I only exist to please Mergify :(
run: echo "It's a sad existence but necessary"
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.5.9"
version = "3.10.6"
runner.dialect = scala3
fileOverride {
"glob:**/scaladex/src/**" {
Expand Down
73 changes: 48 additions & 25 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,55 @@ import org.scalajs.linker.interface.StandardConfig
enablePlugins(ScalaJSPlugin)
enablePlugins(NpmPackagePlugin)

name := "dexsearch"
version := "0.1.5"
// name := "dexsearch"
// version := "0.1.5"

scalaVersion := "3.2.1" // or any other Scala version >= 2.11.12

libraryDependencies ++= Seq(
"com.monovore" %%% "decline-effect" % "2.4.1"
)

// This is an application with a main method
scalaJSUseMainModuleInitializer := true
Compile / scalaJSLinkerConfig := {
val c = scalaJSLinkerConfig.value
c.withModuleKind(ModuleKind.ESModule).withJSHeader("#!/usr/bin/env node\n")
lazy val Versions = new {
val Scala = "3.9.0-RC1"
}
licenses := Seq(License.Apache2)

npmPackageAuthor := "Neandertech"
npmPackageDescription := "CLI that uses the Scaladex API to quickly search libraries and copy them to the clipboard"
npmPackageName := "dexsearch"
npmPackageNpmrcScope := Some("neandertech")
npmPackageBinaryEnable := true
npmPackageDependencies ++= {
Seq(
"node-fetch" -> "^2.6.1",
"prompts" -> "^2.4.2",
"clipboardy" -> "^3.0.0"
lazy val root = project.in(file(".")).aggregate(dexsearch.projectRefs *)

lazy val dexsearch = projectMatrix
.in(file("cli"))
.nativePlatform(
Seq(Versions.Scala),
Seq.empty,
_.enablePlugins(ForgeNativeBinaryPlugin).settings(
Seq(
libraryDependencies += "com.softwaremill.sttp.client4" %%% "core" % "4.0.25",
libraryDependencies += "com.softwaremill.sttp.client4" %%% "upickle" % "4.0.25"
)
)
)
}
.jsPlatform(
Seq(Versions.Scala),
Seq.empty,
_.enablePlugins(ScalaJSPlugin, NpmPackagePlugin).settings(
scalaJSUseMainModuleInitializer := true,
Compile / scalaJSLinkerConfig := {
val c = scalaJSLinkerConfig.value
c.withModuleKind(ModuleKind.ESModule)
.withJSHeader("#!/usr/bin/env node\n")
},
npmPackageAuthor := "Neandertech",
npmPackageDescription := "CLI that uses the Scaladex API to quickly search libraries and copy them to the clipboard",
npmPackageName := "dexsearch",
npmPackageNpmrcScope := Some("neandertech"),
npmPackageBinaryEnable := true,
npmPackageDependencies ++= {
Seq(
"node-fetch" -> "3.3.2",
"clipboardy" -> "5.3.1"
)
}
)
)
.settings(
libraryDependencies ++= Seq(
"com.monovore" %%% "decline-effect" % "2.6.2",
"tech.neander" %%% "cue4s-cats-effect" % "0.0.13"
)
)

inThisBuild(List(licenses := Seq(License.Apache2)))
8 changes: 8 additions & 0 deletions cli/src/main/scala/dex/Clipboard.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dex

import cats.effect.IO

trait Clipboard:
def copyToClipboard(lines: Seq[String]): IO[Unit]

object Clipboard extends ClipboardPlatform
File renamed without changes.
26 changes: 26 additions & 0 deletions cli/src/main/scala/dex/Scaladex.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dex

import cats.effect.IO

trait Scaladex:
protected val target = "JVM"
protected val scalaVersion = "2.13"

def search(name: String): IO[Array[Project]]
def project(org: String, repo: String): IO[ProjectDetails]

object Scaladex extends ScaladexPlatform


case class Project(
organization: String,
repository: String,
artifacts: Array[String]
)

case class ProjectDetails(
groupId: String,
version: String,
artifacts: Array[String],
versions: Array[String]
)
66 changes: 66 additions & 0 deletions cli/src/main/scala/dex/main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package dex

import scala.util.Success
import scala.util.Failure
import com.monovore.decline.CommandApp
import com.monovore.decline.Opts
import cats.syntax.all._
import com.monovore.decline.effect.CommandIOApp
import cats.effect.IO
import cats.effect.ExitCode
import cue4s.catseffect.PromptsIO
import cue4s.CompletionError

object Main
extends CommandIOApp("dex", "searches scaladex for Scala libraries"):

val doneMessage = "Dependencies were copied to your clipboard, ready to paste"

def main = (BuildTool.opt, LibName.argument).mapN {
(maybeBuildTool, maybeLibName) =>
Clipboard.copyToClipboard(Seq("hello", "poopoo")) *>
PromptsIO.make
.use: prompts =>
for
libName <- maybeLibName
.map(IO.pure(_))
.getOrElse(promptLibName(prompts))
projects <- Scaladex.search(libName.value)
project <- promptProject(prompts, projects)
modules <- promptModules(prompts, project)
details <- Scaladex.project(
project.organization,
project.repository
)
version <- promptVersion(prompts, details)
buildTool <- maybeBuildTool
.map(IO.pure(_))
.getOrElse(promptBuildTool(prompts))
content = format(buildTool, details.groupId, modules, version)
_ <- Clipboard.copyToClipboard(content)
_ <- IO.println(doneMessage)
yield ExitCode(0)
.recoverWith:
case CompletionError.Interrupted =>
IO.println("cancelled").as(ExitCode.Error)
case CompletionError.Error(msg) => IO.println(msg).as(ExitCode.Error)
}
end main

def format(
buildTool: BuildTool,
groupId: String,
modules: Array[String],
version: String
): List[String] = modules.toList.map { case module =>
buildTool match
case BuildTool.SBT => s""""$groupId" %% "$module" % "$version""""
case BuildTool.Mill => s"""ivy"$groupId::$module:$version""""
case BuildTool.Bleep => s"""$groupId::$module:$version"""
case BuildTool.ScalaCLI =>
s"""//> using dep "$groupId::$module:$version""""
case BuildTool.Ammonite =>
s"""import $$ivy.`$groupId::$module:$version`"""
}

end Main
Loading
Loading