From 17242c7a410d45e2ea5f214e2f0730a1002683db Mon Sep 17 00:00:00 2001 From: Chris Jenkins Date: Mon, 21 Oct 2024 15:30:03 -0600 Subject: [PATCH] setup workflow to deploy on release --- .github/workflows/deploy-to-github.yml | 24 +++++++++++++++++ README.MD | 22 ++++++--------- build.gradle.kts | 37 +++++++++++++++++++++----- gradle.properties | 15 +++++++++++ gradle/libs.versions.toml | 2 +- library/build.gradle.kts | 3 +-- library/gradle.properties | 3 +++ 7 files changed, 82 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/deploy-to-github.yml create mode 100644 library/gradle.properties diff --git a/.github/workflows/deploy-to-github.yml b/.github/workflows/deploy-to-github.yml new file mode 100644 index 0000000..dd37b0d --- /dev/null +++ b/.github/workflows/deploy-to-github.yml @@ -0,0 +1,24 @@ +name: Create and publish a release to Github Packages + +on: + workflow_dispatch: + release: + types: [published] # Will trigger on (pre)release creation + +jobs: + build-and-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Java JDK + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '21' + - name: Setup Gradle + uses: gradle/actions/setup-gradle + - name: Build and publish + run: ./gradlew publishAllPublicationsToGitHubPackagesRepository + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_VERSION: ${{ github.event.release.tag_name }} \ No newline at end of file diff --git a/README.MD b/README.MD index 943200c..d2bbae3 100644 --- a/README.MD +++ b/README.MD @@ -10,7 +10,7 @@ SQLite and JSONB. ```kotlin // Create a new instance of Sqkon val sqkon = Sqkon( - context = context // (only for Android) + context = context // (only for Android) ) // Create a Store for each type/entity you want to create @@ -43,21 +43,15 @@ data class Merchant( **TODO PUBLISH TO MAVEN CENTRAL GH ACTIONS** -1) Registering a Sonatype account as described here: - https://dev.to/kotlin/how-to-build-and-publish-a-kotlin-multiplatform-library-going-public-4a8k -2) Add developer id, name, email and the project url to - `/convention-plugins/src/main/kotlin/convention.publication.gradle.kts` -3) Add the secrets to `local.properties`: +### Publish to github packages -``` -signing.keyId=... -signing.password=... -signing.secretKeyRingFile=... -ossrhUsername=... -ossrhPassword=... -``` +Creating a new release will publish the artifacts to GitHub Packages. + +If publishing locally you will need `GITHUB_ACTOR` and `GITHUB_TOKEN` environment variables set with +repository write permissions. + +`./gradlew publishToGitHubPackages` -4) Run `./gradlew :core:publishAllPublicationsToSonatypeRepository` ### Build platform artifacts diff --git a/build.gradle.kts b/build.gradle.kts index 173d733..02863c1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,18 +1,41 @@ +import com.vanniktech.maven.publish.MavenPublishPlugin + plugins { alias(libs.plugins.multiplatform).apply(false) alias(libs.plugins.android.library).apply(false) alias(libs.plugins.kotlinx.serialization).apply(false) alias(libs.plugins.sqlDelight).apply(false) - alias(libs.plugins.axion.release) + alias(libs.plugins.maven.publish) } -scmVersion { - nextVersion { suffix.set("alpha") } - versionCreator("versionWithCommitHash") +allprojects { + group = findProperty("GROUP").toString() + version = System.getenv("RELEASE_VERSION")?.takeIf { it.isNotBlank() } + ?: findProperty("VERSION_NAME").toString() } -version = scmVersion.version - subprojects { - project.version = rootProject.version + plugins.withType().configureEach { + extensions.findByType()?.also { publishing -> + logger.lifecycle("Publishing ${project.group}:${project.name}:${project.version}") + publishing.repositories { + // GitHub Packages + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/MercuryTechnologies/sqkon") + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } + } + } } + +tasks.register("version") { + notCompatibleWithConfigurationCache("Version task is not compatible with configuration cache") + doLast { + println("Version: $version") + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 2b84000..e3584f3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,6 +5,21 @@ org.gradle.configuration-cache=true org.gradle.daemon=true org.gradle.parallel=true +# Maven +GROUP=com.mercury.sqkon +VERSION_NAME=1.0.0-alpha01 +POM_NAME=Sqkon +POM_INCEPTION_YEAR=2024 +POM_URL=https://github.com/MercuryTechnologies/sqkon/ +POM_LICENSE_NAME=The Apache Software License, Version 2.0 +POM_LICENSE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt +POM_LICENSE_DIST=repo +POM_SCM_URL=https://github.com/MercuryTechnologies/sqkon/ +POM_SCM_CONNECTION=scm:git:git://github.com/MercuryTechnologies/sqkon.git +POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/MercuryTechnologies/sqkon.git +POM_DEVELOPER_NAME=MercuryTechnologies +POM_DEVELOPER_URL=https://github.com/MercuryTechnologies/ + #Kotlin kotlin.code.style=official kotlin.daemon.jvmargs=-Xmx4G diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bbba167..f2bc1d0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -26,7 +26,7 @@ sqlDelight-driver-js = { module = "app.cash.sqldelight:web-worker-driver", versi [plugins] android-library = { id = "com.android.library", version.ref = "agp" } -axion-release = { id = "pl.allegro.tech.build.axion-release", version = "1.18.12" } +maven-publish = { id = "com.vanniktech.maven.publish", version = "0.30.0" } multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } sqlDelight = { id = "app.cash.sqldelight", version.ref = "sqlDelight" } diff --git a/library/build.gradle.kts b/library/build.gradle.kts index b0e98ce..7602249 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -3,10 +3,9 @@ plugins { alias(libs.plugins.android.library) alias(libs.plugins.kotlinx.serialization) alias(libs.plugins.sqlDelight) + alias(libs.plugins.maven.publish) } -group = "com.mercury.sqkon" - kotlin { applyDefaultHierarchyTemplate() jvmToolchain(11) diff --git a/library/gradle.properties b/library/gradle.properties new file mode 100644 index 0000000..34459e4 --- /dev/null +++ b/library/gradle.properties @@ -0,0 +1,3 @@ +POM_ARTIFACT_ID=library +POM_NAME=Library +POM_DESCRIPTION=Core library for Sqkon, includes runtime and code used to make sqkon work.