ci: Cache Playwright Docker image between runs#2228
Conversation
Add caching for the Playwright Docker image to speed up CI and reduce network pulls. The workflow now computes a slugified image path and cache key, restores a cached tarball, loads it with docker load when available, and skips pulling if the image is already present. If no cache hit occurs and the image is pulled, it is saved to a tar file and persisted to the actions cache. Uses actions/cache v4 and adds outputs (image, cache-dir, cache-file, cache-key, pulled) to coordinate steps.
Replace the synchronous is_element_scrolled_to_bottom evaluator with a SCROLLED_TO_BOTTOM_SCRIPT constant and a new expect_element_scrolled_to_bottom(page, selector, timeout=30000) helper that uses page.wait_for_function. Update the test to call the new helper (removing the manual boolean check and assert). This makes the scroll-to-bottom assertion wait for asynchronous scrolling and reduces test flakiness.
Remove a stray blank line between the imports and the SCROLLED_TO_BOTTOM_SCRIPT constant in tests/playwright/shiny/components/MarkdownStream/basic/test_stream_basic.py. Pure whitespace cleanup with no behavioral change.
There was a problem hiding this comment.
Pull request overview
This PR speeds up Playwright-based CI by caching the Playwright Docker image between runs, and improves a Playwright UI test assertion by switching from a one-shot check to a wait-based expectation.
Changes:
- Add GitHub Actions cache restore/load/save steps for the Playwright Docker image in the remote Playwright setup composite action.
- Refactor the MarkdownStream “scrolled to bottom” test helper to use
page.wait_for_functionfor a more reliable assertion.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
.github/py-shiny/setup-playwright-remote/action.yaml |
Adds restore/load/pull/save steps to cache the Playwright Docker image keyed by Playwright version + runner OS/arch. |
tests/playwright/shiny/components/MarkdownStream/basic/test_stream_basic.py |
Replaces a boolean helper with a wait-based expectation for “scrolled to bottom”. |
| - name: Save Playwright image to cache | ||
| if: steps.restore-image-cache.outputs.cache-hit != 'true' && steps.pull-image.outputs.pulled == 'true' | ||
| shell: bash | ||
| run: | | ||
| IMAGE="${{ steps.image-cache-key.outputs.image }}" | ||
| CACHE_FILE="${{ steps.image-cache-key.outputs.cache-file }}" | ||
| echo "Saving $IMAGE to $CACHE_FILE" | ||
| docker save "$IMAGE" -o "$CACHE_FILE" | ||
|
|
||
| - name: Persist Playwright image cache | ||
| if: steps.restore-image-cache.outputs.cache-hit != 'true' && steps.pull-image.outputs.pulled == 'true' | ||
| uses: actions/cache/save@v4 | ||
| with: | ||
| path: ${{ steps.image-cache-key.outputs.cache-dir }} | ||
| key: ${{ steps.image-cache-key.outputs.cache-key }} |
There was a problem hiding this comment.
The save/persist steps are gated on cache-hit != 'true'. If a restore reports a hit but the image couldn’t be loaded (missing tar, load failure, wrong tag), the pull step will re-download the image but these steps won’t refresh the cache, so subsequent runs will keep missing. Consider gating cache save on “pulled == true” and a separate “cache_loaded == false” flag (instead of cache-hit), or otherwise ensuring the cache can be repaired when the restored contents are unusable.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Done in a848953. Removed the cache-hit != 'true' guard from both "Save" and "Persist" steps so they now run whenever pulled == 'true'. This means if a cache hit occurs but the tar is corrupt/missing and the image gets re-pulled, the cache will be refreshed and subsequent runs won't keep hitting the same stale entry.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ache entries Agent-Logs-Url: https://github.com/posit-dev/py-shiny/sessions/d769a58c-6581-4578-b76b-bb68a5863447 Co-authored-by: karangattu <4220325+karangattu@users.noreply.github.com>
This pull request introduces an image caching mechanism to the Playwright setup workflow in
.github/py-shiny/setup-playwright-remote/action.yamlto speed up CI runs by avoiding redundant image pulls. Additionally, it refactors a Playwright test utility intest_stream_basic.pyfor improved reliability and readability.CI/CD improvements:
Testing improvements:
test_stream_basic.pyby replacing theis_element_scrolled_to_bottomfunction withexpect_element_scrolled_to_bottom, which uses Playwright'swait_for_functionfor more robust and reliable assertions.