Skip to content

Commit

Permalink
Maven central publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetuska committed May 26, 2021
1 parent 381ff7a commit 3d26a0a
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 82 deletions.
110 changes: 97 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
required: true
description: Package version to publish under
skipGradlePluginPortal:
description: Should we skip publishing to Gradle Plugin Portal
required: false
default: "true"
skipGitHub:
description: Should we skip publishing to GitHub
required: false
default: "true"
skipMavenCentral:
description: Should we skip publishing to Maven Central
required: false
default: "true"
release:
types: [created]

env:
VERSION: ${{ github.event.release.tag_name }}

jobs:
check:
runs-on: ubuntu-latest
Expand All @@ -16,6 +36,9 @@ jobs:
path: |
~/.gradle/caches
~/.gradle/wrapper
~/.gradle/yarn
~/.gradle/nodejs
~/.konan
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
Expand All @@ -24,20 +47,33 @@ jobs:
with:
java-version: 11
- name: Check with gradle
run: ./gradlew check
# - name: Publish Pages
# run: |
# ./gradlew dokkaHtml;
# cp -avr build/dokka/html/ public;
# find public -type f -regex '.*\.\(htm\|html\|txt\|text\|js\|css\)$' -exec gzip -f -k {} \;
# echo '/npm-publish /npm-publish/npm-publish/index.html 301' > public/_redirects;
# echo '/npm-publish/index.html /npm-publish/npm-publish/index.html 301' >> public/_redirects;

shell: bash
run: |
VERSION=${VERSION:=${{ github.event.inputs.version }}}
VERSION=${VERSION/v}
./gradlew check
- name: Publish Pages
shell: bash
run: |
VERSION=${VERSION:=${{ github.event.inputs.version }}}
VERSION=${VERSION/v}
./gradlew dokkaHtml;
cp -avr build/dokka/html/ public;
find public -type f -regex '.*\.\(htm\|html\|txt\|text\|js\|css\)$' -exec gzip -f -k {} \;
echo '/npm-publish /npm-publish/npm-publish/index.html 301' > public/_redirects;
echo '/npm-publish/index.html /npm-publish/npm-publish/index.html 301' >> public/_redirects;
- uses: crazy-max/ghaction-github-pages@v2
with:
target_branch: gh-pages
build_dir: public
env:
GITHUB_TOKEN: ${{ github.token }}

