Skip to content
Merged
Changes from 4 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
28 changes: 19 additions & 9 deletions tests/playwright/utils/deploy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
import subprocess
import time
from typing import Any, Callable, TypeVar

import pytest
Expand Down Expand Up @@ -128,6 +129,18 @@ def write_requirements_txt(app_dir: str) -> None:
f.write(f"git+https://github.com/posit-dev/py-shiny.git@{git_hash}\n")


def assert_rsconnect_file_updated(file_path: str, max_minutes: int) -> None:
"""
Asserts that the specified file has been updated within the last `max_minutes` minutes.
"""
current_time = time.time()
mod_time = os.path.getmtime(file_path)
time_diff = (current_time - mod_time) / 60
assert (
time_diff < max_minutes
), f"File '{file_path}' was not updated within the last {max_minutes} minutes which means the deployment failed or was skipped"


def deploy_app(
app_file_path: str,
location: str,
Expand All @@ -139,16 +152,9 @@ def deploy_app(
pytest.skip("`DEPLOY_APPS` does not equal `true`")

run_on_ci = os.environ.get("CI", "False") == "true"
repo = os.environ.get("GITHUB_REPOSITORY", "unknown")
branch_name = os.environ.get("GITHUB_HEAD_REF", "unknown")

if (
not run_on_ci
or repo != "posit-dev/py-shiny"
or not (branch_name.startswith("deploy") or branch_name == "main")
):

if not run_on_ci:
pytest.skip("Not on CI or posit-dev/py-shiny repo or deploy* or main branch")
raise RuntimeError()

app_dir = os.path.dirname(app_file_path)
write_requirements_txt(app_dir)
Expand All @@ -159,6 +165,10 @@ def deploy_app(
}[location]

url = deployment_function(app_name, app_dir)
rsconnect_dir = os.path.join(
app_dir, "rsconnect-python", f"{os.path.basename(app_dir)}.json"
)
assert_rsconnect_file_updated(rsconnect_dir, 10)
return url


Expand Down