Skip to content

Commit

Permalink
TECH: snapshot publish (#455)
Browse files Browse the repository at this point in the history
* TECH: snapshot publish: for experiment remove manually repository creation
* TECH: snapshot publish: refactor release publish code && prepare to publish to snapshot repo
* TECH: snapshot publish: fix version set error && setup pipeline choice params
* TECH: snapshot publish: rollback --no-parallel
* TECH: snapshot publish: code cleanup
* TECH: snapshot publish: add kaspresso prefix to version flag
  • Loading branch information
VladislavSumin authored Dec 16, 2022
1 parent c96b51d commit 8973e3e
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 232 deletions.
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()
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

0 comments on commit 8973e3e

Please sign in to comment.