release-GradlePluginPortal:
name: "Release: GradlePluginPortal"
runs-on: ubuntu-latest
needs: [ check ]
if: ${{ github.event.inputs.skipGradlePluginPortal != 'true' }}
steps:
- uses: actions/checkout@v2
- name: Restore Gradle cache
Expand All @@ -55,14 +91,22 @@ jobs:
with:
java-version: 11
- name: Publish to Gradle Plugin Portal
run: ./gradlew publishPlugins -Pgradle.publish.key="${{ secrets.GRADLE_PUBLISH_KEY }}" -Pgradle.publish.secret="${{ secrets.GRADLE_PUBLISH_SECRET }}" -Pversion=${VERSION//v}
shell: bash
run: |
VERSION=${VERSION:=${{ github.event.inputs.version }}}
VERSION=${VERSION/v}
./gradlew publishPlugins -Pgradle.publish.key="${{ secrets.GRADLE_PUBLISH_KEY }}" -Pgradle.publish.secret="${{ secrets.GRADLE_PUBLISH_SECRET }}" -Pversion=${VERSION//v}
env:
VERSION: ${{ github.event.release.tag_name }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}


release-GitHub:
name: "Release: GitHub"
runs-on: ubuntu-latest
needs: [check]
if: ${{ github.event.inputs.skipGitHub != 'true' }}
steps:
- uses: actions/checkout@v2
- name: Restore Gradle cache
Expand All @@ -80,8 +124,48 @@ jobs:
with:
java-version: 11
- name: Publish to GitHub Packages
run: ./gradlew publish -Ppublish.GitHub=true -Ppublish=true -Poverride=false -Pversion=${VERSION//v}
shell: bash
run: |
VERSION=${VERSION:=${{ github.event.inputs.version }}}
VERSION=${VERSION/v}
./gradlew publishAllPublicationsToGitHubRepository -Pversion=${VERSION//v}
env:
VERSION: ${{ github.event.release.tag_name }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
GH_USERNAME: ${{ github.actor }}
GH_PASSWORD: ${{ github.token }}

release-MavenCentral:
name: "Release: MavenCentral"
runs-on: ubuntu-latest
needs: [ check ]
if: ${{ github.event.inputs.skipMavenCentral != 'true' }}
steps:
- uses: actions/checkout@v2
- name: Restore Gradle cache
id: cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 11
- name: Publish to GitHub Packages
shell: bash
run: |
VERSION=${VERSION:=${{ github.event.inputs.version }}}
VERSION=${VERSION/v}
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -Pversion=${VERSION//v}
env:
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![Gitpod ready-to-code](https://img.shields.io/badge/gitpod-ready_to_code-blue?logo=gitpod&style=flat-square)](https://gitpod.io/#https://github.com/mpetuska/npm-publish)
[![Slack chat](https://img.shields.io/badge/kotlinlang-green?logo=slack&style=flat-square)](https://kotlinlang.slack.com/team/UL1A5BA2X)
[![Dokka docks](https://img.shields.io/badge/docs-dokka-orange?style=flat-square)](http://mpetuska.github.io/npm-publish)
[![Version bintray](https://img.shields.io/bintray/v/mpetuska/dev.petuska/npm-publish?style=flat-square&logo=jfrog-bintray)](https://bintray.com/mpetuska/dev.petuska/npm-publish/_latestVersion)
[![Dokka docs](https://img.shields.io/badge/docs-dokka-orange?style=flat-square)](http://mpetuska.github.io/npm-publish)
[![Version gradle-plugin-portal](https://img.shields.io/maven-metadata/v?label=gradle%20plugin%20portal&logo=gradle&metadataUrl=https%3A%2F%2Fplugins.gradle.org%2Fm2%2Fdev.petuska%2Fnpm-publish%2Fmaven-metadata.xml&style=flat-square)](https://plugins.gradle.org/plugin/dev.petuska.npm.publish)
[![Version maven-central](https://img.shields.io/maven-central/v/dev.petuska/npm-publish?logo=apache-maven&style=flat-square)](https://mvnrepository.com/artifact/dev.petuska/npm-publish/latest)

# NPM-PUBLISH GRADLE PLUGIN

Expand Down
67 changes: 40 additions & 27 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ plugins {
id("org.jetbrains.dokka")
id("com.github.jakemarsden.git-hooks")
id("org.jlleitschuh.gradle.ktlint")
id("io.github.gradle-nexus.publish-plugin")
signing
idea
}

description = "Gradle plugin for npm package publishing"
description = """
A maven-publish alternative for NPM package publishing.
Integrates with kotlin JS/MPP plugins (if applied) to automatically
setup publishing to NPM repositories for all JS targets.
""".trimIndent()

idea {
module {
Expand Down Expand Up @@ -57,12 +63,7 @@ gradlePlugin {
create(project.name) {
id = pluginId
displayName = "NPM package publishing to NPM repositories"
description =
"""
A maven-publish alternative for NPM package publishing.
Integrates with kotlin JS/MPP plugins (if applied) to automatically
setup publishing to NPM repositories for all JS targets.
""".trimIndent()
description = rootProject.description
implementationClass = "dev.petuska.npm.publish.NpmPublishPlugin"
}
}
Expand All @@ -75,25 +76,39 @@ pluginBundle {
}

java {
withSourcesJar()
withJavadocJar()
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}

signing {
val signingKey: String? by project
val signingPassword: String? by project
if (signingKey != null) {
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}
}

tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "${JavaVersion.VERSION_11}"
}
}
}

publishing {
fun checkAnyTrue(vararg props: String) = props.any {
"true".equals(project.properties[it] as String?, true)
}

fun checkNoneStarting(vararg props: String) = props.none {
project.properties.keys.any { p -> p.startsWith(it) }
}
publications {
withType<MavenPublication> {
pom {
Expand All @@ -108,6 +123,14 @@ publishing {
}
}

developers {
developer {
id to "mpetuska"
name to "Martynas Petuška"
email to "[email protected]"
}
}

scm {
connection by "scm:git:[email protected]:mpetuska/${project.name}.git"
url by "https://github.com/mpetuska/${project.name}"
Expand All @@ -116,18 +139,8 @@ publishing {
}
}
repositories {
fun repository(name: String, config: MavenArtifactRepository.() -> Unit) {
if ((checkAnyTrue("publish.all", "publish.$name") && checkNoneStarting("publish.skip")) &&
checkNoneStarting("publish.skip.$name")
) {
maven {
this.name = name
config()
}
}
}
repository("GitHub") {
url = uri("https://maven.pkg.github.com/mpetuska/${project.name}")
maven("https://maven.pkg.github.com/mpetuska/${project.name}") {
name = "GitHub"
credentials {
username = System.getenv("GH_USERNAME")
password = System.getenv("GH_PASSWORD")
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ kotlin.mpp.stability.nowarn=true
kotlin.stdlib.default.dependency=false
org.gradle.project.sourceCompatibility=11
org.gradle.vfs.watch=true

version=0.0.0
group=dev.petuska
#publish.all=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@ plugins {
kotlin {
js {
browser()
useCommonJs()
binaries.library()
}
dependencies {
implementation(npm("axios", "*"))
api(devNpm("snabbdom", "*"))
implementation("io.ktor:ktor-client-core:1.4.1")
}
sourceSets {
all {
languageSettings.useExperimentalAnnotation("kotlin.js.ExperimentalJsExport")
}
}
}

npmPublishing {
organization = group as String

publications {
val js by getting {
named("js") {
packageJsonTemplateFile = projectDir.resolve("../template.package.json")
packageJson {
author { name = "Martynas Petuška" }
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions sandbox/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
kotlin.mpp.stability.nowarn=true
org.gradle.vfs.watch=true
npm.publish.dry=true
kotlin.js.compiler=ir
20 changes: 5 additions & 15 deletions sandbox/mpp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,26 @@ plugins {
}

kotlin {
js("browser", IR) {
js("browser") {
browser()
useCommonJs()
binaries.library()
}
js("node", IR) {
js("node") {
useCommonJs()
nodejs()
binaries.library()
}

sourceSets {
all {
kotlin.srcDirs("src/main/kotlin")
resources.srcDirs("src/main/resources")
dependencies {
implementation("io.ktor:ktor-client-core:1.4.1")
implementation(devNpm("axios", "*"))
api(npm("snabbdom", "*"))
}
languageSettings.useExperimentalAnnotation("kotlin.js.ExperimentalJsExport")
}
// val bothMain by getting
// named("browserMain") {
// kotlin.srcDirs(bothMain.kotlin.srcDirs)
// resources.srcDirs(bothMain.resources.srcDirs)
// }
// named("nodeMain") {
// kotlin.srcDirs(bothMain.kotlin.srcDirs)
// resources.srcDirs(bothMain.resources.srcDirs)
// }
}
}

Expand All @@ -49,13 +39,13 @@ npmPublishing {
}

publications {
val browser by getting {
named("browser") {
moduleName = "mpp-browser"
packageJson {
// bundledDependencies = mutableSetOf("kotlin-test")
}
}
val node by getting {
named("node") {
moduleName = "mpp-node"
packageJson {
author to "Custom Author"
Expand Down
Loading

0 comments on commit 3d26a0a

Please sign in to comment.