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

Support configuration cache #291

Merged
merged 2 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions shot/src/main/scala/com/karumi/shot/ShotPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,35 +174,75 @@ class ShotPlugin extends Plugin[Project] {
removeScreenshotsAfterExecution.configure { task =>
task.setDescription(RemoveScreenshotsTask.description(flavor, buildType))
task.flavor = flavor
task.buildType = buildType
task.buildTypeName = buildType.getName
task.appId = appId
task.orchestrated = orchestrated
task.projectPath = project.getProjectDir.getAbsolutePath
task.buildPath = project.getBuildDir.getAbsolutePath
task.shotExtension = project.getExtensions.findByType(classOf[ShotExtension])
task.directorySuffix =
if (project.hasProperty("directorySuffix"))
Some(project.property("directorySuffix").toString)
else None
task.recordScreenshots = project.hasProperty("record")
task.printBase64 = project.hasProperty("printBase64")
task.projectName = project.getName
}
removeScreenshotsBeforeExecution.configure { task =>
task.setDescription(RemoveScreenshotsTask.description(flavor, buildType))
task.flavor = flavor
task.buildType = buildType
task.buildTypeName = buildType.getName
task.appId = appId
task.orchestrated = orchestrated
task.projectPath = project.getProjectDir.getAbsolutePath
task.buildPath = project.getBuildDir.getAbsolutePath
task.shotExtension = project.getExtensions.findByType(classOf[ShotExtension])
task.directorySuffix =
if (project.hasProperty("directorySuffix"))
Some(project.property("directorySuffix").toString)
else None
task.recordScreenshots = project.hasProperty("record")
task.printBase64 = project.hasProperty("printBase64")
task.projectName = project.getName
}

val downloadScreenshots = tasks
.register(DownloadScreenshotsTask.name(flavor, buildType), classOf[DownloadScreenshotsTask])
downloadScreenshots.configure { task =>
task.setDescription(DownloadScreenshotsTask.description(flavor, buildType))
task.flavor = flavor
task.buildType = buildType
task.buildTypeName = buildType.getName
task.appId = appId
task.orchestrated = orchestrated
task.projectPath = project.getProjectDir.getAbsolutePath
task.buildPath = project.getBuildDir.getAbsolutePath
task.shotExtension = project.getExtensions.findByType(classOf[ShotExtension])
task.directorySuffix =
if (project.hasProperty("directorySuffix"))
Some(project.property("directorySuffix").toString)
else None
task.recordScreenshots = project.hasProperty("record")
task.printBase64 = project.hasProperty("printBase64")
task.projectName = project.getName
}
val executeScreenshot = tasks
.register(ExecuteScreenshotTests.name(flavor, buildType), classOf[ExecuteScreenshotTests])
executeScreenshot.configure { task =>
task.setDescription(ExecuteScreenshotTests.description(flavor, buildType))
task.flavor = flavor
task.buildType = buildType
task.buildTypeName = buildType.getName
task.appId = appId
task.orchestrated = orchestrated
task.projectPath = project.getProjectDir.getAbsolutePath
task.buildPath = project.getBuildDir.getAbsolutePath
task.shotExtension = project.getExtensions.findByType(classOf[ShotExtension])
task.directorySuffix =
if (project.hasProperty("directorySuffix"))
Some(project.property("directorySuffix").toString)
else None
task.recordScreenshots = project.hasProperty("record")
task.printBase64 = project.hasProperty("printBase64")
task.projectName = project.getName
}

if (runInstrumentation(project, extension)) {
Expand Down
42 changes: 19 additions & 23 deletions shot/src/main/scala/com/karumi/shot/tasks/Tasks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ import org.gradle.api.{DefaultTask, GradleException}
import java.io.File

abstract class ShotTask extends DefaultTask {
var appId: String = _
var flavor: Option[String] = _
var buildType: BuildType = _
var orchestrated: Boolean = false
private val console = new Console
var appId: String = _
var flavor: Option[String] = _
var buildTypeName: String = _
var orchestrated: Boolean = false
var projectPath: String = _
var buildPath: String = _
var shotExtension: ShotExtension = _
var directorySuffix: Option[String] = _
var recordScreenshots: Boolean = _
var printBase64: Boolean = _
var projectName: String = _
private val console = new Console
protected val shot: Shot =
new Shot(
new Adb,
Expand All @@ -36,18 +43,14 @@ abstract class ShotTask extends DefaultTask {
new ConsoleReporter(console),
new EnvVars()
)
protected val shotExtension: ShotExtension =
getProject.getExtensions.findByType(classOf[ShotExtension])

protected def shotFolder: ShotFolder = {
val project = getProject
ShotFolder(
project.getProjectDir.getAbsolutePath,
project.getBuildDir.getAbsolutePath,
buildType.getName,
projectPath,
buildPath,
buildTypeName,
flavor,
if (project.hasProperty("directorySuffix")) Some(project.property("directorySuffix").toString)
else None,
directorySuffix,
File.separator,
orchestrated
)
Expand Down Expand Up @@ -77,22 +80,15 @@ class ExecuteScreenshotTests extends ShotTask {

@TaskAction
def executeScreenshotTests(): Unit = {
val project = getProject
val tolerance = project.getExtensions
.getByType[ShotExtension](classOf[ShotExtension])
.tolerance
val recordScreenshots = project.hasProperty("record")
val printBase64 = project.hasProperty("printBase64")
val showOnlyFailingTestsInReports = project.getExtensions
.getByType[ShotExtension](classOf[ShotExtension])
.showOnlyFailingTestsInReports
val tolerance = shotExtension.tolerance
val showOnlyFailingTestsInReports = shotExtension.showOnlyFailingTestsInReports
if (recordScreenshots) {
shot.recordScreenshots(appId, shotFolder, orchestrated)
} else {
val result = shot.verifyScreenshots(
appId,
shotFolder,
project.getName,
projectName,
printBase64,
tolerance,
showOnlyFailingTestsInReports,
Expand Down