Skip to content

Commit

Permalink
feedback grails#355
Browse files Browse the repository at this point in the history
  • Loading branch information
jdaugherty committed Dec 1, 2024
1 parent 7ebd890 commit c9bc9a2
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 90 deletions.
19 changes: 8 additions & 11 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['17']
java: ['17', '21']
env:
WORKSPACE: ${{ github.workspace }}
steps:
Expand Down Expand Up @@ -67,8 +67,8 @@ jobs:
permissions:
contents: write
env:
GIT_USER_NAME: 'grails-build'
GIT_USER_EMAIL: 'grails-build@users.noreply.github.com'
GIT_USER_NAME: grails-build
GIT_USER_EMAIL: grails-build@users.noreply.github.com
steps:
- name: "📥 Checkout repository"
uses: actions/checkout@v4
Expand All @@ -81,15 +81,13 @@ jobs:
uses: gradle/actions/setup-gradle@v4
with:
develocity-access-key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
- name: Generate Groovydoc
- name: "📜 Generate Groovydoc"
id: groovydoc
uses: gradle/gradle-build-action@v3
env:
DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }}
DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }}
with:
arguments: groovydoc
- name: Publish to Github Pages
run: ./gradle groovydoc
- name: "🚀 Publish to Github Pages"
id: docs
if: success()
uses: grails/github-pages-deploy-action@v2
Expand All @@ -100,6 +98,5 @@ jobs:
BRANCH: gh-pages
FOLDER: build/docs
DOC_FOLDER: gh-pages
COMMIT_EMAIL: behlp@unityfoundation.io
COMMIT_NAME: Puneet Behl
VERSION: ${{ needs.publish.outputs.release_version }}
COMMIT_EMAIL: ${{ env.GIT_USER_EMAIL }}
COMMIT_NAME: ${{ env.GIT_USER_NAME }}
47 changes: 24 additions & 23 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,18 @@ jobs:
DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }}
DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }}
run: ./gradlew assemble
- name: Upload Distribution
- name: "🚀 Upload Distribution"
if: success()
uses: actions/upload-artifact@v4
with:
name: grails-${{ steps.release_version.outputs.value }}.zip
path: build/distributions/grails-${{ steps.release_version.outputs.value }}.zip
- name: Generate secring file
- name: "📝 Generate secring file"
env:
SECRING_FILE: ${{ secrets.SECRING_FILE }}
run: echo $SECRING_FILE | base64 -d > ${{ github.workspace }}/secring.gpg
- name: Publish to Sonatype OSSRH
- name: "🚀 Publish to Sonatype OSSRH"
id: publish
uses: gradle/gradle-build-action@v3
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
Expand All @@ -72,8 +71,8 @@ jobs:
SECRING_FILE: ${{ secrets.SECRING_FILE }}
DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }}
DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }}
with:
arguments: |
run: |
./gradlew
-Psigning.secretKeyRingFile=${{ github.workspace }}/secring.gpg
publishToSonatype
closeSonatypeStagingRepository
Expand All @@ -83,27 +82,31 @@ jobs:
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up JDK
- name: "📥 Checkout repository"
uses: actions/checkout@v4
- name: "☕️ Setup JDK"
uses: actions/setup-java@v4
with:
distribution: temurin
distribution: liberica
java-version: 17
- name: Checkout repository
- name: "📥 Checkout repository"
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}
ref: v${{ needs.publish.outputs.release_version }}
- name: "🐘 Setup Gradle"
uses: gradle/actions/setup-gradle@v4
with:
develocity-access-key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
- name: Nexus Staging Close And Release
uses: gradle/gradle-build-action@v3
env:
DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }}
DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
with:
arguments: |
run: |
./gradlew
findSonatypeStagingRepository
releaseSonatypeStagingRepository
- name: Run post-release
Expand All @@ -122,36 +125,34 @@ jobs:
GIT_USER_NAME: 'grails-build'
GIT_USER_EMAIL: 'grails-build@users.noreply.github.com'
steps:
- name: Checkout repository
- name: "📥 Checkout repository"
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}
ref: v${{ needs.publish.outputs.release_version }}
- name: Set up JDK
- name: "☕️ Setup JDK"
uses: actions/setup-java@v4
with:
distribution: temurin
distribution: liberica
java-version: 17
- name: Generate Groovydoc
- name: "📜 Generate Groovydoc"
id: groovydoc
uses: gradle/gradle-build-action@v3
env:
DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }}
DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }}
with:
arguments: groovydoc
- name: Publish to Github Pages
run: ./gradlew groovydoc
- name: "🚀 Publish to Github Pages"
id: docs
if: success()
uses: grails/github-pages-deploy-action@v2
env:
SKIP_SNAPSHOT: ${{ contains(needs.publish.outputs.release_version, 'M') }}
SKIP_LATEST: ${{ !startsWith(needs.publish.outputs.target_branch, '6.1') }}
SKIP_LATEST: ${{ !startsWith(needs.publish.outputs.target_branch, '6.2') }}
TARGET_REPOSITORY: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
BRANCH: gh-pages
FOLDER: build/docs
DOC_FOLDER: gh-pages
COMMIT_EMAIL: ${{ env.GIT_USER_EMAIL }}
COMMIT_NAME: Puneet Behl
COMMIT_NAME: ${{ env.GIT_USER_NAME }}
VERSION: ${{ needs.publish.outputs.release_version }}
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ _Todo_: Add the docs

