Skip to content

Commit

Permalink
Add deployment to maven central (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasForst authored May 16, 2021
1 parent 9b6d409 commit 774e9a4
Show file tree
Hide file tree
Showing 8 changed files with 829 additions and 95 deletions.
33 changes: 0 additions & 33 deletions .github/workflows/cd.yml

This file was deleted.

29 changes: 20 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
name: CI Build Pipeline
name: CI test

# Trigger on each push
on: [push]
on:
push:
pull_request:

jobs:
build:
name: Build and test
runs-on: ubuntu-latest
test:
runs-on: ${{ matrix.os }}
name: Build & Test - Java ${{ matrix.java }} on ${{ matrix.os }}
strategy:
matrix:
os: [ windows-latest, ubuntu-latest ]
java: [ 8, 11, 16 ]

steps:
- uses: actions/checkout@v2
- name: Setup JDK
uses: actions/setup-java@v1
with:
java-version: 11.0.3
java-version: ${{ matrix.java }}

- name: Execute test with gradle
run: ./gradlew test
- name: Build lib
run: ./gradlew assemble

- name: Run tests
run: ./gradlew test --info

- name: Check styling using Detekt
run: ./gradlew detekt --info
63 changes: 63 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Release pipeline

on:
release:
types: [ published ]

jobs:
test:
name: Build & Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup JDK
uses: actions/setup-java@v1
with:
java-version: 8

- name: Build lib
run: ./gradlew assemble

- name: Run tests
run: ./gradlew test --info

- name: Check styling using Detekt
run: ./gradlew detekt --info

publish:
needs: [ test ]
name: Build and publish library
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup JDK
uses: actions/setup-java@v1
with:
java-version: 8
server-id: ossrh
server-username: OSSRH_USERNAME
server-password: OSSRH_PASSWORD
gpg-private-key: ${{ secrets.GPG_KEY }}
gpg-passphrase: GPG_KEY_PASSWORD

- name: Build lib
run: ./gradlew assemble --info

- name: Publish to Maven Central
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --info
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
GPG_KEY: ${{ secrets.GPG_KEY }}
GPG_KEY_PASSWORD: ${{ secrets.GPG_KEY_PASSWORD }}

- name: Generate API documentation
run: ./gradlew dokkaHtml

- name: Deploy API documentation to Github Pages
uses: JamesIves/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: build/docs
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Exposed PostgreSQL Upsert
![CI Build Pipeline](https://github.com/LukasForst/exposed-upsert/workflows/CI%20Build%20Pipeline/badge.svg)
![CD publish pipeline](https://github.com/LukasForst/exposed-upsert/workflows/CD%20publish%20pipeline/badge.svg)
[ ![Download](https://api.bintray.com/packages/lukas-forst/jvm-packages/exposed-upsert/images/download.svg?version=1.0) ](https://bintray.com/lukas-forst/jvm-packages/exposed-upsert/1.0/link)

Unfortunately, current [Exposed](https://github.com/JetBrains/Exposed) framework does not contain upsert
(update or insert) functionality out of the box.
Expand All @@ -22,16 +21,15 @@ Votes.insertOrUpdate(Votes.pollId, Votes.userId) {
}
```

Library is hosted on [Github Packages](https://github.com/LukasForst/exposed-upsert/packages) and on [Bintray](https://bintray.com/beta/#/lukas-forst/jvm-packages/exposed-upsert). To include the libary in your project:
Maven:
Library is hosted on Maven Central.
```xml
<dependency>
<groupId>pw.forst</groupId>
<artifactId>exposed-upsert</artifactId>
<version>1.0</version>
<version>1.1.0</version>
</dependency>
```
Gradle:
```kotlin
implementation("pw.forst", "exposed-upsert", "1.0")
implementation("pw.forst", "exposed-upsert", "1.1.0")
```
129 changes: 83 additions & 46 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
import com.jfrog.bintray.gradle.BintrayExtension
import org.gradle.jvm.tasks.Jar
import java.net.URL

plugins {
kotlin("jvm") version "1.5.0"

`maven-publish`
kotlin("jvm") version "1.3.70"
id("net.nemerosa.versioning") version "2.8.2"
id("com.jfrog.bintray") version "1.8.4"
signing
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"

id("net.nemerosa.versioning") version "2.14.0"
id("org.jetbrains.dokka") version "1.4.32"
id("io.gitlab.arturbosch.detekt") version "1.17.0"
}

// project name must be set in settings.gradle.kts
group = "pw.forst"
version = versioning.info.lastTag
base.archivesBaseName = "exposed-upsert"
version = (versioning.info?.tag ?: versioning.info?.lastTag ?: versioning.info?.build) ?: "SNAPSHOT"

repositories {
jcenter()
mavenCentral()
}

dependencies {
compileOnly(kotlin("stdlib-jdk8"))
compileOnly("org.jetbrains.exposed", "exposed-core", "0.21.1")
compileOnly("org.jetbrains.exposed", "exposed-core", "0.31.1")
compileOnly("org.jetbrains.kotlin", "kotlin-reflect", "1.5.0")
}

detekt {
parallel = true
input = files("$rootDir/src")
config = files(rootDir.resolve("detekt-config.yml"))
}

tasks {
Expand All @@ -27,14 +40,29 @@ tasks {
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

test {
useJUnitPlatform()
}

dokkaHtml {
outputDirectory.set(File("$buildDir/docs"))

dokkaSourceSets {
configureEach {
displayName.set("Exposed Upsert")

sourceLink {
localDirectory.set(file("src/main/kotlin"))
remoteUrl.set(URL("https://github.com/LukasForst/exposed-upsert/tree/master/src/main/kotlin"))
remoteLineSuffix.set("#L")
}
}
}
}
}

// ------------------------------------ Deployment Configuration ------------------------------------
val githubRepository = "LukasForst/exposed-upsert"
val descriptionForPackage = "Simple upsert implementation for Exposed and PostgreSQL"
val tags = arrayOf("kotlin", "PostgreSQL", "Exposed", "Exposed-Extensions")
// everything bellow is set automatically

// deployment configuration - deploy with sources and documentation
val sourcesJar by tasks.creating(Jar::class) {
archiveClassifier.set("sources")
Expand All @@ -47,49 +75,58 @@ val javadocJar by tasks.creating(Jar::class) {
}

// name the publication as it is referenced
val publication = "default-gradle-publication"
val publication = "mavenJava"
publishing {
// create jar with sources and with javadoc
publications {
register(publication, MavenPublication::class) {
create<MavenPublication>(publication) {
from(components["java"])
artifact(sourcesJar)
artifact(javadocJar)
}
}

// publish package to the github packages
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/$githubRepository")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
pom {
name.set("exposed-upsert")
description.set("Simple upsert implementation for Exposed and PostgreSQL.")
url.set("https://exposed-upsert.forst.pw")
packaging = "jar"
licenses {
license {
name.set("MIT")
url.set("https://mit-license.org/license.txt")
}
}
developers {
developer {
id.set("lukasforst")
name.set("Lukas Forst")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:git://github.com/LukasForst/exposed-upsert.git")
url.set("https://github.com/LukasForst/exposed-upsert")
}
}
}
}
}

// upload to bintray
bintray {
// env variables loaded from pipeline for publish
user = project.findProperty("bintray.user") as String? ?: System.getenv("BINTRAY_USER")
key = project.findProperty("bintray.key") as String? ?: System.getenv("BINTRAY_TOKEN")
publish = true
setPublications(publication)
pkg(delegateClosureOf<BintrayExtension.PackageConfig> {
// my repository for maven packages
repo = "jvm-packages"
name = project.name
// my user account at bintray
userOrg = "lukas-forst"
websiteUrl = "https://forst.pw"
githubRepo = githubRepository
vcsUrl = "https://github.com/$githubRepository"
description = descriptionForPackage
setLabels(*tags)
setLicenses("MIT")
desc = description
})
signing {
val signingKeyId = project.findProperty("gpg.keyId") as String? ?: System.getenv("GPG_KEY_ID")
val signingKey = project.findProperty("gpg.key") as String? ?: System.getenv("GPG_KEY")
val signingPassword = project.findProperty("gpg.keyPassword") as String? ?: System.getenv("GPG_KEY_PASSWORD")

useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign(publishing.publications[publication])
}

nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username.set(project.findProperty("ossrh.username") as String? ?: System.getenv("OSSRH_USERNAME"))
password.set(project.findProperty("ossrh.password") as String? ?: System.getenv("OSSRH_PASSWORD"))
}
}
}
Loading

0 comments on commit 774e9a4

Please sign in to comment.