3.8 KiB
Drone CI Pipeline Configuration
This repository includes a CI pipeline configuration for Drone CI to automate testing and syntax validation for a project with PHP, HTML, React, and Python components.
Pipeline Overview
The .drone.yml file defines a multi-step pipeline that performs the following actions:
Steps
- Check PHP Syntax:
Verifies the syntax of all
.phpfiles in the repository using PHP's built-in linter. - Check HTML Syntax:
Uses the
tidytool to validate the syntax of all.htmlfiles in the repository. - Run Tests for React Client:
Executes unit tests for the React client application if a
package.jsonfile exists in theservices/clientdirectory. - Run Tests for Python Backend:
Installs dependencies, recreates the database, and runs unit tests for the Python backend application using
pytest.
Services - PostgreSQL Database Service
A PostgreSQL container named gamedb is set up to provide a testing database for the Python backend.
How It Works
Pipeline Configuration
The pipeline is defined in the .drone.yml file. Each step uses a Docker container to provide the required environment and tools.
Key Features
- PHP Syntax Check: Scans all
.phpfiles and ensures there are no syntax errors. - HTML Syntax Check: Installs and uses the
tidytool to validate.htmlfiles. - React Client Tests: Runs tests using
yarnif apackage.jsonfile is present in theservices/clientdirectory. - Python Backend Tests: Runs
pytestafter installing dependencies and recreating the database.
Environment Variables
The pipeline uses the following environment variables for the Python backend tests:
FLASK_ENV: Set toproductionto ensure tests run in the correct environment.APP_SETTINGS: Specifies the configuration class for the Flask app.DATABASE_TEST_URL: Connection string for the testing database.
Requirements
- Drone CI: The pipeline requires a Drone CI server to execute the
.drone.ymlfile. - Docker: The pipeline steps and services run in Docker containers, so Docker must be available on the Drone runner.
Usage
Local Testing
Before pushing changes to the repository, you can manually test each component:
- PHP Syntax:
find . -type f -name '*.php' -exec php -l {} \;
- HTML Syntax:
Install tidy and run:
find . -type f -name '*.html' -exec tidy -q -e {} \;
- React Client Tests:
Navigate to services/client and run:
yarn install
CI=true yarn test --coverage
- Python Backend Tests:
Navigate to services/game and run:
pip install -r requirements.txt
python manage.py recreate_db
pytest --cov=project --cov-report=term-missing
Running the Pipeline
Push your changes to the repository. The pipeline will execute automatically in Drone CI. Review the results in the Drone CI dashboard.
Directory Structure
Ensure the following structure for the pipeline to work:
.
├── services/
│ ├── client/ # React client code
│ │ ├── package.json
│ │ ├── src/
│ │ └── ...
│ └── game/ # Python backend code
│ ├── manage.py
│ ├── requirements.txt
│ └── ...
├── .drone.yml # Drone CI pipeline configuration
└── README.md # Project documentation
Troubleshooting
Common Issues
- Missing Directories: If the pipeline cannot find services/client or services/game, ensure your repository structure matches the expected layout.
- Missing Dependencies: Make sure all required dependencies are installed in package.json and requirements.txt.
- Database Connection Errors: Ensure the gamedb service is running and accessible by the Python backend.