Skip to content

Commit

Permalink
publishing to github?
Browse files Browse the repository at this point in the history
  • Loading branch information
osoykan committed May 3, 2024
1 parent 2c02d18 commit b437c38
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 60 deletions.
1 change: 1 addition & 0 deletions .github/workflows/gradle-publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ jobs:
gpg_passphrase: ${{ secrets.gpg_passphrase }}
nexus_username: ${{ secrets.nexus_username }}
nexus_password: ${{ secrets.nexus_password }}
bot_repo_token: ${{ secrets.bot_repo_token }}
1 change: 1 addition & 0 deletions .github/workflows/gradle-publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ jobs:
gpg_passphrase: ${{ secrets.gpg_passphrase }}
nexus_username: ${{ secrets.nexus_username }}
nexus_password: ${{ secrets.nexus_password }}
bot_repo_token: ${{ secrets.bot_repo_token }}
128 changes: 68 additions & 60 deletions buildSrc/src/main/kotlin/stove-publishing.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,77 +1,85 @@
plugins {
`maven-publish`
signing
java
`maven-publish`
signing
java
}
fun getProperty(
projectKey: String,
environmentKey: String
projectKey: String,
environmentKey: String
): String? {
return if (project.hasProperty(projectKey)) {
project.property(projectKey) as? String?
} else {
System.getenv(environmentKey)
}
return if (project.hasProperty(projectKey)) {
project.property(projectKey) as? String?
} else {
System.getenv(environmentKey)
}
}

publishing {
publications {
create<MavenPublication>("publish-${project.name}") {
groupId = rootProject.group.toString()
version = rootProject.version.toString()
artifactId = project.name
from(components["java"])
pom {
name.set(project.name)
description.set(project.properties["projectDescription"].toString())
url.set(project.properties["projectUrl"].toString())
packaging = "jar"
licenses {
license {
name.set(project.properties["licence"].toString())
url.set(project.properties["licenceUrl"].toString())
}
}
developers {
developer {
id.set("osoykan")
name.set("Oguzhan Soykan")
email.set("[email protected]")
}
}
scm {
connection.set("scm:[email protected]:Trendyol/stove.git")
developerConnection.set("scm:git:ssh://github.com:Trendyol/stove.git")
url.set(project.properties["projectUrl"].toString())
}
}
publications {
create<MavenPublication>("publish-${project.name}") {
groupId = rootProject.group.toString()
version = rootProject.version.toString()
artifactId = project.name
from(components["java"])
pom {
name.set(project.name)
description.set(project.properties["projectDescription"].toString())
url.set(project.properties["projectUrl"].toString())
packaging = "jar"
licenses {
license {
name.set(project.properties["licence"].toString())
url.set(project.properties["licenceUrl"].toString())
}
}
developers {
developer {
id.set("osoykan")
name.set("Oguzhan Soykan")
email.set("[email protected]")
}
}
scm {
connection.set("scm:[email protected]:Trendyol/stove.git")
developerConnection.set("scm:git:ssh://github.com:Trendyol/stove.git")
url.set(project.properties["projectUrl"].toString())
}
}
}
}

repositories {
maven {
val releasesRepoUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
val snapshotsRepoUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/")
url = if (rootProject.version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
// url = rootProject.buildDir.resolve("publications").toURI()
credentials {
username = getProperty("nexus_username", "nexus_username")
password = getProperty("nexus_password", "nexus_password")
}
}
repositories {
maven {
val releasesRepoUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
val snapshotsRepoUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/")
url = if (rootProject.version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
// url = rootProject.buildDir.resolve("publications").toURI()
credentials {
username = getProperty("nexus_username", "nexus_username")
password = getProperty("nexus_password", "nexus_password")
}
}
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/trendyol/stove")
credentials {
username = "trendyol-bot"
password = getProperty("BOT_REPO_TOKEN", "BOT_REPO_TOKEN")
}
}
}
}

val signingKey = getProperty(projectKey = "gpg.key", environmentKey = "gpg_private_key")
val passPhrase = getProperty(projectKey = "gpg.passphrase", environmentKey = "gpg_passphrase")
signing {
if (passPhrase == null) {
logger.warn(
"The passphrase for the signing key was not found. " +
"Either provide it as env variable 'gpg_passphrase' or " +
"as project property 'gpg_passphrase'. Otherwise the signing might fail!"
)
}
useInMemoryPgpKeys(signingKey, passPhrase)
sign(publishing.publications)
if (passPhrase == null) {
logger.warn(
"The passphrase for the signing key was not found. " +
"Either provide it as env variable 'gpg_passphrase' or " +
"as project property 'gpg_passphrase'. Otherwise the signing might fail!"
)
}
useInMemoryPgpKeys(signingKey, passPhrase)
sign(publishing.publications)
}

0 comments on commit b437c38

Please sign in to comment.