Skip to content

Commit

Permalink
chore: Refactor for modules to release (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
dieppa authored Nov 28, 2024
1 parent 58d8e01 commit 483d5c4
Show file tree
Hide file tree
Showing 45 changed files with 178 additions and 112 deletions.
72 changes: 69 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,81 @@ jobs:
run: ./gradlew clean build

- name: Perform publish
run: ./gradlew publish
run: ./gradlew publish -PreleaseBundle=all
env:
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.FLAMINGOCK_JRELEASER_MAVENCENTRAL_USERNAME }}
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.FLAMINGOCK_JRELEASER_MAVENCENTRAL_PASSWORD }}

- name: Release to Maven Central portal
- name: Release core projects to Maven Central portal
run: |
for i in {1..3}; do
if ./gradlew jreleaserFullRelease --no-daemon --stacktrace; then
if ./gradlew jreleaserFullRelease -PreleaseBundle=core --no-daemon --stacktrace; then
exit 0
fi
if [ $i -eq 3 ]; then
echo "Failed release after 3 attempts"
exit 1
fi
echo
echo "********************************************************************************** RELEASE ATTEMPT($((i + 1))) **********************************************************************************"
sleep 5
done
env:
JRELEASER_GITHUB_TOKEN: ${{ secrets.FLAMINGOCK_JRELEASER_GITHUB_TOKEN }}
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.FLAMINGOCK_JRELEASER_MAVENCENTRAL_USERNAME }}
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.FLAMINGOCK_JRELEASER_MAVENCENTRAL_PASSWORD }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_PASSPHRASE }}

- name: Release driver projects to Maven Central portal
run: |
for i in {1..3}; do
if ./gradlew jreleaserFullRelease -PreleaseBundle=driver --no-daemon --stacktrace; then
exit 0
fi
if [ $i -eq 3 ]; then
echo "Failed release after 3 attempts"
exit 1
fi
echo
echo "********************************************************************************** RELEASE ATTEMPT($((i + 1))) **********************************************************************************"
sleep 5
done
env:
JRELEASER_GITHUB_TOKEN: ${{ secrets.FLAMINGOCK_JRELEASER_GITHUB_TOKEN }}
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.FLAMINGOCK_JRELEASER_MAVENCENTRAL_USERNAME }}
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.FLAMINGOCK_JRELEASER_MAVENCENTRAL_PASSWORD }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_PASSPHRASE }}

- name: Release template projects to Maven Central portal
run: |
for i in {1..3}; do
if ./gradlew jreleaserFullRelease -PreleaseBundle=template --no-daemon --stacktrace; then
exit 0
fi
if [ $i -eq 3 ]; then
echo "Failed release after 3 attempts"
exit 1
fi
echo
echo "********************************************************************************** RELEASE ATTEMPT($((i + 1))) **********************************************************************************"
sleep 5
done
env:
JRELEASER_GITHUB_TOKEN: ${{ secrets.FLAMINGOCK_JRELEASER_GITHUB_TOKEN }}
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.FLAMINGOCK_JRELEASER_MAVENCENTRAL_USERNAME }}
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.FLAMINGOCK_JRELEASER_MAVENCENTRAL_PASSWORD }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_PASSPHRASE }}

