aaredb/.gitlab-ci.yml
GotthardG 81c28b983d Refactor OpenAPI fetcher for improved clarity and robustness
Reorganized and enhanced the OpenAPI fetch logic for better maintainability and error handling. Key updates include improved environment variable validation, more detailed error messages, streamlined configuration loading, and additional safety checks for file paths and directories. Added proper logging and ensured the process flow is easy to trace.
2024-12-18 15:28:08 +01:00

70 lines
2.2 KiB
YAML

# GitLab CI/CD Configuration for FastAPI
stages:
- test
- deploy
- release
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.pip_cache"
VIRTUAL_ENV: ".venv"
# Cache for dependencies
cache:
paths:
- .pip_cache/
before_script: # common setup for every job
- python3.12 -m venv $VIRTUAL_ENV
- source $VIRTUAL_ENV/bin/activate
- pip install --upgrade pip
test:
stage: test
script:
- source $VIRTUAL_ENV/bin/activate
- pip install -r requirements.txt
- export PYTHONPATH=$PYTHONPATH:/home/gitlab-runner/builds/t3_38ooWt/0/mx/heidi-v2/backend
- cd /home/gitlab-runner/builds/t3_38ooWt/0/mx/heidi-v2 # Change to the project root
- pytest --cov=app --cov-report=xml # Run tests and generate coverage report
lint:
stage: test
script:
- source $VIRTUAL_ENV/bin/activate
- pip install pre-commit black flake8
- >
pre-commit run --all-files || {
echo "Pre-commit formatting failed. Auto-fixing formatting issues with black..." &&
black backend/ &&
exit 0;
}
deploy:
stage: deploy
variables:
CI: "true" # Mark this as a CI run
ENVIRONMENT: test # Use test environment settings
PORT: 8081
script:
- echo "Setting up Python dependencies..."
- source $VIRTUAL_ENV/bin/activate
- pip install -r requirements.txt
- echo "Starting the application to test startup with SSL..."
- cd $CI_PROJECT_DIR/backend # Use GitLab-provided dynamic root path
- python -m main # Run the main module dynamically
release:
stage: release
when: manual
variables:
TWINE_USERNAME: gitlab-ci-token # Keep username the same
TWINE_PASSWORD: $CI_JOB_TOKEN # Use PAT stored in GitLab CI/CD Variables
script:
- echo "Setting up Python dependencies..."
- source $VIRTUAL_ENV/bin/activate
- pip install -r requirements.txt
- rm -f openapi.json || true
- rm -rf python-client || true
- bash make_openapi_client.sh # Generate OpenAPI client and package
- ls backend/python-client/dist/ # Debug artifacts to ensure files exist
- twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi backend/python-client/dist/*