From c9bc9a2af360805b396d740ad594fb90c2338a65 Mon Sep 17 00:00:00 2001 From: James Daugherty Date: Sat, 30 Nov 2024 22:52:17 -0500 Subject: [PATCH] feedback #355 --- .github/workflows/gradle.yml | 19 ++--- .github/workflows/release.yml | 47 ++++++------ README.md | 27 ++++--- settings.gradle | 2 +- .../publishing/GrailsPublishExtension.groovy | 2 +- .../GrailsPublishGradlePlugin.groovy | 73 ++++++++++--------- .../plugin/publishing/RepositoryTarget.groovy | 6 ++ .../plugin/publishing/RepositoryType.groovy | 6 -- 8 files changed, 92 insertions(+), 90 deletions(-) create mode 100644 src/main/groovy/org/grails/gradle/plugin/publishing/RepositoryTarget.groovy delete mode 100644 src/main/groovy/org/grails/gradle/plugin/publishing/RepositoryType.groovy diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 87b81807..d8e23a9e 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: ['17'] + java: ['17', '21'] env: WORKSPACE: ${{ github.workspace }} steps: @@ -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 @@ -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 @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 98f2de0f..1199852e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 }} @@ -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 @@ -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 @@ -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 }} diff --git a/README.md b/README.md index 38887d58..dd77ee15 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 @@ -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 diff --git a/settings.gradle b/settings.gradle index 1dada324..8a07d8a1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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' diff --git a/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishExtension.groovy b/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishExtension.groovy index bb3fde64..2fa7934b 100644 --- a/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishExtension.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishExtension.groovy @@ -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 diff --git a/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishGradlePlugin.groovy b/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishGradlePlugin.groovy index 29fc27a2..8bca82f5 100644 --- a/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishGradlePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishGradlePlugin.groovy @@ -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 @@ -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 @@ -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 @@ -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 { @@ -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 } } } @@ -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 } @@ -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) { diff --git a/src/main/groovy/org/grails/gradle/plugin/publishing/RepositoryTarget.groovy b/src/main/groovy/org/grails/gradle/plugin/publishing/RepositoryTarget.groovy new file mode 100644 index 00000000..0dd468f1 --- /dev/null +++ b/src/main/groovy/org/grails/gradle/plugin/publishing/RepositoryTarget.groovy @@ -0,0 +1,6 @@ +package org.grails.gradle.plugin.publishing + +enum RepositoryTarget { + MAVEN_PUBLISH, + NEXUS_PUBLISH +} diff --git a/src/main/groovy/org/grails/gradle/plugin/publishing/RepositoryType.groovy b/src/main/groovy/org/grails/gradle/plugin/publishing/RepositoryType.groovy deleted file mode 100644 index bd141695..00000000 --- a/src/main/groovy/org/grails/gradle/plugin/publishing/RepositoryType.groovy +++ /dev/null @@ -1,6 +0,0 @@ -package org.grails.gradle.plugin.publishing - -enum RepositoryType { - ARTIFACTORY, // standard maven repository such as artifactory - CENTRAL // maven central -}