Skip to content

Commit ca6f8a3

Browse files
authored
impl: improve publish task (#49)
- marketplace token should be in JETBRAINS_MARKETPLACE_PUBLISH_TOKEN env. variable - calls the proper api for upload based on whether it's the first release version or not
1 parent df37364 commit ca6f8a3

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

build.gradle.kts

+44-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import com.github.jk1.license.render.JsonReportRenderer
55
import com.jetbrains.plugin.structure.toolbox.ToolboxMeta
66
import com.jetbrains.plugin.structure.toolbox.ToolboxPluginDescriptor
77
import org.jetbrains.intellij.pluginRepository.PluginRepositoryFactory
8+
import org.jetbrains.intellij.pluginRepository.model.LicenseUrl
9+
import org.jetbrains.intellij.pluginRepository.model.ProductFamily
810
import org.jetbrains.kotlin.com.intellij.openapi.util.SystemInfoRt
911
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
1012
import java.nio.file.Path
@@ -153,7 +155,10 @@ fun CopySpec.fromCompileDependencies() {
153155
)
154156
}
155157

156-
val pluginZip by tasks.creating(Zip::class) {
158+
/**
159+
* Useful when doing manual local install.
160+
*/
161+
val pluginPrettyZip by tasks.creating(Zip::class) {
157162
archiveBaseName.set(properties("name"))
158163
dependsOn(tasks.jar)
159164
dependsOn(tasks.getByName("generateLicenseReport"))
@@ -162,6 +167,14 @@ val pluginZip by tasks.creating(Zip::class) {
162167
into(extension.id) // folder like com.coder.toolbox
163168
}
164169

170+
val pluginZip by tasks.creating(Zip::class) {
171+
dependsOn(tasks.jar)
172+
dependsOn(tasks.getByName("generateLicenseReport"))
173+
174+
fromCompileDependencies()
175+
archiveBaseName.set(extension.id)
176+
}
177+
165178
tasks.register("cleanAll", Delete::class.java) {
166179
dependsOn(tasks.clean)
167180
delete(getPluginInstallDir())
@@ -187,20 +200,43 @@ private fun getPluginInstallDir(): Path {
187200
return pluginsDir / extension.id
188201
}
189202

190-
val publishPlugin by tasks.creating {
203+
val publishPlugin by tasks.registering {
191204
dependsOn(pluginZip)
192205

193206
doLast {
207+
val pluginMarketplaceToken: String = if (System.getenv("JETBRAINS_MARKETPLACE_PUBLISH_TOKEN").isNullOrBlank()) {
208+
error("Env. variable `JETBRAINS_MARKETPLACE_PUBLISH_TOKEN` does not exist. Please set the env. variable to a token obtained from the marketplace.")
209+
} else {
210+
System.getenv("JETBRAINS_MARKETPLACE_PUBLISH_TOKEN")
211+
}
212+
213+
println("Plugin Marketplace Token: ${pluginMarketplaceToken.take(5)}*****")
214+
194215
val instance = PluginRepositoryFactory.create(
195216
"https://plugins.jetbrains.com",
196-
project.property("PUBLISH_TOKEN").toString()
217+
pluginMarketplaceToken
197218
)
198219

199-
// first upload
200-
// instance.uploader.uploadNewPlugin(pluginZip.outputs.files.singleFile, listOf("toolbox", "gateway"), LicenseUrl.APACHE_2_0, ProductFamily.TOOLBOX)
201-
202-
// subsequent updates
203-
instance.uploader.upload(extension.id, pluginZip.outputs.files.singleFile)
220+
if (extension.version == "0.1.0") {
221+
instance.uploader.uploadNewPlugin(
222+
pluginZip.outputs.files.singleFile,
223+
listOf("toolbox", "gateway"), // do not change
224+
LicenseUrl.MIT, // choose wisely
225+
ProductFamily.TOOLBOX, // do not change
226+
extension.meta.vendor, // do not change
227+
isHidden = true
228+
)
229+
} else {
230+
// !!! subsequent updates !!!
231+
instance.uploader.uploadUpdateByXmlIdAndFamily(
232+
extension.id, // do not change
233+
ProductFamily.TOOLBOX, // do not change
234+
pluginZip.outputs.files.singleFile, // do not change
235+
null, // do not change. Channels will be available later
236+
"Bug fixes and improvements",
237+
true
238+
)
239+
}
204240
}
205241
}
206242

0 commit comments

Comments
 (0)