From b695b73651c26049c2475523d1c42f5994b5bea0 Mon Sep 17 00:00:00 2001 From: Ci Tester Date: Sat, 22 Aug 2026 10:36:32 -0500 Subject: [PATCH] Pull latest changes on redeploy instead of skipping setup.sh skipped git clone entirely whenever the project directory already existed, so a redeploy never fetched new commits pushed since the first deploy. Run git pull in that branch instead. --- scripts/setup.sh | 3 +- tests/integration_tests/test_setup_script.py | 54 +++++++++++++++----- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index 4fb21b6..14ad81e 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -18,7 +18,8 @@ echo "Cloning repository..." if [ ! -d "$REPO_NAME" ]; then git clone "$GIT_REPO_URL" "$REPO_NAME" else - echo "Directory $REPO_NAME already exists. Skipping clone." + echo "Directory $REPO_NAME already exists. Pulling latest changes..." + git -C "$REPO_NAME" pull fi # Create and activate a Python virtual environment, if it doesn't already exist diff --git a/tests/integration_tests/test_setup_script.py b/tests/integration_tests/test_setup_script.py index 585ddea..0ac64b4 100644 --- a/tests/integration_tests/test_setup_script.py +++ b/tests/integration_tests/test_setup_script.py @@ -7,18 +7,8 @@ import pytest -@pytest.fixture(scope="module") -def setup_script_result(tmp_path_factory) -> dict: - """Run setup.sh once and return the result along with paths for testing.""" - tmp_path = tmp_path_factory.mktemp("setup_script") - script_path = Path(__file__).parent.parent.parent / "scripts" / "setup.sh" - dir_name = "test_project" - django_project_name = "mysite" - # Use the current Python version available on CI for testing - python_version = f"python{sys.version_info.major}.{sys.version_info.minor}" - - # Create a minimal git repository with a requirements.txt file and Django project - source_repo = tmp_path / "source_repo" +def _create_source_repo(source_repo: Path, django_project_name: str) -> None: + """Create a minimal git repository with a requirements.txt file and Django project.""" source_repo.mkdir() (source_repo / "requirements.txt").write_text("django\n") @@ -59,6 +49,20 @@ def setup_script_result(tmp_path_factory) -> dict: check=True, capture_output=True, ) + + +@pytest.fixture(scope="module") +def setup_script_result(tmp_path_factory) -> dict: + """Run setup.sh once and return the result along with paths for testing.""" + tmp_path = tmp_path_factory.mktemp("setup_script") + script_path = Path(__file__).parent.parent.parent / "scripts" / "setup.sh" + dir_name = "test_project" + django_project_name = "mysite" + # Use the current Python version available on CI for testing + python_version = f"python{sys.version_info.major}.{sys.version_info.minor}" + + source_repo = tmp_path / "source_repo" + _create_source_repo(source_repo, django_project_name) repo_url = source_repo.as_uri() try: result = subprocess.run( @@ -128,3 +132,29 @@ def test_setup_script_runs_migrate(setup_script_result): assert "Running migrations and collectstatic..." in stdout # Check that migrations ran (either applied or no migrations to apply) assert "Operations to perform:" in stdout or "No migrations to apply" in stdout + + +def test_setup_script_redeploy_pulls_latest_changes(tmp_path): + """Running setup.sh again pulls new commits instead of skipping the existing clone.""" + script_path = Path(__file__).parent.parent.parent / "scripts" / "setup.sh" + dir_name = "test_project" + django_project_name = "mysite" + python_version = f"python{sys.version_info.major}.{sys.version_info.minor}" + + source_repo = tmp_path / "source_repo" + _create_source_repo(source_repo, django_project_name) + repo_url = source_repo.as_uri() + + args = ["bash", str(script_path), repo_url, dir_name, django_project_name, python_version] + subprocess.run(args, cwd=tmp_path, check=True, capture_output=True, text=True) + + # A new commit lands on the remote after the first deploy. + (source_repo / "REDEPLOY_MARKER.txt").write_text("second deploy") + subprocess.run(["git", "add", "."], cwd=source_repo, check=True, capture_output=True) + subprocess.run( + ["git", "commit", "-m", "Second commit"], cwd=source_repo, check=True, capture_output=True + ) + + subprocess.run(args, cwd=tmp_path, check=True, capture_output=True, text=True) + + assert (tmp_path / dir_name / "REDEPLOY_MARKER.txt").exists()