Skip to content

ci: Cache Playwright Docker image between runs#2228

Open
karangattu wants to merge 6 commits intomainfrom
cache-docker-images
Open

ci: Cache Playwright Docker image between runs#2228
karangattu wants to merge 6 commits intomainfrom
cache-docker-images

Conversation

@karangattu
Copy link
Copy Markdown
Collaborator

@karangattu karangattu commented Apr 30, 2026

This pull request introduces an image caching mechanism to the Playwright setup workflow in .github/py-shiny/setup-playwright-remote/action.yaml to speed up CI runs by avoiding redundant image pulls. Additionally, it refactors a Playwright test utility in test_stream_basic.py for improved reliability and readability.

CI/CD improvements:

  • Added steps to compute a cache key, restore, load, save, and persist the Playwright Docker image using GitHub Actions cache, reducing redundant downloads and potentially speeding up CI runs. (.github/py-shiny/setup-playwright-remote/action.yaml)

Testing improvements:

  • Refactored the scroll-to-bottom check in test_stream_basic.py by replacing the is_element_scrolled_to_bottom function with expect_element_scrolled_to_bottom, which uses Playwright's wait_for_function for more robust and reliable assertions.
  • Cache key includes the resolved Playwright version + runner.os/runner.arch, so each Playwright bump invalidates cleanly.
  • On cache hit, the image tar is loaded with docker load and the MCR pull is skipped entirely.
  • On cache miss, the existing retry-with-backoff pull runs, then the image is saved with docker save and uploaded with actions/cache/save.
  • Restore/save are split so a successful restore doesn't re-upload, and the save only runs when an actual pull happened.

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.
@cpsievert cpsievert requested a review from Copilot May 1, 2026 20:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_function for 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”.

Comment thread .github/py-shiny/setup-playwright-remote/action.yaml
Comment on lines +104 to +118
- 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 }}
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

karangattu and others added 3 commits May 1, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants