semver-git-plugin icon indicating copy to clipboard operation
semver-git-plugin copied to clipboard

always dirty

Open benkeil opened this issue 2 years ago • 3 comments

The branch is clean.

output of git log

485155d (HEAD -> main, origin/main, origin/HEAD) chore: add env to check step
c8a8891 chore: use dependabot plugin
d9f7bab chore: update README
8e120c3 (tag: v1.0.10) chore(release): 1.0.10 [skip ci]

output of ./gradlew showVersion

> Task :showVersion
Version: 1.0.10-dirty-SNAPSHOT

Happens on my Mac, my colleagues with Linux don't face the problem.

benkeil avatar Apr 03 '23 02:04 benkeil

After a new build

output of git log

bcabb17 (HEAD -> main, tag: v1.0.11, origin/main) chore(release): 1.0.11 [skip ci]

output of ./gradlew showVersion

> Task :showVersion
Version: 1.0.11-dirty-SNAPSHOT

benkeil avatar Apr 04 '23 03:04 benkeil

and the configuration:

semver {
  snapshotSuffix = "SNAPSHOT" // (default) appended if the commit is without a release tag
  dirtyMarker = "dirty" // (default) appended if there are uncommitted changes
  initialVersion = "0.1.22" // (default) initial version in semantic versioning
  tagPrefix = "v" // (default) each project can have its own tags identified by a unique prefix.
  tagType = io.wusa.TagType.LIGHTWEIGHT // (default) options are Annotated or Lightweight
  branches { // list of branch configurations
    branch {
      regex = ".+" // regex for the branch you want to configure, put this one last
      incrementer = "NO_VERSION_INCREMENTER" // (default) version incrementer
      formatter = Transformer {
        "${semver.info.version.major}.${semver.info.version.minor}.${semver.info.version.patch}"
      }
    }
  }
}

benkeil avatar Apr 04 '23 03:04 benkeil

The problem is missing environment variables in the ProcessBuilder.

As a test:

fun String.runCommand(workingDir: File): String? {
  try {
    println(">> workingDir: $workingDir")
    val parts = this.split("\\s".toRegex())
    return ProcessBuilder(*parts.toTypedArray())
      .directory(workingDir)
      .redirectOutput(ProcessBuilder.Redirect.PIPE)
      .redirectError(ProcessBuilder.Redirect.PIPE)
      .also { it.environment().putAll(System.getenv()) }
      .start()
      .apply { waitFor(10, TimeUnit.SECONDS) }
      .inputStream.bufferedReader().readText()
  } catch(e: IOException) {
    e.printStackTrace()
    return null
  }
}

println("git status -s".runCommand(rootProject.rootDir))
println(GitCommandRunner.execute(project.projectDir, arrayOf("status", "-s")))

benkeil avatar Apr 04 '23 05:04 benkeil