Files
drone_example/README.md
Ondřej Hrachovina 5fae03501c
All checks were successful
continuous-integration/drone/push Build is passing
Update README.md
2024-11-28 17:07:06 +01:00

119 lines
3.8 KiB
Markdown

## 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
1. **Check PHP Syntax**:
Verifies the syntax of all `.php` files in the repository using PHP's built-in linter.
2. **Check HTML Syntax**:
Uses the `tidy` tool to validate the syntax of all `.html` files in the repository.
3. **Run Tests for React Client**:
Executes unit tests for the React client application if a `package.json` file exists in the `services/client` directory.
4. **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 `.php` files and ensures there are no syntax errors.
* **HTML Syntax Check:** Installs and uses the `tidy` tool to validate `.html` files.
* **React Client Tests:** Runs tests using `yarn` if a `package.json` file is present in the `services/client` directory.
* **Python Backend Tests:** Runs `pytest` after installing dependencies and recreating the database.
### Environment Variables
The pipeline uses the following environment variables for the Python backend tests:
* `FLASK_ENV`: Set to `production` to 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.yml` file.
* **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:
1. **PHP Syntax:**
```bash
find . -type f -name '*.php' -exec php -l {} \;
```
2. **HTML Syntax:**
Install tidy and run:
```bash
find . -type f -name '*.html' -exec tidy -q -e {} \;
```
3. **React Client Tests:**
Navigate to services/client and run:
```bash
yarn install
CI=true yarn test --coverage
```
4. **Python Backend Tests:**
Navigate to services/game and run:
```bash
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.