grails-publish
---------
A Gradle plugin to simplify publishing to either an Artifactory or Maven Central endpoint for snapshots & to Maven Central for releases.
A Gradle plugin to simplify publishing:

1. snapshots with either the Maven Publish gradle plugin or Nexus Publish gradle plugin.
2. releases with the Nexus Publish gradle plugin.

Example Usage:

Expand All @@ -52,11 +55,11 @@ Example Usage:
license {
name = 'Apache-2.0'
}
issueTrackerUrl = 'http://github.com/myname/myplugin/issues'
vcsUrl = 'http://github.com/myname/myplugin'
title = "My plugin title"
desc = "My plugin description"
developers = [johndoe:"John Doe"]
issueTrackerUrl = 'https://github.com/myname/myplugin/issues'
vcsUrl = 'https://github.com/myname/myplugin'
title = 'My plugin title'
desc = 'My plugin description'
developers = [johndoe: 'John Doe']
}

or
Expand All @@ -66,22 +69,22 @@ or
license {
name = 'Apache-2.0'
}
title = "My plugin title"
desc = "My plugin description"
developers = [johndoe:"John Doe"]
title = 'My plugin title'
desc = 'My plugin description'
developers = [johndoe: 'John Doe']
}

By default this plugin will publish to the specified Artifactory instance for snapshots, and Maven Central for releases. To change the snapshot publish behavior, you can set the `snapshotRepoType` to `RepositoryType.CENTRAL`.
By default this plugin will publish to the specified `MAVEN_PUBLISH` instance for snapshots, and `NEXUS_PUBLISH` for releases. To change the snapshot publish behavior, you can set the `snapshotRepoType` to `RepositoryTarget.NEXUS_PUBLISH`.

The credentials and connection url must be specified as a project property or an environment variable.

Artifactory Environment Variables are:
The `MAVEN_PUBLISH` Environment Variables are:

ARTIFACTORY_USERNAME
ARTIFACTORY_PASSWORD
ARTIFACTORY_URL

Sonatype Environment Variables are:
The `NEXUS_PUBLISH` Environment Variables are:

SONATYPE_NEXUS_URL
SONATYPE_SNAPSHOT_URL
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def isLocal = !isCI
def isAuthenticated = System.getenv('DEVELOCITY_ACCESS_KEY') != null
def isBuildCacheAuthenticated =
System.getenv('DEVELOCITY_BUILD_CACHE_NODE_USER') != null &&
System.getenv('DEVELOCITY_BUILD_CACHE_NODE_KEY') != null
System.getenv('DEVELOCITY_BUILD_CACHE_NODE_KEY') != null

