Skip to content

Commit

Permalink
Merge pull request #8 from bee-produced/7-pipeline
Browse files Browse the repository at this point in the history
Pipeline + Publish Artifacts to Maven Central
  • Loading branch information
kurbaniec authored Oct 28, 2023
2 parents 3e7833f + df8b90d commit 4674e05
Show file tree
Hide file tree
Showing 10 changed files with 615 additions and 39 deletions.
134 changes: 134 additions & 0 deletions .github/workflows/github-actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Build, Test & Publish
on:
push:
tags:
- '*'
branches:
- '**'
jobs:
Build-Test:
runs-on: ubuntu-latest
if: "!startsWith(github.ref, 'refs/tags/')"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
cache: 'gradle'
- name: Make gradlew executable
run: |
chmod +x ./bee.persistent/gradlew
chmod +x ./bee.functional/gradlew
chmod +x ./bee.buzz/gradlew
chmod +x ./bee.generative/gradlew
chmod +x ./bee.fetched/gradlew
chmod +x ./bee.fetched.test/gradlew
chmod +x ./example/application/gradlew
- name: Build & Test bee.persistent
working-directory: ./bee.persistent
run: ./gradlew build
- name: Build & Test bee.functional
working-directory: ./bee.functional
run: ./gradlew build
- name: Build & Test bee.buzz
working-directory: ./bee.buzz
run: ./gradlew build
- name: Build & Test bee.generative
working-directory: ./bee.generative
run: ./gradlew build
- name: Build & Test bee.fetched
run: |
cd ./bee.fetched/
./gradlew build
cd ../bee.fetched.test/
./gradlew build
- name: Build & Test example application
working-directory: ./example/application
run: ./gradlew build

Build-Test-Publish:
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
env:
JRELEASER_NEXUS2_USERNAME: ${{ secrets.JRELEASER_NEXUS2_USERNAME }}
JRELEASER_NEXUS2_PASSWORD: ${{ secrets.JRELEASER_NEXUS2_PASSWORD }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Remove -SNAPSHOT suffix from bee-built version
run: sed -i '/bee-built/ s/-SNAPSHOT//g' ./gradle/libs.versions.toml
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
cache: 'gradle'
- name: Make gradlew executable
run: |
chmod +x ./bee.persistent/gradlew
chmod +x ./bee.functional/gradlew
chmod +x ./bee.buzz/gradlew
chmod +x ./bee.generative/gradlew
chmod +x ./bee.fetched/gradlew
chmod +x ./bee.fetched.test/gradlew
chmod +x ./example/application/gradlew
- name: Build & Test bee.persistent
working-directory: ./bee.persistent
run: ./gradlew build
- name: Build & Test bee.functional
working-directory: ./bee.functional
run: ./gradlew build
- name: Build & Test bee.buzz
working-directory: ./bee.buzz
run: ./gradlew build
- name: Build & Test bee.generative
working-directory: ./bee.generative
run: ./gradlew build
- name: Build & Test bee.fetched
run: |
cd ./bee.fetched/
./gradlew build
cd ../bee.fetched.test/
./gradlew build
- name: Build & Test example application
working-directory: ./example/application
run: ./gradlew build

- name: Publish bee.persistent
continue-on-error: true
working-directory: ./bee.persistent
run: |
./gradlew publish
./gradlew jreleaserDeploy
- name: Publish bee.functional
continue-on-error: true
working-directory: ./bee.functional
run: |
./gradlew publish
./gradlew jreleaserDeploy
- name: Publish bee.buzz
continue-on-error: true
working-directory: ./bee.buzz
run: |
./gradlew publish
./gradlew jreleaserDeploy
- name: Publish bee.generative
continue-on-error: true
working-directory: ./bee.generative
run: |
./gradlew publish
./gradlew jreleaserDeploy
- name: Publish bee.fetched
continue-on-error: true
working-directory: ./bee.fetched
run: |
./gradlew publish
./gradlew jreleaserDeploy
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Extend DGS:
Some changes are currently being made:

* `bee.persistent`
Easier data handling for GraphQL + JPA, [documentation](./lib.data/README.md)
Easier data handling for GraphQL + JPA, [documentation](./bee.persistent/README.md)
* `bee.functional`
Functional kotlin bindings, integration with DGS, `bee.persistent` & more
* `bee.buzz`
Expand Down
93 changes: 92 additions & 1 deletion bee.buzz/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jreleaser.model.Active

plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.spring.boot).apply(false)
alias(libs.plugins.spring.dependencymanagement)
alias(libs.plugins.jreleaser)
`maven-publish`
signing
java
}

