Skip to content
Merged
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
3 changes: 2 additions & 1 deletion scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 42 additions & 12 deletions tests/integration_tests/test_setup_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()