Skip to content

Commit 9544a99

Browse files
authored
Merge pull request #1270 from square/ray/stable-ci
Adds `STABLE_EVENT_HANDLERS` to runtime config tools, CI
2 parents 687a4e2 + 42f90cf commit 9544a99

File tree

3 files changed

+86
-59
lines changed

3 files changed

+86
-59
lines changed

.github/workflows/kotlin.yml

+25-3
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ jobs :
212212
- name : Check with Gradle
213213
uses : ./.github/actions/gradle-task
214214
with :
215-
task : jvmTest --continue -Pworkflow.runtime=baseline-stateChange
215+
task : jvmTest --continue -Pworkflow.runtime=stateChange
216216
restore-cache-key : main-build-artifacts
217217

218218
# Report as GitHub Pull Request Check.
@@ -222,6 +222,27 @@ jobs :
222222
with :
223223
report_paths : '**/build/test-results/test/TEST-*.xml'
224224

225+
jvm-stable-handlers-test:
226+
name: Stable Event Handlers Only Runtime JVM Tests
227+
runs-on: ubuntu-latest
228+
timeout-minutes: 20
229+
steps:
230+
- name: Checkout
231+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
232+
233+
- name: Check with Gradle
234+
uses: ./.github/actions/gradle-task
235+
with:
236+
task: jvmTest --continue -Pworkflow.runtime=stable
237+
restore-cache-key: main-build-artifacts
238+
239+
# Report as GitHub Pull Request Check.
240+
- name: Publish Test Report
241+
uses: mikepenz/action-junit-report@5f47764eec0e1c1f19f40c8e60a5ba47e47015c5 # v4
242+
if: always() # always run even if the previous step fails
243+
with:
244+
report_paths: '**/build/test-results/test/TEST-*.xml'
245+
225246
jvm-partial-runtime-test:
226247
name: Partial Tree Rendering Only Runtime JVM Tests
227248
runs-on: ubuntu-latest
@@ -233,7 +254,7 @@ jobs :
233254
- name: Check with Gradle
234255
uses: ./.github/actions/gradle-task
235256
with:
236-
task: jvmTest --continue -Pworkflow.runtime=baseline-partial
257+
task: jvmTest --continue -Pworkflow.runtime=partial
237258
restore-cache-key: main-build-artifacts
238259

239260
# Report as GitHub Pull Request Check.
@@ -391,7 +412,7 @@ jobs :
391412
### <start-connected-check-shards>
392413
shardNum: [ 1, 2, 3 ]
393414
### <end-connected-check-shards>
394-
runtime : [ conflate, baseline-stateChange, conflate-stateChange, baseline-partial, conflate-partial ]
415+
runtime : [ conflate, stateChange, conflate-stateChange, partial, conflate-partial, stable ]
395416
steps :
396417
- name: Checkout
397418
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
@@ -421,6 +442,7 @@ jobs :
421442
- js-tests
422443
- jvm-conflate-runtime-test
423444
- jvm-stateChange-runtime-test
445+
- jvm-stable-handlers-test
424446
- jvm-partial-runtime-test
425447
- jvm-conflate-stateChange-runtime-test
426448
- jvm-conflate-partial-runtime-test

workflow-config/config-android/src/main/java/com/squareup/workflow1/config/AndroidRuntimeConfigTools.kt

+29-27
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,54 @@ import com.squareup.workflow1.RuntimeConfigOptions
55
import com.squareup.workflow1.RuntimeConfigOptions.CONFLATE_STALE_RENDERINGS
66
import com.squareup.workflow1.RuntimeConfigOptions.PARTIAL_TREE_RENDERING
77
import com.squareup.workflow1.RuntimeConfigOptions.RENDER_ONLY_WHEN_STATE_CHANGES
8+
import com.squareup.workflow1.RuntimeConfigOptions.STABLE_EVENT_HANDLERS
89
import com.squareup.workflow1.WorkflowExperimentalRuntime
910

