|
1 |
| -# Continuous Integration and Deployment |
2 |
| - |
3 |
| -This GitHub Actions workflow automates testing, code quality checks, and deployment to platform.sh. |
4 |
| - |
5 |
| -## Trigger |
6 |
| - |
7 |
| -The CI workflow is triggered by: |
8 |
| - |
9 |
| -- Push events to the `main` branch. |
10 |
| -- Push events creating new tags. |
11 |
| -- Pull request events. |
12 |
| - |
13 |
| -## Concurrency Control |
14 |
| - |
15 |
| -The workflow ensures concurrency control, allowing only one workflow run per branch/tag. It cancels in-progress runs if a new run is triggered. |
16 |
| - |
17 |
| -## Jobs |
18 |
| - |
19 |
| -Each job checks out the repository code using [actions/checkout](https://github.com/actions/checkout) and performs caching with [actions/cache](https://github.com/actions/cache) to optimize subsequent runs. |
20 |
| - |
21 |
| -### 1. Drupal Code Quality (`drupal_codequality`) |
22 |
| - |
23 |
| -**Intent:** Ensure Drupal code quality. |
24 |
| - |
25 |
| -**Description:** Uses GrumPHP to perform code quality checks on the Drupal codebase, ensuring adherence to our predefined standards. We use [axelerant/drupal-quality-checker](https://github.com/axelerant/drupal-quality-checker) for local checks, so we apply the same configuration in CI to maintain consistency. |
26 |
| - |
27 |
| -### 2. Frontend Code Quality (`frontend_codequality`) |
28 |
| - |
29 |
| -**Intent:** Ensure frontend code quality. |
30 |
| - |
31 |
| -**Description:** This job runs linting checks on JavaScript and other frontend code to maintain code quality and consistency. |
32 |
| - |
33 |
| -### 3. Drupal Test (`drupal_test`) |
34 |
| - |
35 |
| -**Intent:** Run comprehensive tests on the Drupal site. |
36 |
| - |
37 |
| -**Description:** This job sets up the ddev environment in CI to replicate the local development environment. It performs the following tests: |
38 |
| -- **Unit Tests with DTT:** Ensures individual units of code work as expected. |
39 |
| -- **PHPStan Checks:** Static analysis to find errors in code without running it. |
40 |
| -- **Cypress Tests:** End-to-end testing to ensure functionalities work. Integrated with Percy for Visual Testing. |
41 |
| - |
42 |
| -**Note:** |
43 |
| -- We spin up ddev in CI to ensure a consistent environment with our local development setup. This is necessary because we need a site running for Cypress tests and Drupal test traits. |
44 |
| -- PHPStan checks are included in this job and not part of the `drupal_codequality` job because it requires all dependencies to be present. |
45 |
| - |
46 |
| -### 4. Deploy (`deploy`) |
47 |
| - |
48 |
| -**Intent:** Deploy code to platform.sh. |
49 |
| - |
50 |
| -**Description:** This job deploys code to platform.sh based on the branch (`main` for production, others for feature environments). It ensures that only code passing the `drupal_codequality` and `drupal_test` jobs is deployed. Dependabot PRs are excluded from deployment. |
51 |
| - |
52 |
| -## References |
53 |
| - |
54 |
| -- [Events that trigger workflows](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows) |
55 |
| -- [Caching dependencies](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows) |
56 |
| -- [Drupal Quality Checker](https://github.com/axelerant/drupal-quality-checker) |
57 |
| -- [Defining outputs for jobs](https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs) |
58 |
| -- [Storing workflow data as artifacts](https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts) |
59 |
| -- [Using Secrets in GitHub Actions](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) |
60 |
| -- [Example Workflows](https://github.com/actions/starter-workflows) |
| 1 | +# CI/CD Documentation |
| 2 | + |
| 3 | +This document outlines the Continuous Integration and Continuous Delivery (CI/CD) workflows implemented in this project. These workflows are designed to automate testing, code quality checks, and environment management, facilitating a robust and efficient development lifecycle. |
| 4 | + |
| 5 | +## Workflow Overview |
| 6 | + |
| 7 | +This project leverages GitHub Actions for CI/CD. Workflow definitions are located in the `.github/workflows` directory within the repository. Each workflow addresses a specific aspect of the software development lifecycle, from code quality assurance to environment cleanup. |
| 8 | + |
| 9 | +## Workflow Details |
| 10 | + |
| 11 | +### 1. Visual Regression Testing (VR) Workflow |
| 12 | + |
| 13 | +* **File:** `.github/workflows/vr.yml` |
| 14 | +* **Purpose:** Executes visual regression tests to detect unintended visual changes in the application. This helps ensure a consistent user interface across deployments. |
| 15 | +* **Triggers:** |
| 16 | + * `push` events on tags (`*`): Triggers when a new tag is pushed to the repository, typically indicating a release. |
| 17 | + * `workflow_dispatch`: Allows manual triggering of the workflow from the GitHub Actions UI. This is useful for on-demand testing. |
| 18 | + * `schedule` (cron: `0 0 * * MON`): Runs the workflow every Monday at midnight (UTC). This provides regular visual regression testing. |
| 19 | +* **Concurrency:** Prevents concurrent VR test runs using `vr-${{ github.ref }}`. This ensures that tests are executed in isolation and avoids potential conflicts. |
| 20 | +* **Job:** `vr_test` |
| 21 | + * **Runs On:** `ubuntu-latest` (latest version of Ubuntu runner). |
| 22 | + * **Environment Variables:** Configures environment variables required for the test execution. |
| 23 | + * `CYPRESS_ADMIN_USERNAME`: Username for the administrative user in the Cypress testing environment. |
| 24 | + * `CYPRESS_ADMIN_PASSWORD`: Password for the administrative user in the Cypress testing environment. |
| 25 | + * `PERCY_TOKEN`: API token for authenticating with the Percy visual regression testing platform. This is retrieved from GitHub secrets for security. |
| 26 | + * **Steps:** |
| 27 | + 1. **Checkout Code:** Checkouts the repository code using `actions/checkout@v4`, making the project code available to the workflow. |
| 28 | + 2. **Determine Cache Directories:** This step identifies cache directories for Composer and npm, optimizing dependency management for subsequent runs by storing and retrieving cached dependencies. |
| 29 | + |
| 30 | +### 2. Pull Request Close Workflow |
| 31 | + |
| 32 | +* **File:** `.github/workflows/pr-close.yml` |
| 33 | +* **Purpose:** Cleans up Platform.sh environments that were provisioned for pull request testing. This helps to minimize resource usage and avoid unnecessary costs. |
| 34 | +* **Triggers:** `pull_request` events with `types: [closed]`: Triggers when a pull request is closed (either merged or closed without merging). |
| 35 | +* **Job:** `on-pr-close` |
| 36 | + * **Runs On:** `ubuntu-latest` |
| 37 | + * **Steps:** |
| 38 | + 1. **Clean PR Environment:** Utilizes the `axelerant/platformsh-action@v1` action with the `clean-pr-env` parameter. This action automatically removes the Platform.sh environment associated with the closed pull request. The workflow requires the following parameters: |
| 39 | + * `project-id`: The Platform.sh project ID. Often configured within the repository settings or workflow file (refer to Axelerant's documentation for specifics) |
| 40 | + * `cli-token`: A Platform.sh CLI token with appropriate permissions. This token is securely stored as a GitHub secret (`secrets.PLATFORMSH_CLI_TOKEN`). |
| 41 | + |
| 42 | +### 3. Cypress Tests Workflow |
| 43 | + |
| 44 | +* **File:** `.github/workflows/cypress-tests.yml` |
| 45 | +* **Purpose:** Executes end-to-end (E2E) tests using Cypress. These tests simulate user interactions with the application, verifying its functionality and behavior. |
| 46 | +* **Triggers:** `schedule` (cron: `0 0 * * 0`): Runs the workflow every Sunday at midnight (UTC). This ensures that E2E tests are performed regularly. |
| 47 | +* **Job:** `cypress_tests` |
| 48 | + * **Runs On:** `ubuntu-latest` |
| 49 | + * **Environment Variables:** |
| 50 | + * `CYPRESS_ADMIN_USERNAME`: Username for the administrative user in the Cypress testing environment. |
| 51 | + * `CYPRESS_ADMIN_PASSWORD`: Password for the administrative user in the Cypress testing environment. |
| 52 | + * **Steps:** |
| 53 | + 1. **Checkout Code:** Checkouts the repository code. |
| 54 | + 2. **Setup DDEV:** Sets up DDEV (a local development environment tool) using the `ddev/github-action-setup-ddev@v1` action. |
| 55 | + 3. **Configure DDEV:** Configures DDEV to include the Platform.sh token using `ddev config global`. This allows DDEV to interact with Platform.sh during testing. |
| 56 | + 4. **Install Dependencies and Start DDEV:** Installs Composer dependencies using `ddev composer install` and starts the DDEV environment using `ddev`. |
| 57 | + |
| 58 | +### 4. Continuous Integration (CI) Workflow |
| 59 | + |
| 60 | +* **File:** `.github/workflows/ci.yml` |
| 61 | +* **Purpose:** Performs code quality checks to ensure that the codebase adheres to defined coding standards and best practices. |
| 62 | +* **Triggers:** |
| 63 | + * `push` events on the `main` branch and tags (`*`): Triggers when changes are pushed to the main branch or when a tag is created. |
| 64 | + * `pull_request`: Triggers when a pull request is opened, updated, or synchronized. |
| 65 | +* **Concurrency:** Prevents concurrent CI runs using `${{ github.ref }}`. |
| 66 | +* **Jobs:** |
| 67 | + * `drupal_codequality`: Performs Drupal-specific code quality checks. |
| 68 | + * **Uses:** `hussainweb/drupalqa-action@v2` (a GitHub Action designed for Drupal code quality). |
| 69 | + * **PHP Version:** Specifies PHP version 8.2 for the code analysis. |
| 70 | + * **GrumPHP Configuration:** Configures code quality checks using GrumPHP, including: |
| 71 | + * `phplint`: Checks for PHP syntax errors. |
| 72 | + * `yamllint`: Checks for YAML syntax errors and formatting issues. |
| 73 | + * `jsonlint`: Checks for JSON syntax errors and formatting issues. |
| 74 | + * `phpcs`: Checks for PHP coding standard violations using PHP_CodeSniffer. |
| 75 | + * `phpmd`: Performs static analysis of PHP code using PHP Mess Detector. |
| 76 | + * `twigcs`: Checks for coding standards violations in Twig templates. |
| 77 | + * `frontend_codequality`: Performs frontend code quality checks. |
| 78 | + * **Container:** Uses a `node:18` container to provide a Node.js environment for the checks. |
| 79 | + * **Steps:** |
| 80 | + 1. `npm install`: Installs Node.js dependencies. |
| 81 | + 2. Runs linting processes (details of specific linting tools and configurations should be found within the `package.json` file or related configuration files in the project repository, for example: ESLint, stylelint). |
| 82 | + |
| 83 | +## Secrets |
| 84 | + |
| 85 | +The workflows utilize GitHub secrets for storing sensitive information, enhancing security: |
| 86 | + |
| 87 | +* `PERCY_TOKEN`: API token for authenticating with the Percy visual regression testing platform. |
| 88 | +* `PLATFORMSH_CLI_TOKEN`: A Platform.sh CLI token used for interacting with the Platform.sh API. This secret should have the necessary permissions to manage environments. |
| 89 | + |
| 90 | +## Dependencies |
| 91 | + |
| 92 | +The CI/CD workflows rely on several key dependencies: |
| 93 | + |
| 94 | +* **GitHub Actions:** The underlying platform for workflow execution. |
| 95 | +* **Community Actions:** Reusable actions from the GitHub Marketplace that simplify common tasks (e.g., `actions/checkout@v4`, `axelerant/platformsh-action@v1`, `hussainweb/drupalqa-action@v2`, `ddev/github-action-setup-ddev@v1`). |
| 96 | +* **DDEV:** A local development environment tool used to configure and manage the testing environment within the CI workflows. |
| 97 | +* **Platform.sh:** A cloud hosting platform used for environment management, particularly for pull request environments. |
| 98 | +* **GrumPHP:** A PHP task runner used for automating code quality checks in Drupal projects. |
| 99 | +* **Node.js/npm:** A javascript runtime environment and package manager, both of which are used for Frontend Code Quality Checks. |
| 100 | +* **Composer:** A dependency manager for PHP used to managing project dependencies. |
| 101 | + |
| 102 | +## Interactions |
| 103 | + |
| 104 | +The workflows interact with the following services and tools: |
| 105 | + |
| 106 | +* **GitHub:** Provides source code management, workflow execution, and secure secret storage. |
| 107 | +* **Platform.sh:** Provides cloud hosting and environment management. |
| 108 | +* **Percy:** A visual regression testing platform. |
| 109 | +* **DDEV:** A local development environment platform. |
0 commit comments