develocity {
server = 'https://ge.grails.org'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class GrailsPublishExtension {
/**
* Determines the snapshot repository to publish to
*/
RepositoryType snapshotRepoType = RepositoryType.ARTIFACTORY
RepositoryTarget snapshotRepoType = RepositoryTarget.MAVEN_PUBLISH

/**
* The slug from github
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.grails.gradle.plugin.publishing

import grails.util.GrailsNameUtils
import io.github.gradlenexus.publishplugin.InitializeNexusStagingRepository
import io.github.gradlenexus.publishplugin.NexusPublishPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand Down Expand Up @@ -51,11 +52,11 @@ grailsPublish {
license {
name = 'Apache-2.0'
}
issueTrackerUrl = 'http://github.com/myname/myplugin/issues'
vcsUrl = 'http://github.com/myname/myplugin'
title = "My plugin title"
desc = "My plugin description"
developers = [johndoe:"John Doe"]
issueTrackerUrl = 'https://github.com/myname/myplugin/issues'
vcsUrl = 'https://github.com/myname/myplugin'
title = 'My plugin title'
desc = 'My plugin description'
developers = [johndoe: 'John Doe']
}
or
Expand All @@ -65,19 +66,19 @@ grailsPublish {
license {
name = 'Apache-2.0'
}
title = "My plugin title"
desc = "My plugin description"
developers = [johndoe:"John Doe"]
title = 'My plugin title'
desc = 'My plugin description'
developers = [johndoe: 'John Doe']
}
The credentials and connection url must be specified as a project property or an environment variable:
Artifactory Environment Variables are:
`MAVEN_PUBLISH` Environment Variables are:
ARTIFACTORY_USERNAME
ARTIFACTORY_PASSWORD
ARTIFACTORY_URL
Sonatype Environment Variables are:
`NEXUS_PUBLISH` Environment Variables are:
SONATYPE_NEXUS_URL
SONATYPE_SNAPSHOT_URL
SONATYPE_USERNAME
Expand All @@ -91,33 +92,33 @@ Sonatype Environment Variables are:
void apply(Project project) {
final ExtensionContainer extensionContainer = project.extensions
final TaskContainer taskContainer = project.tasks
final GrailsPublishExtension gpe = extensionContainer.create("grailsPublish", GrailsPublishExtension)
final GrailsPublishExtension gpe = extensionContainer.create('grailsPublish', GrailsPublishExtension)

final String artifactoryUsername = project.findProperty("artifactoryPublishUsername") ?: System.getenv("ARTIFACTORY_USERNAME") ?: ''
final String artifactoryPassword = project.findProperty("artifactoryPublishPassword") ?: System.getenv("ARTIFACTORY_PASSWORD") ?: ''
final String artifactoryPublishUrl = project.findProperty("artifactoryPublishUrl") ?: System.getenv("ARTIFACTORY_URL") ?: ''
final String sonatypeNexusUrl = project.findProperty("sonatypeNexusUrl") ?: System.getenv("SONATYPE_NEXUS_URL") ?: ''
final String sonatypeSnapshotUrl = project.findProperty("sonatypeSnapshotUrl") ?: System.getenv("SONATYPE_SNAPSHOT_URL") ?: ''
final String sonatypeUsername = project.findProperty("sonatypeUsername") ?: System.getenv("SONATYPE_USERNAME") ?: ''
final String sonatypePassword = project.findProperty("sonatypePassword") ?: System.getenv("SONATYPE_PASSWORD") ?: ''
final String sonatypeStagingProfileId = project.findProperty("sonatypeStagingProfileId") ?: System.getenv("SONATYPE_STAGING_PROFILE_ID") ?: ''
final String artifactoryUsername = project.findProperty('artifactoryPublishUsername') ?: System.getenv('ARTIFACTORY_USERNAME') ?: ''
final String artifactoryPassword = project.findProperty('artifactoryPublishPassword') ?: System.getenv('ARTIFACTORY_PASSWORD') ?: ''
final String artifactoryPublishUrl = project.findProperty('artifactoryPublishUrl') ?: System.getenv('ARTIFACTORY_URL') ?: ''
final String sonatypeNexusUrl = project.findProperty('sonatypeNexusUrl') ?: System.getenv('SONATYPE_NEXUS_URL') ?: ''
final String sonatypeSnapshotUrl = project.findProperty('sonatypeSnapshotUrl') ?: System.getenv('SONATYPE_SNAPSHOT_URL') ?: ''
final String sonatypeUsername = project.findProperty('sonatypeUsername') ?: System.getenv('SONATYPE_USERNAME') ?: ''
final String sonatypePassword = project.findProperty('sonatypePassword') ?: System.getenv('SONATYPE_PASSWORD') ?: ''
final String sonatypeStagingProfileId = project.findProperty('sonatypeStagingProfileId') ?: System.getenv('SONATYPE_STAGING_PROFILE_ID') ?: ''

final ExtraPropertiesExtension extraPropertiesExtension = extensionContainer.findByType(ExtraPropertiesExtension)

extraPropertiesExtension.setProperty(SIGNING_KEY_ID, project.hasProperty(SIGNING_KEY_ID) ? project[SIGNING_KEY_ID] : System.getenv("SIGNING_KEY") ?: null)
extraPropertiesExtension.setProperty(SIGNING_PASSWORD, project.hasProperty(SIGNING_PASSWORD) ? project[SIGNING_PASSWORD] : System.getenv("SIGNING_PASSPHRASE") ?: null)
extraPropertiesExtension.setProperty(SIGNING_KEYRING, project.hasProperty(SIGNING_KEYRING) ? project[SIGNING_KEYRING] : System.getenv("SIGNING_KEYRING") ?: null)
extraPropertiesExtension.setProperty(SIGNING_KEY_ID, project.hasProperty(SIGNING_KEY_ID) ? project[SIGNING_KEY_ID] : System.getenv('SIGNING_KEY') ?: null)
extraPropertiesExtension.setProperty(SIGNING_PASSWORD, project.hasProperty(SIGNING_PASSWORD) ? project[SIGNING_PASSWORD] : System.getenv('SIGNING_PASSPHRASE') ?: null)
extraPropertiesExtension.setProperty(SIGNING_KEYRING, project.hasProperty(SIGNING_KEYRING) ? project[SIGNING_KEYRING] : System.getenv('SIGNING_KEYRING') ?: null)

project.afterEvaluate {
RepositoryType snapshotType = gpe.snapshotRepoType
boolean isSnapshot = project.version.endsWith("SNAPSHOT")
RepositoryTarget snapshotType = gpe.snapshotRepoType
boolean isSnapshot = project.version.endsWith('SNAPSHOT')
boolean isRelease = !isSnapshot
final PluginManager projectPluginManager = project.getPluginManager()
final PluginManager rootProjectPluginManager = project.rootProject.getPluginManager()
projectPluginManager.apply(MavenPublishPlugin.class)
projectPluginManager.apply(MavenPublishPlugin)

project.publishing {
if (isSnapshot && snapshotType == RepositoryType.ARTIFACTORY) {
if (isSnapshot && snapshotType == RepositoryTarget.MAVEN_PUBLISH) {
System.setProperty('org.gradle.internal.publish.checksums.insecure', true as String)
repositories {
maven {
Expand All @@ -126,10 +127,10 @@ Sonatype Environment Variables are:
password = artifactoryPassword
}

if(!artifactoryPublishUrl) {
throw new RuntimeException("Could not locate a project property of `artifactoryPublishUrl` or an environment variable of `ARTIFACTORY_URL` for the snapshot url")
if (!artifactoryPublishUrl) {
throw new RuntimeException('Could not locate a project property of `artifactoryPublishUrl` or an environment variable of `ARTIFACTORY_URL` for the snapshot url')
}
url artifactoryPublishUrl
url = artifactoryPublishUrl
}
}
}
Expand All @@ -139,11 +140,11 @@ Sonatype Environment Variables are:
artifactId project.name

doAddArtefact(project, delegate)
def sourcesJar = taskContainer.findByName("sourcesJar")
def sourcesJar = taskContainer.findByName('sourcesJar')
if (sourcesJar != null) {
artifact sourcesJar
}
def javadocJar = taskContainer.findByName("javadocJar")
def javadocJar = taskContainer.findByName('javadocJar')
if (javadocJar != null) {
artifact javadocJar
}
Expand Down Expand Up @@ -262,17 +263,17 @@ Sonatype Environment Variables are:
}
}

if (isRelease || (isSnapshot && snapshotType == RepositoryType.CENTRAL)) {
rootProjectPluginManager.apply(NexusPublishPlugin.class)
projectPluginManager.apply(SigningPlugin.class)
if (isRelease || (isSnapshot && snapshotType == RepositoryTarget.NEXUS_PUBLISH)) {
rootProjectPluginManager.apply(NexusPublishPlugin)
projectPluginManager.apply(SigningPlugin)

extensionContainer.configure(SigningExtension, {
it.required = isRelease
it.sign project.publishing.publications.maven
})

project.rootProject.tasks.withType(io.github.gradlenexus.publishplugin.InitializeNexusStagingRepository).configureEach { io.github.gradlenexus.publishplugin.InitializeNexusStagingRepository task ->
task.setShouldRunAfter(project.tasks.withType(Sign))
project.rootProject.tasks.withType(InitializeNexusStagingRepository).configureEach { InitializeNexusStagingRepository task ->
task.shouldRunAfter = project.tasks.withType(Sign)
}

project.tasks.withType(Sign) {
Expand Down
Loading

0 comments on commit c9bc9a2

Please sign in to comment.