Skip to content

Commit a731874

Browse files
authored
JS: skip npm publish when snapshot version already exists (#7552)
npm has no `--skip-duplicate`, so the daily scheduled publish failed with a 403 whenever no new commit had landed since the previous run (the snapshot version is derived from the latest commit timestamp). Mirrors the intent of #7544 for NuGet.
1 parent bd95250 commit a731874

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

rewrite-javascript/build.gradle.kts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,24 @@ val npmPublish = tasks.register<NpmTask>("npmPublish") {
253253
}
254254

255255
workingDir.set(file("rewrite"))
256+
257+
// npm has no `--skip-duplicate`; the daily scheduled publish would fail with a 403
258+
// whenever no new commit had landed since the previous run (the snapshot version is
259+
// derived from the latest commit timestamp). Skip the task if the version already exists.
260+
onlyIf {
261+
val versionToCheck = extractVersionFromJar() ?: datedSnapshotVersion
262+
val process = ProcessBuilder("npm", "view", "@openrewrite/rewrite@$versionToCheck", "version")
263+
.directory(file("rewrite"))
264+
.redirectErrorStream(true)
265+
.start()
266+
process.waitFor()
267+
val output = process.inputStream.bufferedReader().readText().trim()
268+
val alreadyPublished = output.contains(versionToCheck)
269+
if (alreadyPublished) {
270+
logger.lifecycle("Skipping npmPublish: @openrewrite/rewrite@$versionToCheck already published")
271+
}
272+
!alreadyPublished
273+
}
256274
}
257275

258276
tasks.named("publish") {

0 commit comments

Comments
 (0)