Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diff.patch not correctly created when running inside CI #16

Closed
locomike opened this issue Aug 3, 2021 · 3 comments · Fixed by #18
Closed

diff.patch not correctly created when running inside CI #16

locomike opened this issue Aug 3, 2021 · 3 comments · Fixed by #18
Assignees
Labels
bug Something isn't working

Comments

@locomike
Copy link

locomike commented Aug 3, 2021

I have configured the project to run correctly locally using git configuration to get the diff.

This is my configuration:

diffCoverageReport {
      def targetBranch = project.getProperties().get("targetBranch") ?: "development"
      diffSource {
          git.compareWith targetBranch
      }

      jacocoExecFiles = files(jacocoTestReport.executionData)
      classesDirs = files(jacocoTestReport.classDirectories)
      srcDirs = files(jacocoTestReport.sourceDirectories)

      reports {
          html = true
          xml = true
      }

      violationRules {
          minBranches = 1
          minLines = 1
          minInstructions = 1
          failOnViolation = true
      }
}

However, when I run inside Gitlab CI/CD, the execution fails because it cannot create diff.patch. I believe the issue is becuase the folder where it wants to create it, build/reports/jacoco/, because if I pre-create this folder empty, then the plugin finishes successfully.

This is the exception:

Caused by: java.io.FileNotFoundException: /builds/android/<REPO>/build/reports/jacoco/diff.patch (No such file or directory)
	at kotlin.io.FilesKt__FileReadWriteKt.writeBytes(FileReadWrite.kt:108)
	at kotlin.io.FilesKt__FileReadWriteKt.writeText(FileReadWrite.kt:134)
	at kotlin.io.FilesKt__FileReadWriteKt.writeText$default(FileReadWrite.kt:134)
	at com.form.coverage.tasks.git.GitDiffSource.saveDiffTo(DiffSource.kt:67)
	at com.form.coverage.tasks.DiffCoverageTask.obtainUpdatesInfo(DiffCoverageTask.kt:109)
	at com.form.coverage.tasks.DiffCoverageTask.executeAction(DiffCoverageTask.kt:61)
	at com.form.coverage.tasks.DiffCoverageTask$executeAction.call(Unknown Source)

I verified that /builds/android/<REPO> exists and it is the root of my project. I also verified that simply running mkdir -p ./build/reports/jacoco before running my gradlew command fixes it.

Can you help me identify why the folder would be successfully created when running locally but fails when running inside CI?

@SurpSG
Copy link
Contributor

SurpSG commented Aug 3, 2021

Hi @locomike
Could you please check if the issue is reproducible on this version?

'com.github.form-com.diff-coverage-gradle:diff-coverage:precreate-reports-dir-SNAPSHOT'

If it still reproducible then enable debug logs:

./gradlew diffCoverage -d

There are a few extra logs was added to help us to investigate what went wrong

@locomike
Copy link
Author

locomike commented Aug 3, 2021

That fixed it, thanks so much for the prompt fix!

Any idea why creating the dir is needed in CI but not in Desktop? Maybe some kind of race condition?

@SurpSG SurpSG self-assigned this Aug 4, 2021
@SurpSG SurpSG linked a pull request Aug 4, 2021 that will close this issue
@SurpSG SurpSG added the bug Something isn't working label Aug 4, 2021
@SurpSG
Copy link
Contributor

SurpSG commented Aug 4, 2021

Hi @locomike
AFAIK Gradle is responsible for creating of the report dir, because the dir is declared as output

@OutputDirectory
fun getOutputDir(): File {
return project.getReportOutputDir().toFile()
}

I wasn't able to reporoduce the issue on my env. We will merge the fix you tested to make sure the output dir exists.
And I have no idea why it works on your local env but doesn't on your CI env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants