Skip to content

Commit

Permalink
ci: manually publish to maven central
Browse files Browse the repository at this point in the history
and drop github package registry publication
  • Loading branch information
ObserverOfTime committed Apr 19, 2024
1 parent a5f6006 commit cfa7dc8
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 128 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ max_line_length = 120
[LICENSE]
max_line_length = off

[README.md]
indent_size = 2
max_line_length = off

[.editorconfig]
max_line_length = off

Expand Down
148 changes: 52 additions & 96 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,42 @@ concurrency:
cancel-in-progress: true
group: ${{github.workflow}}-${{github.ref_name}}

permissions:
packages: write
contents: read

jobs:
gpr:
build:
runs-on: ${{matrix.os}}
name: Publish ${{matrix.platform}} packages on GPR
name: Build ${{matrix.platform}} packages
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
platform: common
targets: >-
:kbigint:publishKotlinMultiplatformPublicationToGitHubRepository
:kbigint-serialization:publishKotlinMultiplatformPublicationToGitHubRepository
:kbigint:publishKotlinMultiplatformPublicationToLocalRepository
:kbigint-serialization:publishKotlinMultiplatformPublicationToLocalRepository
- os: ubuntu-latest
platform: JVM
targets: :kbigint:publishJvmPublicationToGitHubRepository
targets: :kbigint:publishJvmPublicationToLocalRepository
- os: ubuntu-latest
platform: Android
targets: :kbigint:publishAndroidReleasePublicationToGitHubRepository
targets: :kbigint:publishAndroidReleasePublicationToLocalRepository
- os: ubuntu-latest
platform: JS
target: :kbigint:publishJsPublicationToGitHubRepository
targets: :kbigint:publishJsPublicationToLocalRepository
- os: ubuntu-latest
platform: Linux
targets: >-
:kbigint:publishLinuxX64PublicationToGitHubRepository
:kbigint:publishLinuxArm64PublicationToGitHubRepository
:kbigint:publishLinuxX64PublicationToLocalRepository
:kbigint:publishLinuxArm64PublicationToLocalRepository
- os: windows-latest
platform: Windows
targets: :kbigint:publishMingwX64PublicationToGitHubRepository
targets: :kbigint:publishMingwX64PublicationToLocalRepository
- os: macos-14
platform: macOS/iOS
targets: >-
:kbigint:publishMacosX64PublicationToGitHubRepository
:kbigint:publishMacosArm64PublicationToGitHubRepository
:kbigint:publishIosArm64PublicationToGitHubRepository
:kbigint:publishMacosX64PublicationToLocalRepository
:kbigint:publishMacosArm64PublicationToLocalRepository
:kbigint:publishIosArm64PublicationToLocalRepository
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -83,91 +79,51 @@ jobs:
with:
path: ${{runner.tool_cache}}/konan/dependencies
key: konan-${{runner.os}}-dependencies
- name: Publish packages
run: ./gradlew --no-daemon --info ${{matrix.targets}}
- name: Build packages
run: ./gradlew --no-daemon ${{matrix.targets}}
env:
GITHUB_TOKEN: ${{github.token}}
SIGNING_KEY: ${{secrets.SIGNING_KEY}}
SIGNING_PASSWORD: ${{secrets.SIGNING_PASSWORD}}
KONAN_DATA_DIR: ${{runner.tool_cache}}/konan
central:
runs-on: ${{matrix.os}}
name: Publish ${{matrix.platform}} packages on Maven Central
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: kbigint-${{matrix.platform == 'macOS/iOS' && 'macOS-iOS' || matrix.platform}}
path: |
build/repo/**
!build/repo/**/maven-metadata.*
retention-days: 2
publish:
runs-on: ubuntu-latest
name: Publish packages on Maven Central
needs: [build]
environment:
name: sonatype
url: https://central.sonatype.com/artifact/io.github.observeroftime/kbigint
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
platform: common
targets: >-
:kbigint:publishKotlinMultiplatformPublicationToSonatypeRepository
:kbigint-serialization:publishKotlinMultiplatformPublicationToSonatypeRepository
- os: ubuntu-latest
platform: JVM
targets: :kbigint:publishJvmPublicationToSonatypeRepository
- os: ubuntu-latest
platform: Android
targets: :kbigint:publishAndroidReleasePublicationToSonatypeRepository
- os: ubuntu-latest
platform: JS
target: :kbigint:publishJsPublicationToSonatypeRepository
- os: ubuntu-latest
platform: Linux
targets: >-
:kbigint:publishLinuxX64PublicationToSonatypeRepository
:kbigint:publishLinuxArm64PublicationToSonatypeRepository
- os: windows-latest
platform: Windows
targets: :kbigint:publishMingwX64PublicationToSonatypeRepository
- os: macos-14
platform: macOS/iOS
targets: >-
:kbigint:publishMacosX64PublicationToSonatypeRepository
:kbigint:publishMacosArm64PublicationToSonatypeRepository
:kbigint:publishIosArm64PublicationToSonatypeRepository
url: https://central.sonatype.com/artifact/io.github.observeroftime.kbigint/kbigint
env:
SONATYPE_API: https://central.sonatype.com/api/v1/publisher
SONATYPE_AUTH: "Authorization: Bearer ${{secrets.SONATYPE_TOKEN}}"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
submodules: true
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: gradle
cache-dependency-path: |
gradle/libs.versions.toml
gradle/wrapper/gradle-wrapper.properties
- name: Set up cross compilation
run: sudo apt-get install -qy {binutils,gcc}-aarch64-linux-gnu
if: matrix.platform == 'Linux' || matrix.platform == 'common'
- name: Get the cache versions
id: versions
shell: sh
path: kbigint
pattern: kbigint-*
merge-multiple: true
- name: Upload bundle
run: |-
{
sed -n 's/kotlin-stdlib = "\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)"/kotlin=\1.\2.\3/p' gradle/libs.versions.toml
} >> "$GITHUB_OUTPUT"
- name: Restore Kotlin/Native prebuilt
uses: actions/cache/restore@v4
with:
path: ${{runner.tool_cache}}/konan/kotlin-native-prebuilt-*
key: konan-${{runner.os}}-prebuilt-${{steps.versions.outputs.kotlin}}
- name: Restore Kotlin/Native dependencies
uses: actions/cache/restore@v4
if: matrix.platform != 'JVM' && matrix.platform != 'Android' && matrix.platform != 'JS'
with:
path: ${{runner.tool_cache}}/konan/dependencies
key: konan-${{runner.os}}-dependencies
- name: Publish packages
run: ./gradlew --no-daemon --info ${{matrix.targets}}
env:
SIGNING_KEY: ${{secrets.SIGNING_KEY}}
SIGNING_PASSWORD: ${{secrets.SIGNING_PASSWORD}}
SONATYPE_USERNAME: ${{secrets.SONATYPE_USERNAME}}
SONATYPE_PASSWORD: ${{secrets.SONATYPE_PASSWORD}}
KONAN_DATA_DIR: ${{runner.tool_cache}}/konan
url="$SONATYPE_API/upload?publishingType=USER_MANAGED"
(cd kbigint && zip -qr ../kbigint.zip *)
printf >> "$GITHUB_ENV" 'DEPLOYMENT_ID=%s\n' $(curl -Ssf [email protected] -H "$SONATYPE_AUTH" "$url")
- name: Verify status
run: |-
url="$SONATYPE_API/status?id=$DEPLOYMENT_ID"
while [[ ${state:=PENDING} == PENDING ]] || [[ $state == VALIDATING ]]; do
state=$(curl -Ssf -XPOST -H "$SONATYPE_AUTH" "$url" | jq -r .deploymentState)
done
if [[ $state == FAILED ]]; then
printf '::error title=Publication failed::Check https://central.sonatype.com/publishing/deployments\n'
exit 1
fi
- name: Publish deployment
run: curl -fi -XPOST -H "$SONATYPE_AUTH" "$SONATYPE_API/deployment/$DEPLOYMENT_ID"
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

