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

read sha as batch id #31

Merged
merged 14 commits into from
Jul 28, 2022
31 changes: 30 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ jobs:
command: |
circle-android wait-for-boot

- run: bazel test --define=APPLITOOLS_KEY=${APPLITOOLS_KEY} --define=CIRCLE_BUILD_NUM=${CIRCLE_BUILD_NUM} --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY} --config=skip-ios --config=ci -- //android/demo:android_instrumentation_test
- run: bazel test --define=APPLITOOLS_API_KEY=${APPLITOOLS_API_KEY} --define=APPLITOOLS_BATCH_ID=${CIRCLE_SHA1} --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY} --config=ci -- //android/demo:android_instrumentation_test

- store_artifacts:
path: screenshots
Expand Down Expand Up @@ -264,6 +264,20 @@ jobs:
export CIRCLE_BUILD_NUMBER=$(cat .ios-build-number)
npx auto shipit --only-graduate-with-release-label -vv

applitools_init:
executor: base
steps:
- run:
name: Initialize Applitools
command: curl -L -d '' -X POST "$APPLITOOLS_SERVER_URL/api/externals/github/push?apiKey=$APPLITOOLS_API_KEY&CommitSha=$CIRCLE_SHA1&BranchName=$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/$CIRCLE_BRANCH"

applitools_cleanup:
executor: base
steps:
- run:
name: Cleanup Applitools
command: "curl -X POST \"$APPLITOOLS_SERVER_URL/api/externals/github/servers/github.com/commit/$CIRCLE_SHA1/complete?apiKey=$APPLITOOLS_API_KEY\" -H Content-Type:application/json --data '{\"serverId\": \"github.com\", \"commitSha\": \"$CIRCLE_SHA1\"}' -v -L"

workflows:
build_and_test_pr:
jobs:
Expand All @@ -276,12 +290,19 @@ workflows:
tags:
ignore: /.*/

- applitools_init:
context:
- applitools
requires:
- setup

- build:
requires:
- setup

- build_ios:
requires:
- applitools_init
- setup

- test:
Expand All @@ -292,12 +313,20 @@ workflows:
context:
- applitools
requires:
- applitools_init
- build

- coverage:
requires:
- build

- applitools_cleanup:
context:
- applitools
requires:
- android_test
- build_ios

build_and_test_main:
when:
equal: [ "", << pipeline.parameters.GHA_Action >> ]
Expand Down
42 changes: 21 additions & 21 deletions android/build.bzl
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
def _values_to_const(k, v):
return "public val %s = %s;" % (k, v)
return "public val %s = %s;" % (k, v)

def _applitools_config_impl(ctx, **kwargs):
o = ctx.actions.declare_file("ApplitoolsConfig.kt")
head = [
"package %s;" % ctx.attr.package,
"public object ApplitoolsConfig {",
" public val APPLITOOLS_KEY = " + ("\"" + ctx.var["APPLITOOLS_KEY"] + "\"" if "APPLITOOLS_KEY" in ctx.var else "\"UNSET\""),
" public val BATCH_ID = " + ("\"" + ctx.var["CIRCLE_BUILD_NUM"] + "\"" if "CIRCLE_BUILD_NUM" in ctx.var else "\"local\"")
]
last = ["}"]
values = ctx.attr.values
xs = [_values_to_const(x, values[x]) for x in values]
ctx.actions.write(o, "\n".join(
head + xs + last
))
return [DefaultInfo(files = depset([o])), OutputGroupInfo(all_files = depset([o]))]
o = ctx.actions.declare_file("ApplitoolsConfig.kt")
head = [
"package %s;" % ctx.attr.package,
"public object ApplitoolsConfig {",
" public val API_KEY = " + ("\"" + ctx.var["APPLITOOLS_API_KEY"] + "\"" if "APPLITOOLS_API_KEY" in ctx.var else "\"UNSET\""),
" public val BATCH_ID = " + ("\"" + ctx.var["APPLITOOLS_BATCH_ID"] + "\"" if "APPLITOOLS_BATCH_ID" in ctx.var else "\"local\""),
]
last = ["}"]
values = ctx.attr.values
xs = [_values_to_const(x, values[x]) for x in values]
ctx.actions.write(o, "\n".join(
head + xs + last,
))
return [DefaultInfo(files = depset([o])), OutputGroupInfo(all_files = depset([o]))]

applitools_config = rule(
implementation = _applitools_config_impl,
output_to_genfiles = True,
attrs = {
"values": attr.string_dict(doc = "BuildConfig values, KEY -> VALUE"),
"package": attr.string(mandatory = True, doc = "package for generated class"),
},
implementation = _applitools_config_impl,
output_to_genfiles = True,
attrs = {
"values": attr.string_dict(doc = "BuildConfig values, KEY -> VALUE"),
"package": attr.string(mandatory = True, doc = "package for generated class"),
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import com.applitools.eyes.android.common.config.Configuration
import com.applitools.eyes.android.components.androidx.AndroidXComponentsProvider
import com.applitools.eyes.android.espresso.Eyes
import com.applitools.eyes.android.espresso.fluent.Target
import com.intuit.player.android.reference.demo.ApplitoolsConfig
import com.intuit.player.android.reference.demo.ApplitoolsConfig.API_KEY
import com.intuit.player.android.reference.demo.ApplitoolsConfig.BATCH_ID
import com.intuit.player.android.reference.demo.R

abstract class ApplitoolsTest {
Expand All @@ -23,8 +24,10 @@ abstract class ApplitoolsTest {
Eyes().apply {
componentsProvider = AndroidXComponentsProvider()
configuration = Configuration().apply {
appName = "Android Reference Assets"
addProperty("platform", "android")
batch = batchInfo
apiKey = ApplitoolsConfig.APPLITOOLS_KEY
apiKey = API_KEY
setFeatures(Feature.PIXEL_COPY_SCREENSHOT)
setServerUrl("https://intuiteyesapi.applitools.com")
}
Expand All @@ -44,6 +47,9 @@ abstract class ApplitoolsTest {
fun Eyes.checkPlayer(name: String) = check(name, Target.region(ViewMatchers.withId(R.id.player_canvas)))

companion object {
val batchInfo = BatchInfo("android-reference-assets@${ApplitoolsConfig.BATCH_ID}")
val batchInfo = BatchInfo("android-reference-assets@${BATCH_ID}").apply {
// Only manually set the batch ID if it's not a hardcoded fallback
if (BATCH_ID != "local") id = BATCH_ID
}
}
}