- name: Release transactioner projects to Maven Central portal
run: |
for i in {1..3}; do
if ./gradlew jreleaserFullRelease -PreleaseBundle=transactioner --no-daemon --stacktrace; then
exit 0
fi
if [ $i -eq 3 ]; then
Expand Down
73 changes: 45 additions & 28 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,53 +28,81 @@ plugins {

allprojects {
group = "io.flamingock"
version = "0.0.12-beta"
version = "0.0.13-beta"

apply(plugin = "org.jetbrains.kotlin.jvm")

}

val projectsToRelease = setOf(
val coreProjects = setOf(
"flamingock-core",
"flamingock-core-api",
"flamingock-core-template",
"flamingock-springboot-v2-runner",
"flamingock-springboot-v3-runner",
"utils"
)

val localDriverProjects = setOf(
"driver-common",
"couchbase-driver",
"couchbase-springboot-v2-driver",
"dynamodb-driver",
"mongodb-facade",
"mongodb-springdata-v2-driver",
"mongodb-springdata-v3-driver",
"mongodb-springdata-v4-driver",
"mongodb-sync-v4-driver",
"mongodb-v3-driver",
"mongodb-v3-driver"
)

val templateProjects = setOf(
"sql-template",
"sql-springboot-template",
"sql-springboot-template"
)


val transactionerProjects = setOf(
"sql-cloud-transactioner"
)

val allProjects = coreProjects + localDriverProjects + templateProjects + transactionerProjects

val projectNameMaxLength = projectsToRelease.maxOf { it.length }

val projectNameMaxLength = coreProjects.maxOf { it.length }
val tabWidth = 8 //Usually 8 spaces)
val statusPosition = ((projectNameMaxLength / tabWidth) + 1) * tabWidth

val httpClient: HttpClient = HttpClient.newHttpClient()
val mavenUsername: String? = System.getenv("JRELEASER_MAVENCENTRAL_USERNAME")
val mavenPassword: String? = System.getenv("JRELEASER_MAVENCENTRAL_PASSWORD")
val encodedCredentials: String? = if(mavenUsername != null && mavenPassword != null)Base64.getEncoder()
val encodedCredentials: String? = if (mavenUsername != null && mavenPassword != null) Base64.getEncoder()
.encodeToString("$mavenUsername:$mavenPassword".toByteArray()) else null
val releaseBundle: String? = project.findProperty("releaseBundle") as String?
val projectsToRelease = when(releaseBundle) {
"core" -> coreProjects
"driver" -> localDriverProjects
"template" -> templateProjects
"transactioner" -> transactionerProjects
"all" -> allProjects
else -> setOf()
}


val isReleasing = getIsReleasing()

if(isReleasing) {
logger.lifecycle("Release bundle: $releaseBundle")
}

subprojects {
apply(plugin = "java-library")


val tabsPrefix = getTabsPrefix()
if(isReleasing) {
if (isReleasing) {
if (project.isReleasable()) {
if(!project.getIfAlreadyReleasedFromCentralPortal()) {
logger.lifecycle("${project.name}${tabsPrefix}[ \uD83D\uDE80 PUBLISHING ]")
if (!project.getIfAlreadyReleasedFromCentralPortal()) {
logger.lifecycle("${project.name}${tabsPrefix}\uD83D\uDE80 PUBLISHING")
java {
withSourcesJar()
withJavadocJar()
Expand Down Expand Up @@ -219,10 +247,10 @@ subprojects {
}
}
} else {
logger.lifecycle("${project.name}${tabsPrefix}[ ✅ ALREADY PUBLISHED ]")
logger.lifecycle("${project.name}${tabsPrefix}ALREADY PUBLISHED")
}
} else {
logger.lifecycle("${project.name}${tabsPrefix}[ \uD83D\uDCA4 NOT RELEASABLE ]")
logger.debug("${project.name}${tabsPrefix}\uD83D\uDCA4 NOT RELEASABLE")
}
}

Expand Down Expand Up @@ -278,14 +306,10 @@ subprojects {

fun Project.isReleasable(): Boolean = projectsToRelease.contains(name)

fun Project.getIfAlreadyReleasedFromCentralPortal() : Boolean {
fun Project.getIfAlreadyReleasedFromCentralPortal(): Boolean {
val url = "https://central.sonatype.com/api/v1/publisher/published?namespace=${group}&name=$name&version=$version"
val request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("accept", "application/json")
.header("Authorization", "Basic $encodedCredentials")
.GET()
.build()
val request = HttpRequest.newBuilder().uri(URI.create(url)).header("accept", "application/json")
.header("Authorization", "Basic $encodedCredentials").GET().build()


val response = httpClient.send(request, HttpResponse.BodyHandlers.ofString())
Expand All @@ -307,13 +331,6 @@ fun Project.getIfAlreadyReleasedFromCentralPortal() : Boolean {
}


fun getTabsPrefix(): String {
val currentPosition = project.name.length
val tabsNeeded = ((statusPosition - currentPosition + tabWidth - 1) / tabWidth) + 1
return "\t".repeat(tabsNeeded)
}


val String.isPalindrome: Boolean
get() = this == this.reversed()

Expand All @@ -323,5 +340,5 @@ fun Project.getTabsPrefix(): String {
return "\t".repeat(tabsNeeded)
}

fun Project.getIsReleasing() = gradle.startParameter.taskNames.contains("jreleaserFullRelease") ||
gradle.startParameter.taskNames.contains("publish")
fun Project.getIsReleasing() =
gradle.startParameter.taskNames.contains("jreleaserFullRelease") || gradle.startParameter.taskNames.contains("publish")
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
val jacksonVersion = "2.16.0"
dependencies {
api(project(":utils"))
api(project(":flamingock-core-api"))
implementation(project(":utils"))
implementation(project(":flamingock-core-api"))

implementation("org.mongodb:mongodb-driver-sync:4.3.3")
implementation(project(":flamingock-core"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package flamingock.internal.legacy.importer.mongodb;
package io.flamingock.importer.cloud.mongodb;

import io.flamingock.commons.utils.http.Http;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package flamingock.internal.legacy.importer.mongodb;
package io.flamingock.importer.cloud.mongodb;

import io.flamingock.commons.utils.id.EnvironmentId;
import io.flamingock.commons.utils.id.ServiceId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package flamingock.internal.legacy.importer.mongodb;
package io.flamingock.importer.cloud.mongodb;

import io.flamingock.core.api.CloudSystemModule;
import io.flamingock.core.runtime.dependency.Dependency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
* limitations under the License.
*/

package flamingock.internal.legacy.importer.mongodb;
package io.flamingock.importer.cloud.mongodb;


import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import io.changock.migration.api.annotations.NonLockGuarded;
import io.flamingock.commons.utils.JsonObjectMapper;
import io.flamingock.commons.utils.RunnerId;
import io.flamingock.commons.utils.http.Http;
import io.flamingock.core.api.annotations.ChangeUnit;
import io.flamingock.core.api.annotations.Execution;
import io.flamingock.core.api.annotations.NonLockGuarded;
import io.flamingock.core.api.annotations.SystemChange;
import org.apache.http.impl.client.HttpClients;
import org.bson.Document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

package io.flamingock.cloud.transaction.sql.changes.happypath;

import io.changock.migration.api.annotations.NonLockGuarded;

import io.flamingock.core.api.annotations.ChangeUnit;
import io.flamingock.core.api.annotations.Execution;
import io.flamingock.core.api.annotations.NonLockGuarded;

import java.sql.Connection;
import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.flamingock.cloud.transaction.sql.changes.happypath;

import io.changock.migration.api.annotations.NonLockGuarded;
import io.flamingock.core.api.annotations.NonLockGuarded;
import io.flamingock.core.api.annotations.ChangeUnit;
import io.flamingock.core.api.annotations.Execution;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.flamingock.cloud.transaction.sql.changes.unhappypath;

import io.changock.migration.api.annotations.NonLockGuarded;
import io.flamingock.core.api.annotations.NonLockGuarded;
import io.flamingock.core.api.annotations.ChangeUnit;
import io.flamingock.core.api.annotations.Execution;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.flamingock.cloud.transaction.sql.changes.unhappypath;

import io.changock.migration.api.annotations.NonLockGuarded;
import io.flamingock.core.api.annotations.NonLockGuarded;
import io.flamingock.core.api.annotations.ChangeUnit;
import io.flamingock.core.api.annotations.Execution;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies {
implementation("com.mysql:mysql-connector-j:8.2.0")
implementation(project(":templates:sql-template"))

implementation(project(":internal:legacy-importer-mongodb"))
implementation(project(":cloud-importers:mongodb-sync4-cloud-importer"))

implementation(project(":local-drivers:mongodb:mongodb-sync-v4-driver"))
implementation("org.mongodb:mongodb-driver-sync:$mongodbVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import flamingock.internal.legacy.importer.mongodb.MongoDBLegacyImporter;
import io.flamingock.importer.cloud.mongodb.MongoDBLegacyImporter;
import io.flamingock.core.configurator.standalone.FlamingockStandalone;
import org.bson.codecs.configuration.CodecRegistries;
import org.bson.codecs.configuration.CodecRegistry;
Expand Down Expand Up @@ -51,9 +51,6 @@ public void run(MongoClient mongoClient, String databaseName) throws ClassNotFou
.setEnvironment(ENVIRONMENT)
.setService(SERVICE_NAME)
.addSystemModule(new MongoDBLegacyImporter(MONGODB_CHANGELOG_COLLECTION))
.setLockAcquiredForMillis(6 * 1000L)//this is just to show how is set. Default value is still 60 * 1000L
.setLockQuitTryingAfterMillis(10 * 1000L)//this is just to show how is set. Default value is still 3 * 60 * 1000L
.setLockTryFrequencyMillis(3000L)//this is just to show how is set. Default value is still 1000L
.addDependency(mongoClient.getDatabase(databaseName))
.build()
.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import flamingock.internal.legacy.importer.mongodb.MongoDBLegacyImporter;
import flamingock.internal.legacy.importer.mongodb.MongockLegacyImporterChangeUnit;
import io.flamingock.importer.cloud.mongodb.MongoDBLegacyImporter;
import io.flamingock.importer.cloud.mongodb.MongockLegacyImporterChangeUnit;
import io.flamingock.common.test.cloud.AuditEntryExpectation;
import io.flamingock.common.test.cloud.MockRunnerServer;
import io.flamingock.common.test.cloud.MongockLegacyAuditEntry;
Expand Down
2 changes: 1 addition & 1 deletion examples/databases/mysql-standalone/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
implementation("com.mysql:mysql-connector-j:8.2.0")
implementation(project(":templates:sql-template"))

implementation(project(":internal:legacy-importer-mongodb"))
implementation(project(":cloud-importers:mongodb-sync4-cloud-importer"))

implementation("org.slf4j:slf4j-simple:2.0.6")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.flamingock.examples.mysql.standalone;

import flamingock.internal.legacy.importer.mongodb.MongoDBLegacyImporter;
import io.flamingock.cloud.transaction.sql.SqlCloudTransactioner;
import io.flamingock.cloud.transaction.sql.SqlDialect;
import io.flamingock.core.cloud.transaction.CloudTransactioner;
Expand Down
3 changes: 0 additions & 3 deletions flamingock-core-cloud-api/build.gradle.kts

This file was deleted.

File renamed without changes.
3 changes: 1 addition & 2 deletions flamingock-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
val jacksonVersion = "2.16.0"
dependencies {
api(project(":flamingock-core-api"))
api(project(":flamingock-core-cloud-api"))
api(project(":flamingock-template"))
api(project(":flamingock-core-template"))
api(project(":utils"))
api("javax.inject:javax.inject:1")
api("org.reflections:reflections:0.10.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down
Loading

0 comments on commit 483d5c4

Please sign in to comment.