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
1 change: 1 addition & 0 deletions docs/changes/323.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `--ci` flag to allow installing GOATS bypassing the user prompts for a CI pipeline.
9 changes: 9 additions & 0 deletions src/goats_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@
),
callback=validate_addrport,
)
@click.option(
"--ci", is_flag=True, help="Run install in non-interactive CI mode (no prompts)."
)
def install(
project_name: str,
directory: Path,
overwrite: bool,
media_dir: Path | None,
redis_addrport: str,
ci: bool,
) -> None:
"""Installs GOATS with a specified or default name in a specified or
default directory and configures Redis server.
Expand All @@ -101,6 +105,8 @@
The path to save media files.
redis_addrport : `str`
The host and port Redis is served on.
ci : `bool`
Run install in non-interactive CI mode (no prompts).

Raises
------
Expand Down Expand Up @@ -159,6 +165,9 @@
)
goats_setup_command.extend(["--media-dir", f"{resolved_media_dir}"])

if ci:
goats_setup_command.append("--ci")

Check warning on line 169 in src/goats_cli/cli.py

View check run for this annotation

Codecov / codecov/patch

src/goats_cli/cli.py#L169

Added line #L169 was not covered by tests

subprocess.run(goats_setup_command, check=True)

# Migrate the webpage.
Expand Down
46 changes: 40 additions & 6 deletions src/goats_setup/management/commands/goats_setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Django command to install GOATS."""

import os

Check warning on line 3 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L3

Added line #L3 was not covered by tests
import re
import sys
from pathlib import Path
Expand All @@ -14,7 +15,7 @@
from packaging import version
from tom_setup.management.commands.tom_setup import Command as TOMCommand

PYTHON_VERSION: str = "3.10"
PYTHON_VERSION: str = "3.12"

Check warning on line 18 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L18

Added line #L18 was not covered by tests
REDIS_HOST: str = "localhost"
REDIS_PORT: int = 6379
REDIS_ADDRPORT: str = f"{REDIS_HOST}:{REDIS_PORT}"
Expand All @@ -29,8 +30,12 @@

help = "🐐 GOATS setup wizard."

def welcome_banner(self) -> None:
def welcome_banner(self, ci: bool = False) -> None:

Check warning on line 33 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L33

Added line #L33 was not covered by tests
"""Displays a welcome banner."""
if ci:
self.stdout.write("🐐 Running GOATS for CI, skipping prompts.")
return

Check warning on line 37 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L36-L37

Added lines #L36 - L37 were not covered by tests

welcome_text = (
"🐐 Welcome to the GOATS setup wizard. This will assist you with your "
"new GOATS project.\n"
Expand Down Expand Up @@ -82,6 +87,13 @@
"Providing only a port number (e.g., '6379') binds to localhost."
),
)
# Argument to be used for CI.
parser.add_argument(

Check warning on line 91 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L91

Added line #L91 was not covered by tests
"--ci",
action="store_true",
default=False,
help="Run install in non-interactive CI mode (no prompts).",
)

def check_python(self) -> None:
"""Checks the Python version, exits if not compatible."""
Expand Down Expand Up @@ -137,10 +149,11 @@

def handle(self, *args, **options) -> None:
"""Handles the setup process."""
ci = options.get("ci", False)

Check warning on line 152 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L152

Added line #L152 was not covered by tests
self.context["CREATE_DATE"] = timezone.now()
self.context["PROJECT_NAME"] = settings.BASE_DIR.name
self.context["HINTS_ENABLED"] = False
self.welcome_banner()
self.welcome_banner(ci=ci)

Check warning on line 156 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L156

Added line #L156 was not covered by tests
self.stdout.write(self.style.MIGRATE_HEADING("Initial setup:"))
self.check_python()
self.setup_redis(redis_addrport=options.get("redis_addrport"))
Expand All @@ -153,7 +166,7 @@
self.generate_file("urls")
self.generate_file("asgi")
self.run_migrations()
self.create_pi()
self.create_pi(ci=ci)

Check warning on line 169 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L169

Added line #L169 was not covered by tests
self.create_public_group()
self.complete()

Expand Down Expand Up @@ -214,14 +227,35 @@
"""Gets the target type for the project."""
self.context["TARGET_TYPE"] = "SIDEREAL"

def create_pi(self) -> None:
def create_pi(self, ci: bool = False) -> None:

Check warning on line 230 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L230

Added line #L230 was not covered by tests
"""Creates a Principal Investigator (PI) superuser."""
self.stdout.write(
self.style.MIGRATE_HEADING(
"Principal Investigator (PI) and public user creation:",
)
)
call_command("createsuperuser", verbosity=0)
if ci:
password = os.environ.get("DJANGO_SUPERUSER_PASSWORD")

Check warning on line 238 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L238

Added line #L238 was not covered by tests
if not password:
self.stdout.write(

Check warning on line 240 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L240

Added line #L240 was not covered by tests
self.style.WARNING(
"🐐 DJANGO_SUPERUSER_PASSWORD is not set; the superuser will "
"not be able to log in until a password is manually set."
)
)

call_command(

Check warning on line 247 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L247

Added line #L247 was not covered by tests
"createsuperuser",
verbosity=0,
username="goats",
email="goats@goats.com",
interactive=False,
)
else:
call_command(

Check warning on line 255 in src/goats_setup/management/commands/goats_setup.py

View check run for this annotation

Codecov / codecov/patch

src/goats_setup/management/commands/goats_setup.py#L255

Added line #L255 was not covered by tests
"createsuperuser",
verbosity=0,
)
self.status(" PI Superuser created... ")
self.ok()

Expand Down