Skip to content

Commit

Permalink
Merge pull request #1 from hoangmaihuy/universal-packager
Browse files Browse the repository at this point in the history
feat: Universal packager
  • Loading branch information
hoangmaihuy committed Dec 5, 2023
2 parents f68f09c + 602f142 commit 28dc2b5
Show file tree
Hide file tree
Showing 27 changed files with 2,919 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
70 changes: 70 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
on:
push:
branches:
- main
tags:
- '**'
pull_request:

# cancel older runs of a pull request;
# this will not cancel anything for normal git pushes
concurrency:
group: cancel-old-pr-runs-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true


jobs:
build:
name: Build and Test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
java-version: [11]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: temurin

- name: Check publishing local
run: ./millw -i __.publishLocal $(pwd)/testRepo

- name: Test
run: ./millw -i -k __.test

publish:
name: Publish to Maven Central
needs: [build]
if: github.repository == 'hoangmaihuy/mill-universal-packager' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
concurrency: publish-{{ github.sha }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: 11
distribution: temurin

- name: Publish to Maven Central
run: ./millw -i io.kipp.mill.ci.release.ReleaseModule/publishAll
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release
on:
push:
branches:
- main
tags: ["*"]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- run: ./millw -i io.kipp.mill.ci.release.ReleaseModule/publishAll
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

.idea
.vscode
.bsp
out
1 change: 1 addition & 0 deletions .mill-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.11.6
33 changes: 33 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version = "3.7.14"
runner.dialect = scala213

project.git = true
style=default

maxColumn = 120

align.preset = some
align.openParenCallSite = false
align.openParenDefnSite = false

newlines.topLevelStatements = [before,after]
newlines.alwaysBeforeElseAfterCurlyIf = false
newlines.implicitParamListModifierForce = [before]
newlines.penalizeSingleSelectMultiArgList = false
newlines.avoidForSimpleOverflow = [punct]

verticalMultiline.atDefnSite = true
verticalMultiline.newlineAfterOpenParen = true
danglingParentheses.exclude = []

optIn.configStyleArguments = true

runner.optimizer.forceConfigStyleOnOffset = 70
runner.optimizer.forceConfigStyleMinArgCount = 3

continuationIndent.defnSite = 2
continuationIndent.callSite = 2
continuationIndent.ctorSite = 2

danglingParentheses.defnSite = true
danglingParentheses.callSite = true
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
# mill-universal-packager
Universal packaging for Mill

Universal packaging for Java application, ported from [sbt-native-packager](https://github.com/sbt/sbt-native-packager).

Currently, `mill-universal-packager` only supports universal `zip` archive with Bash start script.

## Usage

```scala
// build.sc
import $ivy.`io.github.hoangmaihuy::mill-universal-packager::<latest-version>`

import io.github.hoangmaihuy.mill.packager.archetypes.JavaAppPackagingModule

object example extends JavaAppPackagingModule {
override def packageVersion = "0.1.0"
}
```

Run `universalPackage` command

```bash
> mill example.universalPackage
```

Zip package will be saved at `universalPackage.dest` in Mill's `out` folder.

## Configuration

`mill-universal-packager` configurations are similar to `JavaAppPackaging` and `Universal` plugin keys
from `sbt-native-packager`.

| Key | Type | Default | Description |
|----------------------|----------------------------|-------------------------------------------|------------------------------------------------------------------------|
| packageVersion | String | | Package version to use in `packageName` |
| packageName | String | `artifactName() + "-" + packageVersion()` | Package file name |
| maintainer | String | | Maintainer name
| executableScriptName | String | `artifactName()` | Executable script file name |
| topLevelDirectory | Option[String] | `None` | Top level directory in archive file |
| universalSources | PathRef | `millSourcePath / "universal"` | Files to be included in archive, for example `.conf`, `.ini` files,... |
| universalMappings | Seq[(os.Path, os.SubPath)] | | A list of mappings from original path to archive path |

## More information

This plugin was ported from ported from [sbt-native-packager](https://github.com/sbt/sbt-native-packager). Core functions were copied from `sbt-native-packager` with some modifications to work with Mill.

## Licenses

This software is released under the Apache License 2.0. More information in the file LICENSE distributed with this project.
67 changes: 67 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import $ivy.`de.tototec::de.tobiasroeser.mill.integrationtest::0.7.1`
import $ivy.`io.chris-kipp::mill-ci-release::0.1.9`

import mill._
import mill.scalalib._
import mill.scalalib.publish._
import mill.scalalib.api.ZincWorkerUtil.scalaNativeBinaryVersion

import de.tobiasroeser.mill.integrationtest._
import io.kipp.mill.ci.release.CiReleaseModule
import io.kipp.mill.ci.release.SonatypeHost

def millVersionFile = T.source(PathRef(os.pwd / ".mill-version"))

def millVersion = T {
os.read(millVersionFile().path).trim
}

object Versions {
lazy val scala = "2.13.12"
}

object `mill-universal-packager` extends ScalaModule with CiReleaseModule {

override def scalaVersion = Versions.scala

override def sonatypeHost = Some(SonatypeHost.s01)

override def versionScheme: T[Option[VersionScheme]] = T(Option(VersionScheme.EarlySemVer))

override def pomSettings = PomSettings(
description = "Universal packaging for Mill",
organization = "io.github.hoangmaihuy",
url = "https://github.com/hoangmaihuy/mill-universal-packager",
licenses = Seq(License.`Apache-2.0`),
versionControl = VersionControl.github(owner = "hoangmaihuy", repo = "mill-universal-packager"),
developers = Seq(Developer("hoangmaihuy", "Hoang Mai", "https://github.com/hoangmaihuy"))
)

override def artifactName = "mill-universal-packager"

override def artifactSuffix =
"_mill" + scalaNativeBinaryVersion(millVersion()) +
super.artifactSuffix()

override def scalacOptions = Seq("-Ywarn-unused", "-deprecation")

override def compileIvyDeps = super.compileIvyDeps() ++ Agg(
ivy"com.lihaoyi::mill-scalalib:${millVersion()}"
)
}

object itest extends MillIntegrationTestModule {

override def millTestVersion = millVersion

override def pluginsUnderTest = Seq(`mill-universal-packager`)

def testBase = millSourcePath / "src"

override def testInvocations = Seq(
PathRef(testBase / "example") -> Seq(
TestInvocation.Targets(Seq("universalPackage"))
)
)

}
25 changes: 25 additions & 0 deletions itest/src/example/build.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import $file.plugins
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`

import mill._
import mill.scalalib._
import de.tobiasroeser.mill.vcs.version.VcsVersion

import io.github.hoangmaihuy.mill.packager.archetypes._

object example extends RootModule with ScalaModule with JavaAppPackagingModule {


override def artifactName = "example"

override def scalaVersion = "3.3.1"

override def mainClass = Some("MainApp")

override def packageVersion = VcsVersion.vcsState().format()

override def ivyDeps = super.ivyDeps() ++ Seq(
ivy"dev.zio::zio:2.0.19"
)

}
9 changes: 9 additions & 0 deletions itest/src/example/src/MainApp.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import zio.*

object MainApp extends ZIOAppDefault {

override def run: ZIO[Any & ZIOAppArgs & Scope, Any, Any] = {
ZIO.succeed(println("Hello, World!"))
}

}
9 changes: 9 additions & 0 deletions itest/src/example/src/SecondMainApp.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import zio.*

object SecondMainApp extends ZIOAppDefault {

override def run: ZIO[Any & ZIOAppArgs & Scope, Any, Any] = {
ZIO.succeed(println("Hello, Second World!"))
}

}
Loading

0 comments on commit 28dc2b5

Please sign in to comment.