Skip to content

Commit 2bf5a5d

Browse files
committed
Adjust and document publishing
1 parent bcc5ee5 commit 2bf5a5d

File tree

4 files changed

+58
-10
lines changed

4 files changed

+58
-10
lines changed

.github/workflows/build.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ jobs:
2121
java-version: '21'
2222
distribution: 'temurin'
2323

24+
- name: Create properties from environment
25+
run: sh scripts/create-properties.sh
26+
2427
# Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies.
2528
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
2629
- name: Setup Gradle
@@ -54,6 +57,9 @@ jobs:
5457
java-version: '21'
5558
distribution: 'temurin'
5659

60+
- name: Create properties from environment
61+
run: sh scripts/create-properties.sh
62+
5763
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
5864
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
5965
- name: Generate and submit dependency graph

INTERNAL.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The following documentation provides additional knowledge about the project that
44

55
# Local properties
66

7-
The following properties should be set locally in the `local.properties` file in order to support build and development capabilities.
7+
The following properties should be set locally in the `local.properties` file in order to support build and publishing tasks.
88

99
| Property | Usage |
1010
| ---------------------- | ----- |
@@ -14,3 +14,29 @@ The following properties should be set locally in the `local.properties` file in
1414
| maven.repo.password | Maven repository password. Required when publishing to Maven repository using the `maven-publish` plugin. |
1515
| maven.signing.key | ASCII armored secret key. Required to sign the artifact using the `maven-publish` plugin. |
1616
| maven.signing.password | Passphrase of the secret key. Required to sign the artifact using the `maven-publish` plugin. |
17+
18+
# Publishing
19+
20+
To publish a new version of the plugin to the plugin repositories, bump the `version` property in `build.gradle.kts` and run:
21+
- `publishPlugins` to upload the plugin to Gradle Plugin Repository,
22+
- `publishPluginPublicationToMavenRepository` to upload the plugin to Maven Central Repository.
23+
24+
# Pre-release tests
25+
26+
Testing changes before publishing built artifacts to the repositories can be done by uploading a snapshot version of the plugin.
27+
To do so, add `-SNAPSHOT` suffix to the next release version and upload it to Maven repository with the `publishPluginPublicationToMavenRepository` Gradle task.
28+
29+
In the test project, configure the plugin using the legacy `apply` method as shown below:
30+
```
31+
buildscript {
32+
repositories {
33+
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
34+
}
35+
36+
dependencies {
37+
classpath("io.github.tomwyr:godot-kotlin-tree:X.Y.Z-SNAPSHOT")
38+
}
39+
}
40+
41+
apply<GodotNodeTree>()
42+
```

build.gradle.kts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import com.adarshr.gradle.testlogger.TestLoggerExtension
22
import com.adarshr.gradle.testlogger.theme.ThemeType
3+
import java.io.FileInputStream
4+
import java.util.*
5+
6+
val localProperties = loadLocalProps()
37

48
version = "1.0.1"
59
group = "io.github.tomwyr"
@@ -32,8 +36,9 @@ gradlePlugin {
3236
website = "https://github.com/tomwyr/godot-kotlin-tree"
3337
vcsUrl = "https://github.com/tomwyr/godot-kotlin-tree.git"
3438

35-
envToProp("GRADLE_PUBLISH_KEY", "gradle.publish.key")
36-
envToProp("GRADLE_PUBLISH_SECRET", "gradle.publish.secret")
39+
fun bindProp(key: String) = System.setProperty(key, prop(key))
40+
bindProp("gradle.publish.key")
41+
bindProp("gradle.publish.secret")
3742

3843
plugins {
3944
create("godot-kotlin-tree") {
@@ -92,25 +97,28 @@ publishing {
9297
url = uri(if (isSnapshot) snapshotsRepoUrl else releasesRepoUrl)
9398

9499
credentials {
95-
username = env("MAVEN_REPO_USERNAME")
96-
password = env("MAVEN_REPO_PASSWORD")
100+
username = prop("maven.repo.username")
101+
password = prop("maven.repo.password")
97102
}
98103
}
99104
}
100105
}
101106

102107
signing {
103-
val signingKey = env("MAVEN_SIGNING_KEY")
104-
val signingPassword = env("MAVEN_SIGNING_PASSWORD")
108+
isRequired = true
109+
val signingKey = prop("maven.signing.key").replace("\\n", "\n")
110+
val signingPassword = prop("maven.signing.password")
105111
useInMemoryPgpKeys(signingKey, signingPassword)
106112
sign(publishing.publications["plugin"])
107113
}
108114

109115
val isSnapshot: Boolean
110116
get() = version.toString().endsWith("SNAPSHOT")
111117

112-
fun env(key: String): String? = System.getenv(key)
118+
fun loadLocalProps() = Properties().apply {
119+
load(FileInputStream(rootProject.file("local.properties")))
120+
}
113121

114-
fun envToProp(envKey: String, propKey: String, defaultValue: String = "") {
115-
System.setProperty(propKey, System.getenv(envKey) ?: defaultValue)
122+
fun prop(key: String): String {
123+
return localProperties[key] as? String ?: throw Exception("Expected local property $key not set")
116124
}

scripts/create-properties.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cat > local.properties << EOFecho
2+
gradle.publish.key=
3+
gradle.publish.secret=
4+
maven.repo.username=
5+
maven.repo.password=
6+
maven.signing.key=
7+
maven.signing.password=
8+
EOF

0 commit comments

Comments
 (0)