Skip to content

Commit

Permalink
Adding release configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
orchestr7 committed Feb 9, 2024
1 parent 4483a47 commit 0c5101b
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 249 deletions.
45 changes: 0 additions & 45 deletions .github/workflows/publish-macosArm64.yml

This file was deleted.

92 changes: 29 additions & 63 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,83 +7,49 @@ on:

env:
GRADLE_OPTS: -Dorg.gradle.daemon=true -Dorg.gradle.parallel=true -Dorg.gradle.welcome=never
GPG_SEC: ${{ secrets.PGP_SEC }}
GPG_PASSWORD: ${{ secrets.PGP_PASSWORD }}
PGP_SEC: ${{ secrets.PGP_SEC }}
PGP_PASSWORD: ${{ secrets.PGP_PASSWORD }}
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
release:
name: 'Release'
name: Build release
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]

os: [ macos-latest ]
steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
with:
# Fetch Git tags, so that semantic version can be calculated.
# Alternatively, run `git fetch --prune --unshallow --tags` as the
# next step, see
# https://github.com/actions/checkout/issues/206#issuecomment-607496604.
# release workflow should have access to all tags
fetch-depth: 0

- name: 'Set up Java 17'
uses: actions/setup-java@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 17
java-version: 11
distribution: zulu
java-package: jdk+fx

- name: 'Cache ~/.konan'
id: cache-konan
uses: actions/cache@v4
with:
path: |
~/.konan
key: ${{ runner.os }}-konan-${{ hashFiles('**/*.gradle.kts', '**/gradle-wrapper.properties') }}-release
restore-keys: |
${{ runner.os }}-konan-${{ hashFiles('**/*.gradle.kts', '**/gradle-wrapper.properties') }}-
${{ runner.os }}-konan-
- name: 'Publish a release (Linux)'
id: publish-linux
if: ${{ runner.os == 'Linux' }}
uses: gradle/gradle-build-action@v3
with:
gradle-version: wrapper
arguments: |
build
publishJvmPublicationToGitHubRepository
publishKotlinMultiplatformPublicationToGitHubRepository
publishLinuxX64PublicationToGitHubRepository
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: 'Publish a release (Windows)'
id: publish-windows
if: ${{ runner.os == 'Windows' }}
uses: gradle/gradle-build-action@v3
- name: Status git before
run: git status
- uses: burrunan/gradle-cache-action@v1
with:
gradle-version: wrapper
arguments: |
build
publishMingwX64PublicationToGitHubRepository
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Until https://github.com/burrunan/gradle-cache-action/issues/42 is addressed, gradle should be run as a separate step
- name: gradle release from tag
# if workflow is triggered after push of a tag, deploy full release
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: ./gradlew
--console=rich
-Prelease
-PgprUser=${{ github.actor }}
-PgprKey=${{ secrets.GITHUB_TOKEN }}
publishToSonatype
- name: Status git after
if: ${{ always() }}
run: git status

- name: 'Publish a release (Mac OS X)'
id: publish-macosx
if: ${{ runner.os == 'macOS' }}
uses: gradle/gradle-build-action@v3
with:
gradle-version: wrapper
arguments: |
build
publishMacosX64PublicationToGitHubRepository
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

github_release:
needs: release
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/.run/
/.settings/
/build/
/gradle/plugins/.gradle/
/gradle/plugins/build/
146 changes: 5 additions & 141 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@
)

import com.saveourtool.buildutils.configureDetekt
import com.saveourtool.buildutils.configureSigning
import org.ajoberstar.reckon.gradle.ReckonCreateTagTask
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.gradle.internal.logging.text.StyledTextOutput
import org.gradle.internal.logging.text.StyledTextOutput.Style.Failure
import org.gradle.internal.logging.text.StyledTextOutput.Style.Success
import org.gradle.internal.logging.text.StyledTextOutputFactory
import org.gradle.kotlin.dsl.support.serviceOf
import org.jetbrains.kotlin.gradle.tasks.KotlinTest

plugins {
kotlin("multiplatform")
eclipse
`maven-publish`
signing
id("org.jetbrains.dokka") version "1.9.10"
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
id("io.gitlab.arturbosch.detekt")
id("org.cqfn.diktat.diktat-gradle-plugin") version "1.2.5"
id("com.saveourtool.diktat") version "2.0.0"
id("com.saveourtool.buildutils.publishing-configuration")
}

