diff --git a/README.md b/README.md new file mode 100644 index 0000000..a0dd393 --- /dev/null +++ b/README.md @@ -0,0 +1,114 @@ +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 .php files in the repository using PHP's built-in linter. + +Check HTML Syntax +Uses the tidy tool to validate the syntax of all .html files in the repository. + +Run Tests for React Client +Executes unit tests for the React client application if a package.json file exists in the services/client directory. + +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: + +PHP Syntax: + +bash +Zkopírovat kód +find . -type f -name '*.php' -exec php -l {} \; +HTML Syntax: +Install tidy and run: + +bash +Zkopírovat kód +find . -type f -name '*.html' -exec tidy -q -e {} \; +React Client Tests: +Navigate to services/client and run: + +bash +Zkopírovat kód +yarn install +CI=true yarn test --coverage +Python Backend Tests: +Navigate to services/game and run: + +bash +Zkopírovat kód +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: + +bash +Zkopírovat kód +. +├── 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. +