Kotlin Multiplatform BigInteger library.

<div style="margin-top:16px">
<a href="https://github.com/ObserverOfTime/kbigint/actions/workflows/ci.yml" style="border-bottom:unset">
<img alt="CI" src="https://img.shields.io/github/actions/workflow/status/ObserverOfTime/kbigint/ci.yml?logo=github&label=CI"/>
</a>
<a href="https://observeroftime.github.io/kbigint/" style="border-bottom:unset">
<img alt="Pages" src="https://img.shields.io/github/deployments/ObserverOfTime/kbigint/github-pages?logo=kotlin&label=Documentation"/>
</a>
<a href="https://central.sonatype.com/artifact/io.github.observeroftime.kbigint/kbigint" style="border-bottom:unset">
<img alt="Central" src="https://img.shields.io/maven-central/v/io.github.observeroftime.kbigint/kbigint?logo=sonatype&label=Maven%20Central"/>
</a>
</div>

## Platforms

| Platform | Implementation |
Expand Down
2 changes: 0 additions & 2 deletions kbigint-serialization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ The serialization module of the KBigInt library.

## Add the dependency

Add these to `build.gradle.kts`:

```kotlin
dependencies {
implementation("io.github.observeroftime.kbigint:kbigint-serialization")
Expand Down
18 changes: 4 additions & 14 deletions kbigint-serialization/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ kotlin {
jvm()

androidTarget {
withSourcesJar(true)
publishLibraryVariants("release")
}

Expand Down Expand Up @@ -130,15 +131,13 @@ tasks.dokkaHtmlPartial {

tasks.create<Jar>("javadocJar") {
group = "documentation"
dependsOn(tasks.dokkaHtml)
archiveClassifier.set("javadoc")
from(tasks.dokkaHtml.get().outputDirectory)
from(files("README.md"))
}

publishing {
publications.withType(MavenPublication::class) {
if (System.getenv("SONATYPE_USERNAME") != null)
artifact(tasks["javadocJar"])
artifact(tasks["javadocJar"])
pom {
name.set("KBigInt Serialization")
description.set("The serialization module of the KBigInt library")
Expand Down Expand Up @@ -180,18 +179,9 @@ publishing {
}
}

maven {
name = "Sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = System.getenv("SONATYPE_USERNAME")
password = System.getenv("SONATYPE_PASSWORD")
}
}

maven {
name = "local"
url = uri(rootProject.layout.buildDirectory.dir("repos"))
url = uri(rootProject.layout.buildDirectory.dir("repo"))
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions kbigint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Kotlin Multiplatform BigInteger library.

## Add the dependency

Add these to `build.gradle.kts`:

```kotlin
dependencies {
implementation("io.github.observeroftime.kbigint:kbigint")
Expand Down
23 changes: 9 additions & 14 deletions kbigint/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ kotlin {
jvm()

androidTarget {
withSourcesJar(true)
publishLibraryVariants("release")
}

Expand Down Expand Up @@ -311,17 +312,20 @@ tasks.dokkaHtmlPartial {
}
}

tasks.withType<AbstractPublishToMaven>().configureEach {
mustRunAfter(tasks.withType<Sign>())
}

tasks.create<Jar>("javadocJar") {
group = "documentation"
dependsOn(tasks.dokkaHtml)
group = "documentation"
archiveClassifier.set("javadoc")
from(tasks.dokkaHtml.get().outputDirectory)
from(files("README.md"))
}

publishing {
publications.withType(MavenPublication::class) {
if (System.getenv("SONATYPE_USERNAME") != null)
artifact(tasks["javadocJar"])
artifact(tasks["javadocJar"])
pom {
name.set("KBigInt")
description.set("Kotlin Multiplatform BigInteger library")
Expand Down Expand Up @@ -363,18 +367,9 @@ publishing {
}
}

maven {
name = "Sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = System.getenv("SONATYPE_USERNAME")
password = System.getenv("SONATYPE_PASSWORD")
}
}

maven {
name = "local"
url = uri(rootProject.layout.buildDirectory.dir("repos"))
url = uri(rootProject.layout.buildDirectory.dir("repo"))
}
}
}
Expand Down

0 comments on commit cfa7dc8

Please sign in to comment.