1011
public class AndroidRuntimeConfigTools {
11-
1212
public companion object {
1313
/**
1414
* Helper for Configuration for the workflow runtime in an application.
1515
* This allows one to specify a project property from the gradle build to choose a runtime.
16-
* e.g. add "-Pworkflow.runtime=conflate" in your gradle build to build the conflate runtime
16+
* e.g. add `-Pworkflow.runtime=conflate` in your gradle build to build the conflate runtime
1717
* into the application.
1818
*
1919
* Note that this must be specified in the application built for any ui/integration tests. Call
20-
* this function, and then pass that to the call to [renderWorkflowIn] as the [RuntimeConfig].
20+
* this function and pass the result to [renderWorkflowIn][com.squareup.workflow1.renderWorkflowIn]
21+
* as the [RuntimeConfig] parameter.
22+
*
23+
* Current options (can be combined with `-` characters, e.g. `conflate-partial`):
2124
*
22-
* Current options are:
23-
* "conflate" : Process all queued actions before passing rendering
24-
* to the UI layer.
25-
* "baseline" : Original Workflow Runtime. Note that this doesn't need to
26-
* be specified as it is the current default and is assumed by this utility.
25+
* - `conflate` Process all queued actions before passing rendering to the UI layer.
2726
*
28-
* Then, these can be combined (via '-') with:
29-
* "stateChange" : Only re-render when the state of some WorkflowNode has been changed by an
27+
* - `stateChange` Only re-render when the state of some WorkflowNode has been changed by an
3028
* action cascade.
31-
* "partial" : Which includes "stateChange" as well as partial tree rendering, which only
32-
* re-renders each Workflow node if: 1) its state changed; or 2) one of its descendant's state
33-
* changed.
3429
*
35-
* E.g., "baseline-stateChange" to turn on the stateChange option with the baseline runtime.
30+
* - `partial` Partial tree rendering, which only re-renders each Workflow node if: 1) its
31+
* state changed; or 2) one of its descendant's state changed. (This option requires
32+
* `stateChange`, and enables it as well.)
3633
*
34+
* - `stable` Enables stable event handlers (changes the default value of the `remember`
35+
* parameter of `RenderContext.eventHandler` functions from `false` to `true`)
3736
*/
3837
@WorkflowExperimentalRuntime
3938
public fun getAppWorkflowRuntimeConfig(): RuntimeConfig {
40-
return when (BuildConfig.WORKFLOW_RUNTIME) {
41-
"conflate" -> setOf(CONFLATE_STALE_RENDERINGS)
42-
"conflate-stateChange" -> setOf(CONFLATE_STALE_RENDERINGS, RENDER_ONLY_WHEN_STATE_CHANGES)
43-
"baseline-stateChange" -> setOf(RENDER_ONLY_WHEN_STATE_CHANGES)
44-
"conflate-partial" -> setOf(
45-
CONFLATE_STALE_RENDERINGS,
46-
RENDER_ONLY_WHEN_STATE_CHANGES,
47-
PARTIAL_TREE_RENDERING
48-
)
49-
"baseline-partial" -> setOf(RENDER_ONLY_WHEN_STATE_CHANGES, PARTIAL_TREE_RENDERING)
50-
"", "baseline" -> RuntimeConfigOptions.RENDER_PER_ACTION
51-
else ->
52-
throw IllegalArgumentException("Unrecognized config \"${BuildConfig.WORKFLOW_RUNTIME}\"")
39+
val selection = BuildConfig.WORKFLOW_RUNTIME.split("-")
40+
// We used to have a no-op `baseline` option, let's not choke on it.
41+
.filterNot { it == "baseline" || it.isBlank() }
42+
.toSet()
43+
44+
val config = mutableSetOf<RuntimeConfigOptions>()
45+
selection.forEach {
46+
when (it) {
47+
"conflate" -> config.add(CONFLATE_STALE_RENDERINGS)
48+
"stateChange" -> config.add(RENDER_ONLY_WHEN_STATE_CHANGES)
49+
"partial" -> config.addAll(setOf(RENDER_ONLY_WHEN_STATE_CHANGES, PARTIAL_TREE_RENDERING))
50+
"stable" -> config.add(STABLE_EVENT_HANDLERS)
51+
else -> throw IllegalArgumentException("Unrecognized runtime config option \"$it\"")
52+
}
5353
}
54+
55+
return config
5456
}
5557
}
5658
}

workflow-config/config-jvm/src/main/java/com/squareup/workflow1/config/JvmTestRuntimeConfigTools.kt

+32-29
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,56 @@ import com.squareup.workflow1.RuntimeConfigOptions
55
import com.squareup.workflow1.RuntimeConfigOptions.CONFLATE_STALE_RENDERINGS
66
import com.squareup.workflow1.RuntimeConfigOptions.PARTIAL_TREE_RENDERING
77
import com.squareup.workflow1.RuntimeConfigOptions.RENDER_ONLY_WHEN_STATE_CHANGES
8+
import com.squareup.workflow1.RuntimeConfigOptions.STABLE_EVENT_HANDLERS
89
import com.squareup.workflow1.WorkflowExperimentalRuntime
910

1011
public class JvmTestRuntimeConfigTools {
1112
public companion object {
1213
/**
1314
* Helper for Configuration for the workflow runtime in an application.
1415
* This allows one to specify a project property from the gradle build to choose a runtime.
15-
* e.g. add "-Pworkflow.runtime=conflate" in your gradle build to build the conflate runtime
16+
* e.g. add `-Pworkflow.runtime=conflate` in your gradle build to build the conflate runtime
1617
* into the application.
1718
*
18-
* The [WorkflowTestRuntime] already calls this utility, but if starting your own runtime, then
19-
* call this function and pass the result to the call to [renderWorkflowIn] as the
20-
* [RuntimeConfig].
19+
* The [WorkflowTestRuntime][com.squareup.workflow1.testing.WorkflowTestRuntime]
20+
* and [RenderTester][com.squareup.workflow1.testing.RenderTester] runtimes
21+
* already call this utility. To honor this property from your own runtime call this
22+
* function and pass the result to the call to
23+
* [renderWorkflowIn][com.squareup.workflow1.renderWorkflowIn] as the [RuntimeConfig] parameter.
2124
*
22-
* Current options are:
23-
* "conflate" : Process all queued actions before passing rendering
24-
* to the UI layer.
25-
* "baseline" : Original Workflow Runtime. Note that this doesn't need to
26-
* be specified as it is the current default and is assumed by this utility.
25+
* Current options (can be combined with `-` characters, e.g. `conflate-partial`):
2726
*
28-
* Then, these can be combined (via '-') with:
29-
* "stateChange" : Only re-render when the state of some WorkflowNode has been changed by an
27+
* - `conflate` Process all queued actions before passing rendering to the UI layer.
28+
*
29+
* - `stateChange` Only re-render when the state of some WorkflowNode has been changed by an
3030
* action cascade.
31-
* "partial" : Which includes "stateChange" as well as partial tree rendering, which only
32-
* re-renders each Workflow node if: 1) its state changed; or 2) one of its descendant's state
33-
* changed.
3431
*
35-
* E.g., "baseline-stateChange" to turn on the stateChange option with the baseline runtime.
32+
* - `partial` Partial tree rendering, which only re-renders each Workflow node if: 1) its
33+
* state changed; or 2) one of its descendant's state changed. (This option requires
34+
* `stateChange`, and enables it as well.)
3635
*
36+
* - `stable` Enables stable event handlers (changes the default value of the `remember`
37+
* parameter of `RenderContext.eventHandler` functions from `false` to `true`)
3738
*/
3839
@OptIn(WorkflowExperimentalRuntime::class)
3940
public fun getTestRuntimeConfig(): RuntimeConfig {
40-
return when
41-
(val runtimeConfig = System.getProperty("workflow.runtime", "baseline")) {
42-
"conflate" -> setOf(CONFLATE_STALE_RENDERINGS)
43-
"conflate-stateChange" -> setOf(CONFLATE_STALE_RENDERINGS, RENDER_ONLY_WHEN_STATE_CHANGES)
44-
"baseline-stateChange" -> setOf(RENDER_ONLY_WHEN_STATE_CHANGES)
45-
"conflate-partial" -> setOf(
46-
CONFLATE_STALE_RENDERINGS,
47-
RENDER_ONLY_WHEN_STATE_CHANGES,
48-
PARTIAL_TREE_RENDERING
49-
)
50-
"baseline-partial" -> setOf(RENDER_ONLY_WHEN_STATE_CHANGES, PARTIAL_TREE_RENDERING)
51-
"", "baseline" -> RuntimeConfigOptions.RENDER_PER_ACTION
52-
else ->
53-
throw IllegalArgumentException("Unrecognized config \"$runtimeConfig\"")
41+
val selection = System.getProperty("workflow.runtime", "").split("-")
42+
// We used to have a no-op `baseline` option, let's not choke on it.
43+
.filterNot { it == "baseline" || it.isBlank() }
44+
.toSet()
45+
46+
val config = mutableSetOf<RuntimeConfigOptions>()
47+
selection.forEach {
48+
when (it) {
49+
"conflate" -> config.add(CONFLATE_STALE_RENDERINGS)
50+
"stateChange" -> config.add(RENDER_ONLY_WHEN_STATE_CHANGES)
51+
"partial" -> config.addAll(setOf(RENDER_ONLY_WHEN_STATE_CHANGES, PARTIAL_TREE_RENDERING))
52+
"stable" -> config.add(STABLE_EVENT_HANDLERS)
53+
else -> throw IllegalArgumentException("Unrecognized runtime config option \"$it\"")
54+
}
5455
}
56+
57+
return config
5558
}
5659
}
5760
}

0 commit comments

Comments
 (0)