This commit is contained in:
134
README.md
134
README.md
@@ -1,94 +1,100 @@
|
||||
Drone CI Pipeline Configuration
|
||||
## 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:
|
||||
## Pipeline Overview
|
||||
|
||||
Steps
|
||||
Check PHP Syntax
|
||||
Verifies the syntax of all .php files in the repository using PHP's built-in linter.
|
||||
The `.drone.yml` file defines a multi-step pipeline that performs the following actions:
|
||||
|
||||
Check HTML Syntax
|
||||
Uses the tidy tool to validate the syntax of all .html files in the repository.
|
||||
### Steps
|
||||
|
||||
Run Tests for React Client
|
||||
Executes unit tests for the React client application if a package.json file exists in the services/client directory.
|
||||
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`.
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
A PostgreSQL container named `gamedb` is set up to provide a testing database for the Python backend.
|
||||
|
||||
Key Features
|
||||
PHP Syntax Check:
|
||||
Scans all .php files and ensures there are no syntax errors.
|
||||
## How It Works
|
||||
|
||||
HTML Syntax Check:
|
||||
Installs and uses the tidy tool to validate .html files.
|
||||
### Pipeline Configuration
|
||||
|
||||
React Client Tests:
|
||||
Runs tests using yarn if a package.json file is present in the services/client directory.
|
||||
The pipeline is defined in the `.drone.yml` file. Each step uses a Docker container to provide the required environment and tools.
|
||||
|
||||
Python Backend Tests:
|
||||
Runs pytest after installing dependencies and recreating the database.
|
||||
### 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
|
||||
|
||||
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.
|
||||
* `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.
|
||||
|
||||
Docker
|
||||
The pipeline steps and services run in Docker containers, so Docker must be available on the Drone runner.
|
||||
## 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
|
||||
|
||||
Usage
|
||||
Local Testing
|
||||
Before pushing changes to the repository, you can manually test each component:
|
||||
|
||||
PHP Syntax:
|
||||
1. **PHP Syntax:**
|
||||
|
||||
bash
|
||||
Zkopírovat kód
|
||||
```bash
|
||||
find . -type f -name '*.php' -exec php -l {} \;
|
||||
HTML Syntax:
|
||||
```
|
||||
|
||||
2. **HTML Syntax:**
|
||||
|
||||
Install tidy and run:
|
||||
|
||||
bash
|
||||
Zkopírovat kód
|
||||
```bash
|
||||
find . -type f -name '*.html' -exec tidy -q -e {} \;
|
||||
React Client Tests:
|
||||
```
|
||||
|
||||
3. **React Client Tests:**
|
||||
|
||||
Navigate to services/client and run:
|
||||
|
||||
bash
|
||||
Zkopírovat kód
|
||||
```bash
|
||||
yarn install
|
||||
CI=true yarn test --coverage
|
||||
Python Backend Tests:
|
||||
```
|
||||
|
||||
4. **Python Backend Tests:**
|
||||
|
||||
Navigate to services/game and run:
|
||||
|
||||
bash
|
||||
Zkopírovat kód
|
||||
```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
|
||||
```
|
||||
|
||||
### 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:
|
||||
|
||||
bash
|
||||
Zkopírovat kód
|
||||
```
|
||||
.
|
||||
├── services/
|
||||
│ ├── client/ # React client code
|
||||
@@ -101,14 +107,12 @@ Zkopírovat kód
|
||||
│ └── ...
|
||||
├── .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.
|
||||
## Troubleshooting
|
||||
|
||||
Database Connection Errors:
|
||||
Ensure the gamedb service is running and accessible by the Python backend.
|
||||
### 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.
|
||||
|
||||
Reference in New Issue
Block a user