Skip to content

Commit

Permalink
Multiplatform release (#6)
Browse files Browse the repository at this point in the history
* Progress towards mpp

* Mpp config

* Get ank working again. Also publicly expose some internals

* Maybe working publishing?
  • Loading branch information
1Jajen1 authored Mar 23, 2021
1 parent 4dd0436 commit 656ba74
Show file tree
Hide file tree
Showing 35 changed files with 959 additions and 1,675 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Wrapper validation
uses: gradle/wrapper-validation-action@v1
- name: setup-java
uses: actions/setup-java@v1.3.0
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ on:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: setup-java
uses: actions/setup-java@v1.3.0
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Wrapper validation
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on:
release:
types:
- released

jobs:
build:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: setup-java
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Wrapper validation
uses: gradle/wrapper-validation-action@v1
- name: Build
run: |
chmod +x gradlew
env BINTRAY_USER=jannis BINTRAY_API_KEY=${{ secrets.BINTRAY_API_KEY }} ./gradlew publish
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repositories {
}
dependencies {
implementation "kotlin-pretty:kotlin-pretty:0.5.2"
implementation "kotlin-pretty:kotlin-pretty:0.6.0"
}
```

Expand Down
65 changes: 24 additions & 41 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,70 +1,53 @@
buildscript {
ext {
arrow_version = "0.10.5"
kotlinVersion = "1.3.61"
arrow_version = "0.11.0"
kotlinVersion = "1.4.31"
}

repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
maven { url 'https://dl.bintray.com/arrow-kt/arrow-kt/' }
}
dependencies {
classpath "me.champeau.gradle:jmh-gradle-plugin:0.5.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion"
classpath "io.arrow-kt:arrow-ank-gradle:$arrow_version"
classpath "io.arrow-kt:arrow-ank-gradle:0.10.5"
}
}

// ank setup, kotlin project + sources from both subprojects
apply plugin: 'ank-gradle-plugin'
apply plugin: 'kotlin'

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation project(":kotlin-pretty")
implementation project(":kotlin-pretty-ansi")
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

ank {
source = file("docs/contentIn")
target = file("docs/content")
classpath = sourceSets.main.runtimeClasspath
}

allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
maven { url 'https://dl.bintray.com/arrow-kt/arrow-kt/' }
maven { url 'https://dl.bintray.com/jannis/kotlin-pretty' }
maven { url 'https://dl.bintray.com/jannis/kparsec' }
maven { url 'https://dl.bintray.com/jannis/propCheck-kt' }
}
}

subprojects { proj ->
group = GROUP
version = VERSION_NAME

apply plugin: 'kotlin'
apply plugin: 'kotlin-multiplatform'

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlin {
explicitApi = 'strict'
}
}

// ank setup
apply plugin: 'ank-gradle-plugin'
apply plugin: 'kotlin'

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation project(":kotlin-pretty")
implementation project(":kotlin-pretty-ansi")
}

ank {
source = file("docs/contentIn")
target = file("docs/content")
classpath = sourceSets.main.runtimeClasspath
}
20 changes: 7 additions & 13 deletions docs/contentIn/en/docs/api-reference/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -701,24 +701,18 @@ A very simple layout algorithm that lays out a document with no extra newlines o
Render a simple doc as a string. Ignores annotations.

---
###### `fun <A, B> SimpleDoc<A>.renderDecorated(MO: Monoid<B>, text: (String) -> B, addAnn: (A) -> B, removeAnn: (A) -> B): B`
###### `fun <A, B> SimpleDoc<A>.renderDecorated(empty: B, combine: (B, B) -> B, fromString: (String) -> B, annotate: (A, B) -> B): B`

Helper to implement basic renders that handle annotations. This takes a [Monoid](https://arrow-kt.io/docs/arrow/typeclasses/monoid/), which in short is a combine operation and an empty element for a given datatype (e.g. `StringMonoid = { empty = "", combine = (a: String, b: String) -> a + b }`). Also this should hold a few invariants: `empty + x == x`, `x + empty == x` and `a + (b + c) == (a + b) + c`. The other parameters are functions which handle either text or the addition or removal of an annotation.
Helper to implement basic renders that handle annotations.

For example [renderString]({{< relref "#fun-simpledocarenderstring-string" >}}) is defined as:
```kotlin:ank:silent
import arrow.core.identity
import arrow.core.extensions.monoid
fun <A> SimpleDoc<A>.renderString(): String =
renderDecorated(
String.monoid(), // predefined by arrow
::identity, // also predefined by arrow, simple does nothing with the input
{ "" }, { "" } // don't add anything on either addition or removal of annotations
empty = "",
combine = { a, b -> a + b },
fromString = { it },
annotate = { ann, str -> str }
)
```

---
###### `fun <A, B> SimpleDoc<A>.renderDecoratedA(AP: Applicative<F>, MO: Monoid<B>, text: (String) -> Kind<F, B>, addAnn: (A) -> Kind<F, B>, removeAnn: (A) -> Kind<F, B>): B`

More general form of [renderDecorated]({{< relref "#fun-a-b-simpledocarenderdecoratedaap-applicativef-mo-monoidb-text-string---kindf-b-addann-a---kindf-b-removeann-a---kindf-b-b" >}}). This allows in a purely functional way to do effects when rendering. This can mean keeping some state around, writing additional output or accessing inputs. If you value pure functions, this can also be used to render directly to an output handle in a purely functional way. [renderDecorated]({{< relref "#fun-a-b-simpledocarenderdecoratedaap-applicativef-mo-monoidb-text-string---kindf-b-addann-a---kindf-b-removeann-a---kindf-b-b" >}}) is also defined as `renderDecoratedA` but using the `Id` applicative, which is the identity effect, i.e. it does nothing special on top of the default behaviour.
```
2 changes: 1 addition & 1 deletion docs/contentIn/en/docs/getting-started/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {
}
dependencies {
implementation "kotlin-pretty:kotlin-pretty:0.5.2"
implementation "kotlin-pretty:kotlin-pretty:0.6.0"
}
```

Expand Down
10 changes: 6 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
kotlin.code.style=official
GROUP=kotlin-pretty
VERSION_NAME=0.5.2
VERSION_NAME=0.6.0

# Publication
RELEASE_REPOSITORY=https://api.bintray.com/maven/jannis/kotlin-pretty/kotlin-pretty
POM_DESCRIPTION=Easy to use, extensible pretty-printer
POM_URL=https://github.com/1Jajen1/kotlin-pretty
POM_SCM_URL=https://github.com/1Jajen1/kotlin-pretty
POM_SCM_CONNECTION=scm:git:git://github.com/1Jajen1/kotlin-pretty.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://[email protected]/1Jajen1/kotlin-pretty.git
POM_LICENCE_NAME=BSD-3
POM_LICENCE_URL=https://github.com/1Jajen1/kotlin-pretty/blob/master/LICENSEtxt
POM_LICENCE_URL=https://github.com/1Jajen1/kotlin-pretty/blob/master/LICENSE.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=jannis
POM_DEVELOPER_NAME="Jannis Overesch"

kotlin.native.ignoreDisabledTargets=true
133 changes: 45 additions & 88 deletions gradle/publish.gradle
Original file line number Diff line number Diff line change
@@ -1,103 +1,60 @@
import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'signing'

def findProperty(String key) {
[project.properties[key], System.getenv(key)].find { it != null }
def windowsPublications = ["mingwX64", "mingwX86"]
def macosPublications = kotlin.targets.names.findAll {
it.startsWith("macos") || it.startsWith("ios") || it.startsWith("watchos") || it.startsWith("tvos")
}
def linuxPublications = publishing.publications.names - macosPublications - windowsPublications

def getReleaseRepositoryUrl() {
return findProperty('RELEASE_REPOSITORY_URL') ?: "https://api.bintray.com/maven/jannis/kotlin-pretty/kotlin-pretty"
def publicationsFromThisPlatform = {
if (Os.isFamily(Os.FAMILY_WINDOWS)) return windowsPublications
else if (Os.isFamily(Os.FAMILY_MAC)) return macosPublications
else if (Os.isFamily(Os.FAMILY_UNIX)) return linuxPublications
else error("Expected either a windows, mac or linux host")
}

def getRepositoryUsername() {
return findProperty('BINTRAY_USER') ?: "no.bintray.user"
}

def getRepositoryPassword() {
return findProperty('BINTRAY_KEY') ?: "no.bintray.api.key"
}

uploadArchives {
repositories.mavenDeployer {
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

repository(url: getReleaseRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}

pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL

scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}

developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
kotlin {
publishing {
repositories {
maven {
credentials {
username "$System.env.BINTRAY_USER"
password "$System.env.BINTRAY_API_KEY"
}
url = RELEASE_REPOSITORY
}
}
}
}

install {
repositories.mavenInstaller {
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL

scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
def targetPublications = publicationsFromThisPlatform()
tasks.withType(AbstractPublishToMaven)
.configureEach {
onlyIf { it.publication.name in targetPublications }
}
}

developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
publications.withType(MavenPublication).all {
pom {
name = POM_NAME
description = POM_DESCRIPTION
url = POM_URL
scm {
url = POM_SCM_URL
connection = POM_SCM_CONNECTION
developerConnection = POM_SCM_DEV_CONNECTION
}
licenses {
license {
name = POM_LICENCE_NAME
url = POM_LICENCE_URL
distribution = POM_LICENCE_DIST
}
}
developers {
developer {
name = "Jannis"
}
}
}
}
}
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource + 'build/generated/source/kapt/main', 'build/generated/source/kaptKotlin/main'
}

artifacts {
archives sourcesJar
}
Loading

0 comments on commit 656ba74

Please sign in to comment.