-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 269b2f8
Showing
12 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: unit tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Scala | ||
uses: olafurpg/setup-scala@v12 | ||
with: | ||
java-version: [email protected] | ||
- name: Unit Tests | ||
run: | | ||
set -e | ||
./mill _.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea | ||
.idea_modules | ||
out | ||
jars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License | ||
|
||
Copyright (c) 2022 Fulcrum Genomics LLC | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[![unit tests](https:/fulcrumgenomics/scala-mill-skeleton/actions/workflows/unittests.yaml/badge.svg)](https:/fulcrumgenomics/scala-mill-skeleton/actions/workflows/unittests.yaml) | ||
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https:/fulcrumgenomics/fgbio/blob/main/LICENSE) | ||
[![Language](https://img.shields.io/badge/language-scala-brightgreen.svg)](http://www.scala-lang.org/) | ||
|
||
|
||
A skeleton repository a Scala-based [fgbio][fgbio-link]-like command-line toolkit. | ||
|
||
## Why this repo? | ||
|
||
This the starting point for [Fulcrum Genomics][fulcrum-genomics-link] projects that contain Scala-based | ||
[fgbio][fgbio-link]-like tools. | ||
Using this infrastructure, you can add quickly add your own tools to a stand-alone toolkit: | ||
|
||
- add your own tools to `tools/src/main/scala/com/client/tools` (see `ExampleTool.scala` contained therein) | ||
|
||
## Building & Testing | ||
|
||
This repo uses [mill](https://com-lihaoyi.github.io/mill/mill/Intro_to_Mill.html) as it's build system. | ||
|
||
To run unit tests: | ||
|
||
```console | ||
./mill _.test | ||
``` | ||
|
||
To build an executable JAR at `./jars/<FIXME>-tools.jar`: | ||
|
||
```console | ||
./mill _.deployLocal | ||
``` | ||
|
||
To set up this project for IntelliJ, run: | ||
|
||
```console | ||
mill mill.scalalib.GenIdea/idea | ||
``` | ||
|
||
|
||
[fgbio-link]: https:/fulcrumgenomics/fgbio | ||
[fulcrum-genomics-link]: https://www.fulcrumgenomics.com | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
import java.util.jar.Attributes.Name.{IMPLEMENTATION_VERSION => ImplementationVersion} | ||
import scala.sys.process.Process | ||
import scala.util.{Failure, Success, Try} | ||
import mill._, scalalib._, publish._ | ||
import coursier.maven.MavenRepository | ||
|
||
/** Base trait for build modules. */ | ||
trait CommonModule extends SbtModule { | ||
def deployLocal(assembly: PathRef, jarName:String) = { | ||
os.makeDir.all(os.pwd / 'jars) | ||
println(s"Copying artifact ${assembly.path} to jars / $jarName") | ||
os.copy(assembly.path, os.pwd / 'jars / jarName, replaceExisting=true) | ||
} | ||
|
||
override def repositories: Seq[coursier.Repository] = super.repositories ++ Seq( | ||
MavenRepository("https://oss.sonatype.org/content/repositories/public"), | ||
MavenRepository("https://oss.sonatype.org/content/repositories/snapshots"), | ||
MavenRepository("https://jcenter.bintray.com/"), | ||
MavenRepository("https://artifactory.broadinstitute.org/artifactory/libs-snapshot/") | ||
) | ||
} | ||
|
||
/** A base trait for versioning modules. */ | ||
trait ReleaseModule extends JavaModule { | ||
/** Execute Git arguments and return the standard output. */ | ||
private def git(args: String*): String = os.proc("git", args).call().out.string.trim | ||
|
||
/** Get the commit hash at the HEAD of this branch. */ | ||
private def gitHead: String = git("rev-parse", "HEAD") | ||
|
||
/** Get the commit shorthash at the HEAD of this branch .*/ | ||
private def shortHash: String = gitHead.take(7) | ||
|
||
/** If the Git repository is left in a dirty state. */ | ||
private def dirty: Boolean = git("status", "--porcelain").nonEmpty | ||
|
||
private def today: String = new SimpleDateFormat("yyyyMMdd").format(new Date()) | ||
|
||
/** The implementation version. */ | ||
private def implementationVersion = T input { | ||
val prefix = s"${today}-${shortHash}" | ||
if (dirty) s"${prefix}-dirty" else prefix | ||
} | ||
|
||
/** The version string `Target`. */ | ||
def version = T input { println(implementationVersion()) } | ||
|
||
/** The JAR manifest. */ | ||
override def manifest = T { super.manifest().add(ImplementationVersion.toString -> implementationVersion()) } | ||
} | ||
|
||
|
||
object tools extends CommonModule with PublishModule with ReleaseModule { | ||
def scalaVersion = "2.13.8" | ||
def mainClass = Some("com.client.cmdline.ClientMain") | ||
def artifactName = "client-tools" | ||
def gitHash = Process("git rev-parse --short HEAD").lineStream.head | ||
def publishVersion = s"0.0.1-${gitHash}-SNAPSHOT" | ||
def pomSettings = PomSettings( | ||
description = artifactName(), | ||
organization = "com.client", | ||
url = "https:/fulcrumgenomics/client-tools", | ||
licenses = Seq(new License(id="Private", name="Private", url="n/a", isOsiApproved=false, isFsfLibre=false, distribution="no")), | ||
versionControl = VersionControl.github("fulcrumgenomics", "scala-mill-skeleton"), | ||
developers = Seq( | ||
Developer("tfenne", "Tim Fennell", "https:/tfenne"), | ||
Developer("nh13", "Nils Homer", "https:/nh13"), | ||
) | ||
) | ||
|
||
private val orgsToExclude = Seq( | ||
"org.apache.ant", | ||
"gov.nih.nlm.ncbi", | ||
"org.testng", | ||
"com.google.cloud.genomics" | ||
) | ||
|
||
def ivyDeps = Agg( | ||
ivy"org.scala-lang:scala-compiler:${scalaVersion()}", | ||
ivy"mysql:mysql-connector-java:5.1.24", | ||
ivy"com.fulcrumgenomics:commons_2.13:1.1.0", | ||
ivy"com.fulcrumgenomics:sopt_2.13:1.1.0", | ||
ivy"com.fulcrumgenomics:fgbio_2.13:1.4.0-61dde53-SNAPSHOT".excludeOrg(orgsToExclude:_*), | ||
) | ||
|
||
object test extends Tests { | ||
def ivyDeps = Agg(ivy"org.scalatest::scalatest:3.1.0") | ||
def testFrameworks = Seq("org.scalatest.tools.Framework") | ||
|
||
// run mill tools.test.singleTest com.client.x.y.x.TestClassName | ||
def singleTest(args: String*) = T.command { | ||
super.runMain("org.scalatest.run", args: _*) | ||
} | ||
} | ||
|
||
def javacOptions = Seq("-source", "1.8", "-target", "1.8") | ||
|
||
def deployLocal = T { super.deployLocal(assembly(), "client-tools.jar") } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env sh | ||
|
||
# This is a wrapper script, that automatically download mill from GitHub release pages | ||
# You can give the required mill version with MILL_VERSION env variable | ||
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION | ||
DEFAULT_MILL_VERSION=0.10.1 | ||
|
||
set -e | ||
|
||
if [ -z "$MILL_VERSION" ] ; then | ||
if [ -f ".mill-version" ] ; then | ||
MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)" | ||
elif [ -f "mill" ] && [ "$BASH_SOURCE" != "mill" ] ; then | ||
MILL_VERSION=$(grep -F "DEFAULT_MILL_VERSION=" "mill" | head -n 1 | cut -d= -f2) | ||
else | ||
MILL_VERSION=$DEFAULT_MILL_VERSION | ||
fi | ||
fi | ||
|
||
if [ "x${XDG_CACHE_HOME}" != "x" ] ; then | ||
MILL_DOWNLOAD_PATH="${XDG_CACHE_HOME}/mill/download" | ||
else | ||
MILL_DOWNLOAD_PATH="${HOME}/.cache/mill/download" | ||
fi | ||
MILL_EXEC_PATH="${MILL_DOWNLOAD_PATH}/${MILL_VERSION}" | ||
|
||
version_remainder="$MILL_VERSION" | ||
MILL_MAJOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}" | ||
MILL_MINOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}" | ||
|
||
if [ ! -x "$MILL_EXEC_PATH" ] ; then | ||
mkdir -p $MILL_DOWNLOAD_PATH | ||
if [ "$MILL_MAJOR_VERSION" -gt 0 ] || [ "$MILL_MINOR_VERSION" -ge 5 ] ; then | ||
ASSEMBLY="-assembly" | ||
fi | ||
DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download | ||
MILL_DOWNLOAD_URL="https:/lihaoyi/mill/releases/download/${MILL_VERSION%%-*}/$MILL_VERSION${ASSEMBLY}" | ||
curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL" | ||
chmod +x "$DOWNLOAD_FILE" | ||
mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH" | ||
unset DOWNLOAD_FILE | ||
unset MILL_DOWNLOAD_URL | ||
fi | ||
|
||
unset MILL_DOWNLOAD_PATH | ||
unset MILL_VERSION | ||
|
||
exec $MILL_EXEC_PATH "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.client.cmdline | ||
|
||
import com.fulcrumgenomics.cmdline.FgBioMain | ||
|
||
/** | ||
* Main program that loads everything up and runs the appropriate sub-command | ||
*/ | ||
object ClientMain { | ||
/** The main method */ | ||
def main(args: Array[String]): Unit = new ClientMain().makeItSoAndExit(args) | ||
} | ||
|
||
class ClientMain extends FgBioMain { | ||
|
||
/** The name of the toolkit, used in printing usage and status lines. */ | ||
override def name: String = "client-tools" | ||
|
||
/** The packages we wish to include in our command line **/ | ||
override protected def packageList: List[String] = | ||
List[String]("com.client") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.client.cmdline | ||
|
||
import com.fulcrumgenomics.cmdline.FgBioTool | ||
import com.fulcrumgenomics.commons.util.LazyLogging | ||
|
||
/** All tools should extend this. */ | ||
trait ClientTool extends FgBioTool with LazyLogging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.client.cmdline | ||
|
||
import com.fulcrumgenomics.sopt.cmdline.ClpGroup | ||
|
||
/** Groups for organizing command line programs for display. */ | ||
object ClpGroups { | ||
|
||
class _All extends ClpGroup { | ||
override val name: String = "All tools" | ||
override val description: String = "All tools." | ||
} | ||
|
||
final val All = classOf[_All] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.client.tools | ||
|
||
|
||
import com.fulcrumgenomics.sopt.clp | ||
import com.client.cmdline.{ClpGroups, ClientTool} | ||
|
||
@clp(group=ClpGroups.All, description= | ||
""" | ||
|Trivial example tool to make sure build system is working. | ||
""") | ||
class ExampleTool() extends ClientTool { | ||
|
||
override def execute(): Unit = { | ||
System.err.println("Hello World!") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.client | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
/** Base class for unit tests. */ | ||
class UnitSpec extends AnyFlatSpec with Matchers {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.client.cmdline | ||
|
||
import com.client.UnitSpec | ||
import com.fulcrumgenomics.commons.util.CaptureSystemStreams | ||
|
||
/** Some basic test for the CLP classes. */ | ||
class ClpTests extends UnitSpec with CaptureSystemStreams { | ||
|
||
"ClientTool" should "should print hello world" in { | ||
val (output, _, _) = captureItAll { () => | ||
new ClientMain().makeItSo("ExampleTool".split(' ')) shouldBe 0 | ||
} | ||
output shouldBe "Hello World!\n" | ||
} | ||
} |