Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TECH: snapshot publish #455

Merged
merged 6 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions .github/workflows/deploy_snapshots.yml

This file was deleted.

22 changes: 17 additions & 5 deletions .github/workflows/publication_maven.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
name: Publication to MavenCentral

on: workflow_dispatch
on:
workflow_dispatch:
inputs:
releaseType:
description: 'Release type'
required: true
type: choice
options:
- SonatypeReleases
- SonatypeSnapshots
version:
description: 'Version (for example 1.4.2-SNAPSHOT)'
required: true
type: string

jobs:
publication:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
Expand All @@ -27,14 +39,14 @@ jobs:
env:
OSSRH_USER: ${{ secrets.ossrh_user }}
OSSRH_PASSWORD: ${{ secrets.ossrh_password }}
OSSRH_STAGING_PROFILE_ID: ${{ secrets.ossrh_staging_profile_id }}
PGP_KEYID: ${{ secrets.pgp_keyid }}
PGP_KEY: ${{ secrets.pgp_key }}
PGP_PASSWORD: ${{ secrets.pgp_password }}
run: >
./gradlew publishRelease -Pkaspresso.ossrh.user=${OSSRH_USER}
./gradlew publishAllPublicationsTo${{ inputs.releaseType }}Repository
-Pkaspresso.version=${{ inputs.version }}
-Pkaspresso.ossrh.user=${OSSRH_USER}
-Pkaspresso.ossrh.password=${OSSRH_PASSWORD}
-Pkaspresso.ossrh.stagingProfileId=${OSSRH_STAGING_PROFILE_ID}
-Pkaspresso.pgp.keyid=${PGP_KEYID}
-Pkaspresso.pgp.key=${PGP_KEY}
-Pkaspresso.pgp.password=${PGP_PASSWORD}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import com.android.build.gradle.LibraryExtension
import com.kaspersky.kaspresso.publication.KotlinLibraryPublishExtension

plugins {
id("convention.publication-release")
id("convention.publication-base")
}

val publishExtension = extensions.create<KotlinLibraryPublishExtension>("publish")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
plugins {
`maven-publish`
id("convention.sonatype")
}

group = "com.kaspersky.android-components"

version = property("stableVersion") ?: error("stableVersion property not set")
version = property("kaspresso.version") ?: error("kaspresso.version property not set")

publishing.publications.withType<MavenPublication>().configureEach {
pom {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.kaspersky.kaspresso.publication.KotlinLibraryPublishExtension

plugins {
id("convention.publication-release")
id("convention.publication-base")
}

plugins.withId("kotlin") {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,69 +1,31 @@
import com.kaspersky.kaspresso.publication.CreateStagingRepositoryTask

plugins {
id("convention.publication-base")
signing
}

val ossrhUsername: Provider<String> = providers.gradleProperty("kaspresso.ossrh.user")
.forUseAtConfigurationTime()

val ossrhPassword: Provider<String> = providers.gradleProperty("kaspresso.ossrh.password")
.forUseAtConfigurationTime()

val ossrhStagingProfileId: Provider<String> = providers.gradleProperty("kaspresso.ossrh.stagingProfileId")
.forUseAtConfigurationTime()

val sonatypeRepoName = "SonatypeReleases"
val ossrhUsername = findProperty("kaspresso.ossrh.user")?.toString()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check that configuration cache is not broken here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use configuration cache. No, I'm don't check this point.
I think we check all places when we add configuration cache support

val ossrhPassword = findProperty("kaspresso.ossrh.password")?.toString()

val repositoryUrlOutputFilePath: Provider<RegularFile> = rootProject.layout.buildDirectory.file("sonatype-repo.id")

val createStagingRepositoryTask: TaskProvider<CreateStagingRepositoryTask> = with(rootProject.tasks) {
val createStagingTaskName = "createSonatypeStagingRepository"

try {
@Suppress("UNCHECKED_CAST")
named(createStagingTaskName) as TaskProvider<CreateStagingRepositoryTask>
} catch (e: UnknownTaskException) {
register<CreateStagingRepositoryTask>(createStagingTaskName) {
group = "publication"

stagingProfileId.set(ossrhStagingProfileId)
user.set(ossrhUsername)
password.set(ossrhPassword)
repositoryDescription.set("Release v.$version")
repositoryIdFile.set(repositoryUrlOutputFilePath)
}
}
}

tasks.withType<PublishToMavenRepository>().configureEach {

// https://docs.gradle.org/current/userguide/publishing_customization.html#sec:configuring_publishing_tasks
if (name.contains(sonatypeRepoName)) {
doFirst {

// no direct task access, because "cannot be cast to class CreateStagingRepositoryTask" for some reason
val repositoryUrl = repositoryUrlOutputFilePath.get().asFile.readText()
repository = repository.apply { setUrl(repositoryUrl) }
}
dependsOn(createStagingRepositoryTask)
}
}

val publishTask = tasks.register<Task>("publishToSonatype") {
group = "publication"

dependsOn(tasks.named("publishAllPublicationsTo${sonatypeRepoName}Repository"))
}
val sonatypeReleasesRepoName = "SonatypeReleases"
val sonatypeSnapshotsRepoName = "SonatypeSnapshots"

publishing {
repositories {
maven {
name = sonatypeRepoName
name = sonatypeReleasesRepoName
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = ossrhUsername.orNull
password = ossrhPassword.orNull
username = ossrhUsername
password = ossrhPassword
}
}

maven {
name = sonatypeSnapshotsRepoName
setUrl("https://s01.oss.sonatype.org/content/repositories/snapshots/")
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
}
Expand All @@ -72,23 +34,17 @@ publishing {
signing {
sign(publishing.publications)

val signingKeyId = providers.gradleProperty("kaspresso.pgp.keyid")
.forUseAtConfigurationTime()
.orNull
val signingKey = providers.gradleProperty("kaspresso.pgp.key")
.forUseAtConfigurationTime()
.orNull
val signingPassword = providers.gradleProperty("kaspresso.pgp.password")
.forUseAtConfigurationTime()
.orNull
val signingKeyId = findProperty("kaspresso.pgp.keyid")?.toString()
val signingKey = findProperty("kaspresso.pgp.key")?.toString()
val signingPassword = findProperty("kaspresso.pgp.password")?.toString()

useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
}

tasks.withType<Sign>().configureEach {
onlyIf {
gradle.taskGraph.hasTask(publishTask.get())
val isReleaseQueued = gradle.taskGraph.hasTask("publishAllPublicationsTo${sonatypeReleasesRepoName}Repository")
val isSnapshotQueued = gradle.taskGraph.hasTask("publishAllPublicationsTo${sonatypeSnapshotsRepoName}Repository")
isReleaseQueued || isSnapshotQueued
}
}

fun String?.toFile() = if (this.isNullOrBlank()) null else File(this)
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ kotlin.code.style=official

android.useAndroidX = true

stableVersion=1.4.2
snapshotVersion=1.4.3-SNAPSHOT
kaspresso.version=1.4.2