bufbuild / buf-gradle-plugin

Gradle plugin for the Buf CLI
Apache License 2.0
46 stars 13 forks source link

buf-gradle-plugin build fails on newer Buf CLIs #207

Closed pkwarren closed 1 month ago

pkwarren commented 1 month ago

I attempted to upgrade the plugin from 1.27.1 to 1.34.0 (latest release) and saw these test failuires:

Tests:

Error:

Execution failed for task ':bufBuild'.
> > arguments: [/Users/pkw/dev/buf-gradle-plugin/build/tmp/test/work/.gradle-test-kit/caches/modules-2/files-2.1/build.buf/buf/1.34.0/fb40b6d9b2d05e0eafcac09f5b443778f3beab81/buf-1.34.0-osx-aarch_64.exe, build, --output, /private/var/folders/zw/8cq3lqwd2cj6fznjw037s7480000gn/T/junit15873435901407493843/build/bufbuild/image.json]
  > exit code: 1
  >    stdout: (empty)
  >    stderr: (below)
  > Failure: cannot have a buf.work.yaml and buf.yaml in the same directory "private/var/folders/zw/8cq3lqwd2cj6fznjw037s7480000gn/T/junit15873435901407493843/build/bufbuild"
  > 

These tests appear to copy a file tree:

buf.yaml
src/main/proto/buf/test/v1/test.proto

into a directory (under build/) consisting of:

buf.work.yaml
buf.yaml
src-main-proto -> ../../src/main/proto

The generated buf.work.yaml contains:

version: v1
directories:
  - src-main-proto

This needs more investigation but ideally for v2 configs we wouldn't need to create any filesystem structure like this during the build. A user should be able to use the plugin entirely from the root buf.yaml file with a config like:

version: v2
modules:
  - path: src/main/proto
lint:
  except:
    - FIELD_NOT_REQUIRED
    - PACKAGE_NO_IMPORT_CYCLE
  disallow_comment_ignores: true
breaking:
  except:
    - EXTENSION_NO_DELETE
    - FIELD_SAME_DEFAULT
  ignore:
    - buf
pkwarren commented 1 month ago

Here's the patch I used to run the tests and debug them better:

diff --git a/src/main/kotlin/build/buf/gradle/BufExtension.kt b/src/main/kotlin/build/buf/gradle/BufExtension.kt
index 6c2534a..4774fab 100644
--- a/src/main/kotlin/build/buf/gradle/BufExtension.kt
+++ b/src/main/kotlin/build/buf/gradle/BufExtension.kt
@@ -49,7 +49,7 @@ open class BufExtension {
     /**
      * Specify the version of Buf.
      */
-    var toolVersion = "1.27.1"
+    var toolVersion = "1.34.0"

     internal var buildDetails: BuildDetails? = null

diff --git a/src/test/kotlin/build/buf/gradle/AbstractBufIntegrationTest.kt b/src/test/kotlin/build/buf/gradle/AbstractBufIntegrationTest.kt
index 921835c..fcaaf6e 100644
--- a/src/test/kotlin/build/buf/gradle/AbstractBufIntegrationTest.kt
+++ b/src/test/kotlin/build/buf/gradle/AbstractBufIntegrationTest.kt
@@ -19,13 +19,14 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin.CHECK_TASK_NAME
 import org.gradle.testkit.runner.GradleRunner
 import org.junit.jupiter.api.BeforeEach
 import org.junit.jupiter.api.TestInfo
+import org.junit.jupiter.api.io.CleanupMode
 import org.junit.jupiter.api.io.TempDir
 import java.io.File
 import java.nio.file.Paths
 import java.util.Locale

 abstract class AbstractBufIntegrationTest : IntegrationTest {
-    @TempDir
+    @TempDir(cleanup = CleanupMode.ON_SUCCESS)
     lateinit var projectDir: File

     val buildFile
@@ -75,7 +76,7 @@ abstract class AbstractBufIntegrationTest : IntegrationTest {

     override fun checkRunner() = gradleRunner().withArguments(CHECK_TASK_NAME)

-    fun publishRunner() = gradleRunner().withArguments("publish")
+    fun publishRunner() = gradleRunner().withArguments("publish", "--info")

     fun File.replace(
         oldValue: String,
drice-buf commented 1 month ago

Fixed by https://github.com/bufbuild/buf-gradle-plugin/pull/213