group = "com.beeproduced"
version = libs.versions.bee.built.get()
description = "Simple event manager based on the mediator pattern."
java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17
tasks.withType<KotlinCompile>().configureEach {
Expand Down Expand Up @@ -41,13 +46,17 @@ sourceSets {
}

java {
withSourcesJar()
withJavadocJar()
registerFeature("simple") {
usingSourceSet(sourceSets["simple"])
withSourcesJar()
withJavadocJar()
}
}

dependencies {
implementation("com.beeproduced:bee.functional")
implementation("com.beeproduced:bee.functional:$version")
implementation(libs.kotlin.stdlib)
implementation(libs.spring.boot.starter.web)
testImplementation(libs.junit.api)
Expand All @@ -57,3 +66,85 @@ dependencies {
tasks.withType<Test> {
useJUnitPlatform()
}

// Based on https://www.tschuehly.de/posts/guide-kotlin-gradle-publish-to-maven-central/#51-generate-javadocs-and-sources-jars
publishing {
publications {
create<MavenPublication>("Maven") {
from(components["java"])
description = project.description
}
withType<MavenPublication> {
pom {
packaging = "jar"
name.set(project.name)
description.set(project.description)
url.set("https://github.com/bee-produced/bee-built")
licenses {
license {
name.set("MIT license")
url.set("https://opensource.org/licenses/MIT")
}
}
developers {
developer {
id.set("kurbaniec")
name.set("Kacper Urbaniec")
email.set("kacper.urbaniec@beeproduced.com")
}
}
scm {
connection.set("scm:git:git@github.com:bee-produced/bee-built.git")
developerConnection.set("scm:git:ssh:git@github.com:bee-produced/bee-built.git")
url.set("https://github.com/bee-produced/bee-built")
}
}
}
}
repositories {
maven {
url = layout.buildDirectory.dir("staging-deploy").get().asFile.toURI()
}
}
}

jreleaser {
project {
copyright.set("bee produced")
}
gitRootSearch.set(true)
signing {
active.set(Active.ALWAYS)
armored.set(true)
}
deploy {
maven {
nexus2 {
create("maven-central") {
active.set(Active.ALWAYS)
url.set("https://s01.oss.sonatype.org/service/local")
closeRepository.set(true)
releaseRepository.set(true)
stagingRepositories.add("build/staging-deploy")
}
}
}
}
}

// Invalid pom is produced when using both the dependency management plugin and Gradle's bom support
// See: https://github.com/spring-gradle-plugins/dependency-management-plugin/issues/257#issuecomment-895790557
tasks.withType<GenerateMavenPom>().all {
doLast {
val file = file("${layout.buildDirectory.get().asFile.toURI()}/publications/Maven/pom-default.xml")
var text = file.readText()
val regex = "(?s)(<dependencyManagement>.+?<dependencies>)(.+?)(</dependencies>.+?</dependencyManagement>)".toRegex()
val matcher = regex.find(text)
if (matcher != null) {
text = regex.replaceFirst(text, "")
val firstDeps = matcher.groups[2]!!.value
text = regex.replaceFirst(text, "$1$2$firstDeps$3")
}
file.writeText(text)
}
}
36 changes: 26 additions & 10 deletions bee.fetched/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,30 @@ In addition, these types of data fetchers can be quite easily overlooked during

This code generation library attempts to solve this problem by automatically generating such nested data fetches from DGS DTOs and data loader definitions. `bee.fetched` is based on `ksp` for lightweight, idiomatic code generation.

Note that this library builds upon [DGS](https://netflix.github.io/dgs/) and is not intended for use with only `graphql-java`.
Note that this library builds upon [DGS](https://netflix.github.io/dgs/) and is not intended for use with only `graphql-java`.

## 🚀 Quickstart

### 🛠️ Configuration

The following shows the easiest way to incorporate `bee.fetched` into a project.

`settings.gradle.kts`

```kotlin
pluginManagement {
resolutionStrategy {
eachPlugin {
when (requested.id.id) {
"bee.generative" -> useModule("com.beeproduced:bee.generative:<BEE_BUILT_VERSION>")
}
}
}
}
```

> ⚠️ As `bee.generative` is currently not published to the gradle plugin portal, the publication on maven central has no [plugin marker](https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers) and thus requires this [workaround](https://github.com/GoogleCloudPlatform/app-gradle-plugin/issues/397#issuecomment-1484070866).
`build.gradle.kts`:

```kotlin
Expand All @@ -32,7 +48,7 @@ plugins {
}

dependencies {
beeGenerative("com.beeproduced:bee.fetched")
beeGenerative("com.beeproduced:bee.fetched:<BEE_BUILT_VERSION>")
}

// DGS codegen
Expand Down Expand Up @@ -107,9 +123,9 @@ class WaldoDataLoader : MappedBatchLoaderWithContext<String, Waldo> {
}
```

> ⚠️ Please do not forget to annotate the data loader with `@BeeFetched` if one wants to utilise code generation.
> ⚠️ Please do not forget to annotate the data loader with `@BeeFetched` if one wants to utilise code generation.
> 🪧 The `@BeeFetched` annotation will be explained in the following step by step.
> 🪧 The `@BeeFetched` annotation will be explained in the following step by step.
With the help of `bee.fetched` all of the corresponding nested data fetchers including their data loader invocations can be automatically generated.

Expand All @@ -119,9 +135,9 @@ In the following schema `waldo` and `waldos` are the fields that should be loade

A simple approach is used:

* Entities like `waldo` => Search for `waldoId`
* Entities like `waldo` => Search for `waldoId`
* Collections like `waldos` => Search for `waldoIds` or `waldosIds`
* Not modelled but possible: A collection called `waldo` => Search for `waldoIds` or `waldosIds`
* Not modelled but possible: A collection called `waldo` => Search for `waldoIds` or `waldosIds`

```crystal
type Foo {
Expand Down Expand Up @@ -215,7 +231,7 @@ type Corge {
}
```

To do so, one must provide a `FetcherMapping` via `@BeeFetched` that maps `Corge`'s `waldo` field to the id `corgeToWaldoId`.
To do so, one must provide a `FetcherMapping` via `@BeeFetched` that maps `Corge`'s `waldo` field to the id `corgeToWaldoId`.

```kotlin
@BeeFetched(
Expand Down Expand Up @@ -290,7 +306,7 @@ In these cases, one must provide a `FetcherInternalType` via `@BeeFetched` that
class WaldoDataLoader : MappedBatchLoaderWithContext<String, Waldo>
```

> 🪧 If `Grault` would have another field `waldo2: Waldo` the library would use the `Grault` DTO and not the `TestController.MyGrault` internal type as it is only configured for `DgsConstants.GRAULT.Waldo`. Leaving `DgsConstants.GRAULT.Waldo` empty or adding an additional `FetcherInternalType` for `DgsConstants.GRAULT.Waldo2` would result in usage of the internal type.
> 🪧 If `Grault` would have another field `waldo2: Waldo` the library would use the `Grault` DTO and not the `TestController.MyGrault` internal type as it is only configured for `DgsConstants.GRAULT.Waldo`. Leaving `DgsConstants.GRAULT.Waldo` empty or adding an additional `FetcherInternalType` for `DgsConstants.GRAULT.Waldo2` would result in usage of the internal type.
This results in following generated code.

Expand Down Expand Up @@ -377,7 +393,7 @@ class WaldoDataLoader : MappedBatchLoaderWithContext<String, Waldo>
#### Safety first - Do not load what is already present

By default, `bee.fetched` generates nested data fetcher with an early return when data is already present for the requested field. This feature is called `safeMode` and can be illustrated as follows.
By default, `bee.fetched` generates nested data fetcher with an early return when data is already present for the requested field. This feature is called `safeMode` and can be illustrated as follows.

```kotlin
@DgsData(
Expand Down Expand Up @@ -438,4 +454,4 @@ class WaldoDataLoader : MappedBatchLoaderWithContext<String, Waldo>
## 🧪 Example & Tests

An example on which this documentation is based on can be found under `bee.fetched.test` in the root project. The tests for this library reside also in this example project.
An example on which this documentation is based on can be found under `bee.fetched.test` in the root project. The tests for this library reside also in this example project.
Loading

0 comments on commit 4674e05

Please sign in to comment.