diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..60131bd --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,48 @@ +name: Publish + +on: + release: + types: [ created ] + +env: + JAVA_VERSION: 17 + JAVA_DISTRO: 'temurin' + +jobs: + publish: + name: Publish to GitHub Packages + runs-on: macos-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout code + uses: actions/checkout@v7 + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v6 + + - name: Set up JDK 17 + uses: actions/setup-java@v6 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DISTRO }} + + - name: Set up gradle + uses: gradle/actions/setup-gradle@v6 + + - name: Publish to GitHub Packages + run: ./gradlew publishAllPublicationsToGitHubPackagesRepository --no-configuration-cache + env: + GITHUB_ACTOR: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_TAG: ${{ github.event.release.tag_name }} + + - name: Upload build reports + if: failure() + uses: actions/upload-artifact@v7 + with: + name: build-reports + path: '**/build/reports/' + retention-days: 7 diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 2906157..61019d9 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -6,6 +6,7 @@ dependencies { compileOnly(libs.androidx.gradle) compileOnly(libs.kotlin.gradle) compileOnly(libs.compose.compiler.gradle) + compileOnly(libs.vanniktech.maven.publish.gradle) implementation(libs.spotless.gradle) } @@ -35,5 +36,9 @@ gradlePlugin { id = "cfw.sample.common.deps" implementationClass = "SampleCommonDepsConventionPlugin" } + register("mavenPublish") { + id = "cfw.maven.publish" + implementationClass = "MavenPublishConventionPlugin" + } } } diff --git a/build-logic/convention/src/main/kotlin/MavenPublishConventionPlugin.kt b/build-logic/convention/src/main/kotlin/MavenPublishConventionPlugin.kt new file mode 100644 index 0000000..d24b1ca --- /dev/null +++ b/build-logic/convention/src/main/kotlin/MavenPublishConventionPlugin.kt @@ -0,0 +1,14 @@ +import cfw.buildlogic.configureMavenPublish +import org.gradle.api.Plugin +import org.gradle.api.Project + +@Suppress("unused") +class MavenPublishConventionPlugin : Plugin { + override fun apply(target: Project) { + with(target) { + pluginManager.apply("com.vanniktech.maven.publish") + + configureMavenPublish() + } + } +} diff --git a/build-logic/convention/src/main/kotlin/cfw/buildlogic/MavenPublish.kt b/build-logic/convention/src/main/kotlin/cfw/buildlogic/MavenPublish.kt new file mode 100644 index 0000000..12e8454 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/cfw/buildlogic/MavenPublish.kt @@ -0,0 +1,52 @@ +package cfw.buildlogic + +import com.vanniktech.maven.publish.MavenPublishBaseExtension +import org.gradle.api.Project +import org.gradle.api.publish.PublishingExtension +import org.gradle.kotlin.dsl.configure + +internal fun Project.configureMavenPublish() { + version = providers.environmentVariable("RELEASE_TAG") + .map { it.removePrefix("v") } + .getOrElse("1.0.0") + + extensions.configure { + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/ArthurKun21/compose-overlay-window") + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } + } + + extensions.configure { + pom { + url.set("https://github.com/ArthurKun21/compose-overlay-window") + + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + + developers { + developer { + id.set("ArthurKun21") + name.set("Arthur") + email.set("16458204+ArthurKun21@users.noreply.github.com") + } + } + + scm { + connection.set("scm:git:git://github.com/ArthurKun21/compose-overlay-window.git") + developerConnection.set("scm:git:ssh://github.com/ArthurKun21/compose-overlay-window.git") + url.set("https://github.com/ArthurKun21/compose-overlay-window") + } + } + } +} diff --git a/build.gradle.kts b/build.gradle.kts index 5da5194..80758fc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,4 +7,5 @@ plugins { alias(libs.plugins.spotless) apply false alias(libs.plugins.ksp) apply false alias(libs.plugins.hilt.android) apply false + alias(libs.plugins.vanniktech.maven.publish) apply false } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e2a416e..7ad1442 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -26,6 +26,8 @@ datastore = "1.2.1" spotless = "8.10.2" ktlint-core = "1.8.0" +vanniktech-maven-publish = "0.37.0" + [libraries] androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "android-core-ktx" } appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" } @@ -72,6 +74,8 @@ compose-compiler-gradle = { module = "org.jetbrains.kotlin:compose-compiler-grad spotless-gradle = { group = "com.diffplug.spotless", name = "spotless-plugin-gradle", version.ref = "spotless" } +vanniktech-maven-publish-gradle = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "vanniktech-maven-publish" } + [plugins] kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } agp = { id = "com.android.application", version.ref = "agp" } @@ -82,6 +86,7 @@ ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } spotless = { id = "com.diffplug.spotless", version.ref = "spotless" } +vanniktech-maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktech-maven-publish" } [bundles] datastore = ["datastore", "datastore-preferences"] diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 140acfb..0ef5539 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -1,7 +1,7 @@ plugins { - `maven-publish` id("cfw.library") id("cfw.library.tests") + id("cfw.maven.publish") } android { @@ -16,16 +16,8 @@ android { ) } } - publishing { - singleVariant("release") { - withSourcesJar() - withJavadocJar() - } - } } -version = 1.0 - kotlin { explicitApi() @@ -51,14 +43,15 @@ dependencies { implementation(libs.google.material) } -publishing { - publications { - create("release") { - groupId = "com.github.only52607" - artifactId = "compose-floating-window" - afterEvaluate { - from(components["release"]) - } - } +mavenPublishing { + coordinates( + groupId = "com.github.ArthurKun21", + artifactId = "compose-floating-window", + version = version.toString(), + ) + + pom { + name.set("compose-floating-window") + description.set("Global Floating Window Framework based on Jetpack Compose") } }