Update README.md
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-11-28 17:07:06 +01:00
parent bc62f8bb1c
commit 5fae03501c

134
README.md
View File

@@ -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. 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 ## Pipeline Overview
The .drone.yml file defines a multi-step pipeline that performs the following actions:
Steps The `.drone.yml` file defines a multi-step pipeline that performs the following actions:
Check PHP Syntax
Verifies the syntax of all .php files in the repository using PHP's built-in linter.
Check HTML Syntax ### Steps
Uses the tidy tool to validate the syntax of all .html files in the repository.
Run Tests for React Client 1. **Check PHP Syntax**:
Executes unit tests for the React client application if a package.json file exists in the services/client directory. 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 ### Services - PostgreSQL Database Service
Installs dependencies, recreates the database, and runs unit tests for the Python backend application using pytest.
Services A PostgreSQL container named `gamedb` is set up to provide a testing database for the Python backend.
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 ## How It Works
PHP Syntax Check:
Scans all .php files and ensures there are no syntax errors.
HTML Syntax Check: ### Pipeline Configuration
Installs and uses the tidy tool to validate .html files.
React Client Tests: The pipeline is defined in the `.drone.yml` file. Each step uses a Docker container to provide the required environment and tools.
Runs tests using yarn if a package.json file is present in the services/client directory.
Python Backend Tests: ### Key Features
Runs pytest after installing dependencies and recreating the database.
* **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: 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. * `FLASK_ENV`: Set to `production` to ensure tests run in the correct environment.
APP_SETTINGS: Specifies the configuration class for the Flask app. * `APP_SETTINGS`: Specifies the configuration class for the Flask app.
DATABASE_TEST_URL: Connection string for the testing database. * `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 ## Requirements
The pipeline steps and services run in Docker containers, so Docker must be available on the Drone runner.
* **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: Before pushing changes to the repository, you can manually test each component:
PHP Syntax: 1. **PHP Syntax:**
bash ```bash
Zkopírovat kód
find . -type f -name '*.php' -exec php -l {} \; find . -type f -name '*.php' -exec php -l {} \;
HTML Syntax: ```
2. **HTML Syntax:**
Install tidy and run: Install tidy and run:
bash ```bash
Zkopírovat kód
find . -type f -name '*.html' -exec tidy -q -e {} \; find . -type f -name '*.html' -exec tidy -q -e {} \;
React Client Tests: ```
3. **React Client Tests:**
Navigate to services/client and run: Navigate to services/client and run:
bash ```bash
Zkopírovat kód
yarn install yarn install
CI=true yarn test --coverage CI=true yarn test --coverage
Python Backend Tests: ```
4. **Python Backend Tests:**
Navigate to services/game and run: Navigate to services/game and run:
bash ```bash
Zkopírovat kód
pip install -r requirements.txt pip install -r requirements.txt
python manage.py recreate_db python manage.py recreate_db
pytest --cov=project --cov-report=term-missing pytest --cov=project --cov-report=term-missing
Running the Pipeline ```
Push your changes to the repository.
The pipeline will execute automatically in Drone CI. ### Running the Pipeline
Review the results in the Drone CI dashboard.
Directory Structure 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: Ensure the following structure for the pipeline to work:
bash ```
Zkopírovat kód
. .
├── services/ ├── services/
│ ├── client/ # React client code │ ├── client/ # React client code
@@ -101,14 +107,12 @@ Zkopírovat kód
│ └── ... │ └── ...
├── .drone.yml # Drone CI pipeline configuration ├── .drone.yml # Drone CI pipeline configuration
└── README.md # Project documentation └── 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: ## Troubleshooting
Make sure all required dependencies are installed in package.json and requirements.txt.
Database Connection Errors: ### Common Issues
Ensure the gamedb service is running and accessible by the Python backend.
* **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.