diff --git a/.env.example b/.env.example index 3d56c58538..540fe6af62 100644 --- a/.env.example +++ b/.env.example @@ -34,3 +34,6 @@ FMTM_DB_HOST=fmtm-db FMTM_DB_USER=fmtm FMTM_DB_PASSWORD=fmtm FMTM_DB_NAME=fmtm + +### Underpass (optional) ### +# UNDERPASS_API_URL= diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000000..1e3219854a --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,16 @@ +name: PR + +on: + pull_request: + branches: + - main + - staging + - development + # Allow manual trigger (workflow_dispatch) + workflow_dispatch: + +jobs: + pytest: + uses: ./.github/workflows/reusable/pytest.yml + frontend-tests: + uses: ./.github/workflows/reusable/frontend_tests.yml diff --git a/.github/workflows/pr_pytest.yml b/.github/workflows/pr_pytest.yml new file mode 100644 index 0000000000..7f1009b55f --- /dev/null +++ b/.github/workflows/pr_pytest.yml @@ -0,0 +1,24 @@ +name: PR + +on: + pull_request: + branches: + - main + - staging + - development + paths: + - src/backend/** + # Allow manual trigger (workflow_dispatch) + workflow_dispatch: + +jobs: + frontend-tests: + runs-on: ubuntu-latest + environment: + name: ${{ github.ref_name }} + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: PyTest + uses: ./.github/workflows/reusable/pytest.yml diff --git a/.github/workflows/frontend_test.yml b/.github/workflows/reusable/frontend_tests.yml similarity index 61% rename from .github/workflows/frontend_test.yml rename to .github/workflows/reusable/frontend_tests.yml index ed407a6ed5..56dd3dab30 100644 --- a/.github/workflows/frontend_test.yml +++ b/.github/workflows/reusable/frontend_tests.yml @@ -1,11 +1,9 @@ name: Frontend Tests on: - push: + workflow_call: paths: - - "src/frontend/**" # Trigger the workflow only when files within srv/frontend change - - ".github/workflows/**" # Also trigger if github workflow changes - workflow_dispatch: + - src/frontend/** jobs: test: @@ -13,8 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v2 diff --git a/.github/workflows/pytest.yml b/.github/workflows/reusable/pytest.yml similarity index 88% rename from .github/workflows/pytest.yml rename to .github/workflows/reusable/pytest.yml index ed2aa6e829..136aef25cf 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/reusable/pytest.yml @@ -1,18 +1,9 @@ name: pytest on: - # Run tests on all pushed branches - push: - branches: - - "*" - # Run tests on PR, prior to merge to main & development. - pull_request: - branches: - - main - - staging - - development - # Allow manual trigger (workflow_dispatch) - workflow_dispatch: + workflow_call: + paths: + - src/backend/** permissions: contents: read diff --git a/src/backend/app/config.py b/src/backend/app/config.py index 56daa0f82a..daa77dc272 100644 --- a/src/backend/app/config.py +++ b/src/backend/app/config.py @@ -110,6 +110,7 @@ def assemble_db_connection(cls, v: Optional[str], info: FieldValidationInfo) -> OSM_SCOPE: str = "read_prefs" OSM_LOGIN_REDIRECT_URI: str = "http://127.0.0.1:8080/osmauth/" + UNDERPASS_API_URL: str = "https://raw-data-api0.hotosm.org/v1" SENTRY_DSN: Optional[str] = None model_config = SettingsConfigDict( diff --git a/src/backend/app/projects/project_crud.py b/src/backend/app/projects/project_crud.py index 3aa7a0db13..adc69cdc9b 100644 --- a/src/backend/app/projects/project_crud.py +++ b/src/backend/app/projects/project_crud.py @@ -581,7 +581,7 @@ def get_osm_extracts(boundary: str): else: query["geometry"] = json_boundary - base_url = "https://raw-data-api0.hotosm.org/v1" + base_url = settings.UNDERPASS_API_URL query_url = f"{base_url}/snapshot/" headers = {"accept": "application/json", "Content-Type": "application/json"} @@ -1394,7 +1394,7 @@ def generate_appuser_files( project_log.info(f"Extracting Data from OSM") # OSM Extracts for whole project - pg = PostgresClient("https://raw-data-api0.hotosm.org/v1", "underpass") + pg = PostgresClient(settings.UNDERPASS_API_URL, "underpass") # This file will store osm extracts outfile = f"/tmp/{prefix}_{xform_title}.geojson" @@ -2019,7 +2019,7 @@ async def update_project_form( db.commit() # OSM Extracts for whole project - pg = PostgresClient("https://raw-data-api0.hotosm.org/v1", "underpass") + pg = PostgresClient(settings.UNDERPASS_API_URL, "underpass") outfile = ( f"/tmp/{project_title}_{category}.geojson" # This file will store osm extracts ) diff --git a/src/backend/app/tasks/tasks_crud.py b/src/backend/app/tasks/tasks_crud.py index 21a9d48afb..5aaea42be7 100644 --- a/src/backend/app/tasks/tasks_crud.py +++ b/src/backend/app/tasks/tasks_crud.py @@ -40,6 +40,7 @@ from ..projects import project_crud from ..tasks import tasks_schemas from ..users import user_crud +from app.config import settings async def get_task_count_in_project(db: Session, project_id: int): @@ -330,7 +331,7 @@ async def update_task_files( task_polygons = f"/tmp/{project_name}_{category}_{task_id}.geojson" # Update data extracts in the odk central - pg = PostgresClient("https://raw-data-api0.hotosm.org/v1", "underpass") + pg = PostgresClient(settings.UNDERPASS_API_URL, "underpass") category = "buildings"