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

Add Fix workflow #6

Merged
merged 29 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f9d2430
Add Fix workflow
yschimke Feb 24, 2024
7a694ac
Add Fix workflow
yschimke Feb 24, 2024
bd84c99
Add Fix workflow
yschimke Feb 24, 2024
e32c56b
🤖 Updates screenshots
yschimke Feb 24, 2024
cf3214f
Switch java distribution for GitHub Actions setup-java
LouisCAD Feb 24, 2024
018caf8
Remove unused imports
LouisCAD Feb 24, 2024
b0cc72b
Add clarifying comment as to why auto-commits are not disabled on the…
LouisCAD Feb 24, 2024
a626a87
Merge branch 'main' into fix_workflow
yschimke Feb 24, 2024
96fe161
only update when outside tolerance
yschimke Feb 24, 2024
69e333b
Add screenshot tests
yschimke Feb 24, 2024
fe8871a
Add screenshot tests
yschimke Feb 24, 2024
a17715c
Back to mac images
yschimke Feb 24, 2024
97d94ad
Bump high tolerance
yschimke Feb 24, 2024
5e286f3
Bump high tolerance
yschimke Feb 24, 2024
e32d53b
Back to 0.02 for future larger diffs
yschimke Feb 24, 2024
87e93c6
Wrong path
yschimke Feb 24, 2024
6b20c70
Update workflow
yschimke Feb 24, 2024
c0de2b8
Update workflow
yschimke Feb 24, 2024
2292a34
Update workflow
yschimke Feb 24, 2024
6113d72
Update workflow
yschimke Feb 24, 2024
5971d5c
Update workflow
yschimke Feb 24, 2024
f6fb383
Update workflow
yschimke Feb 24, 2024
18060a0
Update workflow
yschimke Feb 24, 2024
610758a
Update workflow
yschimke Feb 24, 2024
4f3eb48
Fix workflow
yschimke Feb 24, 2024
bc5a710
Fix workflow
yschimke Feb 24, 2024
cecf87d
Avoid
yschimke Feb 24, 2024
89b7bb9
Avoid release tests
yschimke Feb 24, 2024
ac36205
Remove no longer needed workflow permission
LouisCAD Feb 24, 2024
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
30 changes: 28 additions & 2 deletions .github/workflows/build_workflow.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import io.github.typesafegithub.workflows.actions.actions.CheckoutV4
import io.github.typesafegithub.workflows.actions.actions.SetupJavaV4
import io.github.typesafegithub.workflows.actions.actions.UploadArtifactV4
import io.github.typesafegithub.workflows.actions.gradle.GradleBuildActionV3
import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest
import io.github.typesafegithub.workflows.domain.triggers.PullRequest
import io.github.typesafegithub.workflows.domain.triggers.Push
import io.github.typesafegithub.workflows.dsl.expressions.expr
import io.github.typesafegithub.workflows.dsl.workflow
import io.github.typesafegithub.workflows.yaml.writeToFile

