Skip to content

Commit

Permalink
Add a "Publish Release" GitHub action
Browse files Browse the repository at this point in the history
  • Loading branch information
RBusarow committed Feb 2, 2024
1 parent 97b1b70 commit 0075036
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 0 additions & 3 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository

class PublishingConventionPlugin : Plugin<Project> {

override fun apply(target: Project) {
target.plugins.apply("org.jetbrains.dokka")
target.plugins.apply("com.vanniktech.maven.publish.base")
Expand All @@ -37,8 +36,19 @@ class PublishingConventionPlugin : Plugin<Project> {
}
}

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
Expand Down

0 comments on commit 0075036

Please sign in to comment.