Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ repos:
files: ^release-notes\.md$
pass_filenames: false

- id: sync-playwright-version
name: Sync Playwright Docker image version
entry: uv run python scripts/update_playwright_version.py
language: unsupported
files: ^frontend/(package\.json|Dockerfile\.playwright)$|^scripts/update_playwright_version\.py$
pass_filenames: false

- id: zizmor
name: zizmor
language: python
Expand Down
32 changes: 32 additions & 0 deletions scripts/update_playwright_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Keep the Playwright Docker image version in sync with the frontend dependency."""

import json
import re
from pathlib import Path


def main() -> None:
package = json.loads(Path("frontend/package.json").read_text())
version = package["devDependencies"]["@playwright/test"]
if not isinstance(version, str) or not re.fullmatch(
r"[0-9]+\.[0-9]+\.[0-9]+", version
):
raise SystemExit("@playwright/test must be pinned to an exact X.Y.Z version")

dockerfile = Path("frontend/Dockerfile.playwright")
content = dockerfile.read_text()
updated_content, count = re.subn(
r"(?m)^FROM mcr\.microsoft\.com/playwright:v[0-9]+\.[0-9]+\.[0-9]+-([a-z]+)$",
rf"FROM mcr.microsoft.com/playwright:v{version}-\g<1>",
content,
)
if count != 1:
raise SystemExit("Expected exactly one versioned `Playwright FROM` line")

if updated_content != content:
dockerfile.write_text(updated_content)
print(f"Updated Playwright Docker image to {version}")


if __name__ == "__main__":
main()