Expand All @@ -19,17 +21,41 @@ workflow(
),
sourceFile = __FILE__.toPath(),
) {
job(id = "build-and-test", runsOn = UbuntuLatest) {
job(
id = "build-and-test",
runsOn = UbuntuLatest
) {
uses(name = "Check out", action = CheckoutV4())
uses(
name = "Setup Java",
action = SetupJavaV4(distribution = SetupJavaV4.Distribution.Temurin, javaVersion = "17")
action = SetupJavaV4(
distribution = SetupJavaV4.Distribution.Temurin,
javaVersion = "17"
)
)
uses(
name = "Build",
action = GradleBuildActionV3(
arguments = "test",
)
)
uses(
name = "Upload reports",
action = UploadArtifactV4(
name = "Roborazzi",
path = listOf("shared/build/outputs/roborazzi"),
retentionDays = UploadArtifactV4.RetentionPeriod.Default,
),
`if` = expr { always() }
)
uses(
name = "Upload test reports",
action = UploadArtifactV4(
name = "Junit",
path = listOf("**/build/reports/tests"),
retentionDays = UploadArtifactV4.RetentionPeriod.Default,
),
`if` = expr { always() }
)
}
}.writeToFile()
16 changes: 16 additions & 0 deletions .github/workflows/build_workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,19 @@ jobs:
uses: 'gradle/gradle-build-action@v3'
with:
arguments: 'test'
- id: 'step-3'
name: 'Upload reports'
uses: 'actions/upload-artifact@v4'
with:
name: 'Roborazzi'
path: 'shared/build/outputs/roborazzi'
retention-days: '0'
if: '${{ always() }}'
- id: 'step-4'
name: 'Upload test reports'
uses: 'actions/upload-artifact@v4'
with:
name: 'Junit'
path: '**/build/reports/tests'
retention-days: '0'
if: '${{ always() }}'
50 changes: 50 additions & 0 deletions .github/workflows/fix_workflow.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env kotlin

@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.11.0")

import io.github.typesafegithub.workflows.actions.actions.CheckoutV4
import io.github.typesafegithub.workflows.actions.actions.SetupJavaV4
import io.github.typesafegithub.workflows.actions.gradle.GradleBuildActionV3
import io.github.typesafegithub.workflows.actions.stefanzweifel.GitAutoCommitActionV5
import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest
import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch
import io.github.typesafegithub.workflows.dsl.expressions.expr
import io.github.typesafegithub.workflows.dsl.workflow
import io.github.typesafegithub.workflows.yaml.writeToFile

workflow(
name = "Fix workflow",
on = listOf(
WorkflowDispatch(),
),
sourceFile = __FILE__.toPath(),
) {
job(
id = "fix-branch",
runsOn = UbuntuLatest,
// Ensure no auto-commits are ever made on the main/default branch.
// This is an extra security measure, especially since we don't control what the
// "stefanzweifel/git-auto-commit-action@v5" GitHub Action could theoretically do.
`if` = expr { github.ref_name + " != " + github.eventWorkflowDispatch.repository.default_branch }
) {
uses(name = "Check out", action = CheckoutV4())
uses(
name = "Setup Java",
action = SetupJavaV4(distribution = SetupJavaV4.Distribution.Temurin, javaVersion = "17")
)
uses(
name = "Record Screenshots",
action = GradleBuildActionV3(
arguments = "verifyAndRecordRoborazziDebug",
)
)
uses(
name = "Commit Screenshots",
action = GitAutoCommitActionV5(
filePattern = "**/src/test/screenshots/*.png",
disableGlobbing = true,
commitMessage = "🤖 Updates screenshots"
)
)
}
}.writeToFile()
48 changes: 48 additions & 0 deletions .github/workflows/fix_workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This file was generated using Kotlin DSL (.github/workflows/fix_workflow.main.kts).
# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file.
# Generated with https://github.com/typesafegithub/github-workflows-kt

name: 'Fix workflow'
on:
workflow_dispatch: {}
jobs:
check_yaml_consistency:
name: 'Check YAML consistency'
runs-on: 'ubuntu-latest'
steps:
- id: 'step-0'
name: 'Check out'
uses: 'actions/checkout@v4'
- id: 'step-1'
name: 'Execute script'
run: 'rm ''.github/workflows/fix_workflow.yaml'' && ''.github/workflows/fix_workflow.main.kts'''
- id: 'step-2'
name: 'Consistency check'
run: 'git diff --exit-code ''.github/workflows/fix_workflow.yaml'''
fix-branch:
runs-on: 'ubuntu-latest'
needs:
- 'check_yaml_consistency'
if: '${{ github.ref_name != github.event.repository.default_branch }}'
steps:
- id: 'step-0'
name: 'Check out'
uses: 'actions/checkout@v4'
- id: 'step-1'
name: 'Setup Java'
uses: 'actions/setup-java@v4'
with:
java-version: '17'
distribution: 'temurin'
- id: 'step-2'
name: 'Record Screenshots'
uses: 'gradle/gradle-build-action@v3'
with:
arguments: 'verifyAndRecordRoborazziDebug'
- id: 'step-3'
name: 'Commit Screenshots'
uses: 'stefanzweifel/git-auto-commit-action@v5'
with:
commit_message: '🤖 Updates screenshots'
file_pattern: '**/src/test/screenshots/*.png'
disable_globbing: 'true'
1 change: 1 addition & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ android {
}
buildFeatures {
compose = true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = versionFor(AndroidX.compose.compiler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,67 @@
@file:OptIn(ExperimentalRoborazziApi::class)

package org.splitties.compose.oclock.sample.watchfaces

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.github.takahirom.roborazzi.ExperimentalRoborazziApi
import com.github.takahirom.roborazzi.RoborazziOptions
import com.github.takahirom.roborazzi.ThresholdValidator
import com.github.takahirom.roborazzi.captureRoboImage
import com.louiscad.composeoclockplayground.shared.BuildConfig
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.Assume
import org.junit.Assume.assumeFalse
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import org.junit.rules.TestRule
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
import org.splitties.compose.oclock.OClockRootCanvas
import java.io.File

@Config(
sdk = [33],
qualifiers = "w227dp-h227dp-small-notlong-round-watch-xhdpi-keyshidden-nonav",
)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
abstract class ClockScreenshotTest {
@get:Rule
@get:Rule(order = 0)
val debugOnly = TestRule { base, _ ->
Assume.assumeTrue("Screenshot tests not supported for release", BuildConfig.DEBUG)

base
}

@get:Rule(order = 1)
val composeRule = createComposeRule()

abstract val device: WearDevice

// generous to allow for mac/linux differences
open val tolerance = 0.02f

open val roborazziOptions: RoborazziOptions
get() = RoborazziOptions(
compareOptions = RoborazziOptions.CompareOptions(
resultValidator = ThresholdValidator(tolerance)
)
)

@Before
fun check() {
// Robolectric RNG not supported on Windows
// https://github.com/robolectric/robolectric/issues/8312
assumeFalse(System.getProperty("os.name")?.startsWith("Windows") ?: false)
assumeFalse("Robolectric RNG not supported on Windows", System.getProperty("os.name")?.startsWith("Windows") ?: false)
}

fun runTest(isAmbient: Boolean = false, clock: @Composable () -> Unit) {
val filePath =
File("src/test/screenshots/${this.javaClass.simpleName}_${device.id}${if (isAmbient) "_ambient" else ""}.png")

RuntimeEnvironment.setQualifiers("+w${device.dp}dp-h${device.dp}dp")

composeRule.setContent {
Expand All @@ -50,6 +73,6 @@ abstract class ClockScreenshotTest {
}

composeRule.onRoot()
.captureRoboImage("src/test/screenshots/${this.javaClass.simpleName}_${device.id}${if (isAmbient) "_ambient" else ""}.png")
.captureRoboImage(filePath = filePath.path, roborazziOptions = roborazziOptions)
}
}
Loading