Add reset job after integration tests on feature branches
This commit is contained in:
@@ -213,6 +213,61 @@ integration_test_feature:
|
||||
- if: '$CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != "main"'
|
||||
when: on_success
|
||||
|
||||
# Reset feature environment after integration tests
|
||||
# Calls factory-reset to clean up test data created during integration tests
|
||||
reset_feature:
|
||||
stage: deploy
|
||||
needs: [integration_test_feature]
|
||||
image: deps.global.bsf.tools/docker/python:3.12-slim
|
||||
timeout: 5m
|
||||
before_script:
|
||||
- pip install --index-url "$PIP_INDEX_URL" httpx
|
||||
script:
|
||||
- |
|
||||
python - <<'RESET_SCRIPT'
|
||||
import httpx
|
||||
import os
|
||||
import sys
|
||||
|
||||
BASE_URL = f"https://orchard-{os.environ['CI_COMMIT_REF_SLUG']}.common.global.bsf.tools"
|
||||
PASSWORD = os.environ.get("DEV_ADMIN_PASSWORD")
|
||||
|
||||
if not PASSWORD:
|
||||
print("ERROR: DEV_ADMIN_PASSWORD not set")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"Resetting environment at {BASE_URL}")
|
||||
client = httpx.Client(base_url=BASE_URL, timeout=60.0)
|
||||
|
||||
# Login as admin
|
||||
login_resp = client.post("/api/v1/auth/login", json={
|
||||
"username": "admin",
|
||||
"password": PASSWORD
|
||||
})
|
||||
if login_resp.status_code != 200:
|
||||
print(f"ERROR: Login failed: {login_resp.status_code}")
|
||||
sys.exit(1)
|
||||
|
||||
# Call factory reset
|
||||
reset_resp = client.post(
|
||||
"/api/v1/admin/factory-reset",
|
||||
headers={"X-Confirm-Reset": "yes-delete-all-data"}
|
||||
)
|
||||
if reset_resp.status_code == 200:
|
||||
print("SUCCESS: Factory reset completed")
|
||||
print(reset_resp.json())
|
||||
else:
|
||||
print(f"ERROR: Factory reset failed: {reset_resp.status_code}")
|
||||
print(reset_resp.text)
|
||||
sys.exit(1)
|
||||
RESET_SCRIPT
|
||||
variables:
|
||||
DEV_ADMIN_PASSWORD: $DEV_ADMIN_PASSWORD
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != "main"'
|
||||
when: on_success
|
||||
allow_failure: true # Don't fail the pipeline if reset fails
|
||||
|
||||
# Run Python backend unit tests
|
||||
python_unit_tests:
|
||||
stage: test
|
||||
|
||||
Reference in New Issue
Block a user