From 0075036b73fc2e984f465981ced0bf37c0836f05 Mon Sep 17 00:00:00 2001 From: Rick Busarow Date: Fri, 2 Feb 2024 13:17:52 -0600 Subject: [PATCH] Add a "Publish Release" GitHub action --- .github/workflows/publish-release.yml | 38 +++++++++++++++++++ .github/workflows/publish-snapshot.yml | 3 -- RELEASING.md | 10 +++-- .../buildsrc/PublishingConventionPlugin.kt | 14 ++++++- 4 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/publish-release.yml diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 0000000000..56b7e46e39 --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,38 @@ +name : Publish Release + +on : + workflow_dispatch: + +jobs : + publish-release : + runs-on : ubuntu-latest + if : github.repository == 'square/workflow-kotlin' + timeout-minutes : 35 + + steps : + - uses : actions/checkout@v3 + - uses : gradle/wrapper-validation-action@v1 + + - name : Ensure this isn't a -SNAPSHOT version + uses : ./.github/actions/gradle-task + with : + task : checkVersionIsNotSnapshot + + - name : Assemble + uses : ./.github/actions/gradle-task + with : + task : assemble + + - name : Check + uses : ./.github/actions/gradle-task + with : + task : check -x artifactsCheck + + - name : Publish Release + uses : ./.github/actions/gradle-task + with : + task : publish + env : + ORG_GRADLE_PROJECT_mavenCentralUsername : ${{ secrets.SONATYPE_NEXUS_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword : ${{ secrets.SONATYPE_NEXUS_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey : ${{ secrets.ARTIFACT_SIGNING_PRIVATE_KEY }} diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml index cf1875a20f..eca91ed4ba 100644 --- a/.github/workflows/publish-snapshot.yml +++ b/.github/workflows/publish-snapshot.yml @@ -6,9 +6,6 @@ on: branches: - main -env: - GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx12g -Dorg.gradle.daemon=false -Dorg.gradle.logging.stacktrace=all" - jobs: publish-snapshot : runs-on : workflow-kotlin-test-runner-ubuntu-4core diff --git a/RELEASING.md b/RELEASING.md index cd8f44e684..1f0cc1ab90 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -30,14 +30,16 @@ git tag v0.1.0 ``` -1. Upload the kotlin artifacts: +1. Push those changes to the repository: ```bash - ./gradlew clean && ./gradlew build && ./gradlew publish + git push ``` -1. Close and release the staging repository at https://s01.oss.sonatype.org/#stagingRepositories. +1. Run the `Publish Release` action in the [GitHub Actions](https://github.com/square/workflow-kotlin/actions/workflows/publish-release.yml) page by clicking "run workflow" on the right. -1. Bump the version +1. Wait for that publishing job to succeed. + +1. Back on your local machine, bump the version - **Kotlin:** Update the `VERSION_NAME` property in `gradle.properties` to the new snapshot version, e.g. `VERSION_NAME=0.2.0-SNAPSHOT`. diff --git a/build-logic/src/main/java/com/squareup/workflow1/buildsrc/PublishingConventionPlugin.kt b/build-logic/src/main/java/com/squareup/workflow1/buildsrc/PublishingConventionPlugin.kt index fe810a46b0..56e2cd0a7e 100644 --- a/build-logic/src/main/java/com/squareup/workflow1/buildsrc/PublishingConventionPlugin.kt +++ b/build-logic/src/main/java/com/squareup/workflow1/buildsrc/PublishingConventionPlugin.kt @@ -13,7 +13,6 @@ import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.tasks.PublishToMavenRepository class PublishingConventionPlugin : Plugin { - override fun apply(target: Project) { target.plugins.apply("org.jetbrains.dokka") target.plugins.apply("com.vanniktech.maven.publish.base") @@ -37,8 +36,19 @@ class PublishingConventionPlugin : Plugin { } } + target.tasks.register("checkVersionIsNotSnapshot") { task -> + task.group = "publishing" + task.description = "ensures that the project version does not have a -SNAPSHOT suffix" + val versionString = target.version as String + task.doLast { + require(!versionString.endsWith("-SNAPSHOT")) { + "The project's version name cannot have a -SNAPSHOT suffix, but it was $versionString." + } + } + } + target.extensions.configure(MavenPublishBaseExtension::class.java) { basePluginExtension -> - basePluginExtension.publishToMavenCentral(SonatypeHost.S01) + basePluginExtension.publishToMavenCentral(SonatypeHost.S01, automaticRelease = true) // Will only apply to non snapshot builds. basePluginExtension.signAllPublications() // import all settings from root project and project-specific gradle.properties files