group = "com.saveourtool"
description = "A set of extensions to Okio"

configureSigning()

repositories {
mavenCentral()
}
Expand Down Expand Up @@ -92,142 +91,7 @@ tasks.withType<ReckonCreateTagTask> {
}

configureDetekt()
configurePublishing()

fun Project.configurePublishing() {
configureGitHubPublishing()
configurePublications()
configureSigning()
}

fun Project.configureGitHubPublishing() =
publishing {
repositories {
maven {
name = "GitHub"
url = uri("https://maven.pkg.github.com/saveourtool/okio-extras")
credentials {
username = findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR")
password = findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}
}

fun Project.configurePublications() {
val dokkaJar = tasks.create<Jar>("dokkaJar") {
group = "documentation"
archiveClassifier.set("javadoc")
from(tasks.findByName("dokkaHtml"))
}

configure<PublishingExtension> {
publications.withType<MavenPublication>().configureEach {
this.artifact(dokkaJar)
this.pom {
val project = this@configurePublications

name.set(project.name)
description.set(project.description ?: project.name)
url.set("https://github.com/saveourtool/${project.name}")
licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/license/MIT")
distribution.set("repo")
}
}
developers {
developer {
id.set("0x6675636b796f75676974687562")
name.set("Andrey Shcheglov")
email.set("shcheglov.av@phystech.edu")
}
}
scm {
url.set("https://github.com/saveourtool/${project.name}")
connection.set("scm:git:https://github.com/saveourtool/${project.name}.git")
developerConnection.set("scm:git:git@github.com:saveourtool/${project.name}.git")
}
}
}
}
}

/**
* Enables signing of the artifacts if the `signingKey` project property is set.
*
* Should be explicitly called after each custom `publishing {}` section.
*/
fun Project.configureSigning() {
System.getenv("GPG_SEC")?.let {
extra.set("signingKey", it)
}
System.getenv("GPG_PASSWORD")?.let {
extra.set("signingPassword", it)
}

if (hasProperty("signingKey")) {
/*
* GitHub Actions.
*/
configureSigningCommon {
useInMemoryPgpKeys(property("signingKey") as String?, findProperty("signingPassword") as String?)
}
} else if (
hasProperties(
"signing.keyId",
"signing.password",
"signing.secretKeyRingFile",
)
) {
/*-
* Pure-Java signing mechanism via `org.bouncycastle.bcpg`.
*
* Requires an 8-digit (short form) PGP key id and a present `~/.gnupg/secring.gpg`
* (for gpg 2.1, run
* `gpg --keyring secring.gpg --export-secret-keys >~/.gnupg/secring.gpg`
* to generate one).
*/
configureSigningCommon()
} else if (hasProperty("signing.gnupg.keyName")) {
/*-
* Use an external `gpg` executable.
*
* On Windows, you may need to additionally specify the path to `gpg` via
* `signing.gnupg.executable`.
*/
configureSigningCommon {
useGpgCmd()
}
}
}

/**
* @param useKeys the block which configures the PGP keys. Use either
* [SigningExtension.useInMemoryPgpKeys], [SigningExtension.useGpgCmd], or an
* empty lambda.
* @see SigningExtension.useInMemoryPgpKeys
* @see SigningExtension.useGpgCmd
*/
@Suppress(
"MaxLineLength",
"SpreadOperator",
)
fun Project.configureSigningCommon(useKeys: SigningExtension.() -> Unit = {}) {
configure<SigningExtension> {
useKeys()
val publications = extensions.getByType<PublishingExtension>().publications
val publicationCount = publications.size
val message = "The following $publicationCount publication(s) are getting signed: ${publications.map(Named::getName)}"
val style = when (publicationCount) {
0 -> Failure
else -> Success
}
styledOut(logCategory = "signing").style(style).println(message)
sign(*publications.toTypedArray())
}
}

fun Project.styledOut(logCategory: String): StyledTextOutput =
serviceOf<StyledTextOutputFactory>().create(logCategory)
Expand Down
Loading

0 comments on commit 0c5101b

Please sign in to comment.