DrupalEasy: Test-driving GitLab CI templates for Drupal-contributed Module

Post Category :

In the ever-evolving landscape of web development, staying ahead in the game requires continuous integration (CI) processes that are not only robust but also efficient. A recent revolution in this direction is the introduction of GitLab CI templates for Drupal contributed modules.

This comprehensive system, spearheaded by the Drupal Association (DA) and community contributors, aims to streamline and enhance the automated testing process for module maintainers. Let’s explore the ins and outs of this groundbreaking project, providing a comprehensive guide for module maintainers to seamlessly integrate GitLab CI into their workflow.

Background and Motivation

The primary objective behind this initiative was to replace the existing Drupal CI with GitLab’s CI tools. This move aimed to streamline the process of running automated tests for both Drupal core and contributed projects, ultimately saving valuable community and DA resources in the long run.

For contributed module maintainers, this transition translates into the ability to specify more flexible tests and code validations tailored to each module’s unique requirements. The introduction of GitLab templates simplifies this process, offering a solid foundation for maintainers to build upon.

Understanding GitLab CI

Traditionally, Drupal maintained a custom CI platform called Drupal CI. While functional, it lacked flexibility and scalability, creating limitations for diverse module testing needs. The arrival of GitLab CI templates marks a significant shift, leveraging GitLab’s robust CI/CD capabilities to empower module maintainers with greater control and customization.

At its core, GitLab CI ensures that for every commit to a contributed module project, a predefined process, or “job,” runs various checks on the code. These checks include essential steps like validating the project’s composer.json file, conducting coding standard checks via phpcs, and executing static code analysis checks through PhpStan.

Additionally, testing steps are integrated, running the module’s PhpUnit tests in various Drupal environments, encompassing different versions of Drupal core and PHP. These checks are categorized into three stages within GitLab CI:

  1. Build: Building the template using GitLab CI
  2. Validate: Verifying the integrity of the composer.json file, ensuring adherence to coding standards via phpcs, and performing static code analysis with PhpStan.
  3. Test: Running PHPUnit tests across various Drupal core and PHP versions.

Upon completion of these stages, GitLab CI displays comprehensive results, providing valuable insights into the health of the project.

Taking Control of the Process

One of the most exciting aspects of GitLab CI templates is their ease of use. The DA and community contributors have thoughtfully crafted a set of templates, readily available within the GitLab interface for contributed modules.

Module maintainers simply need to create a file named .gitlab-ci.yml and select the appropriate template from the dropdown menu. The DA and community contributors have created a set of templates to get you started with a basic pipeline.

This simplicity paves the way for broader adoption and empowers maintainers to quickly leverage the benefits of automated testing.

Going Beyond the Basics: Customization and Expansion

But the journey doesn’t stop with the basic template. GitLab CI offers extensive customization options, catering to even the most intricate testing needs. Variables within the templates allow maintainers to:

  • Skip specific jobs: Don’t need PhpStan validation? Simply add SKIP_PHPSTAN: 1 to your .gitlab-ci.yml file.
  • Opt-in to additional jobs: Want to test against past Drupal versions or different PHP releases? Use variables like OPT_IN_TEST_PREVIOUS_MAJOR or OPT_IN_TEST_MAX_PHP to expand your testing scope.
  • Fine-tune logging and visibility: Control the amount of log output with _PHPUNIT_EXTRA and even publicly display environment variables for transparency with _SHOW_ENVIRONMENT_VARIABLES.
This empowers module maintainers to craft highly personalized pipelines that cater to their specific testing requirements.

Building the Future of CI

The power of GitLab CI extends beyond pre-defined templates. Advanced users can tap into the full potential of .gitlab-ci.yml syntax, implementing intricate CI processes that go beyond automated testing.

Recent examples showcase the potential for integrating Yarn, generating GitLab pages to document modules, and much more. This level of flexibility grants unparalleled control and innovation to module maintainers.

What's the downside?

While GitLab CI offers immense benefits, it’s crucial to acknowledge potential challenges:

Adoption hurdles

Encouraging widespread adoption among module maintainers accustomed to Drupal CI requires dedicated effort and clear communication of the advantages.

Drupal CI has been the established way of doing things for years, and some maintainers may be hesitant to switch to a new system. The DA and community contributors will need to provide compelling reasons for module maintainers to make the change, such as highlighting the increased flexibility and efficiency of GitLab CI.

Cost considerations

Running GitLab CI pipelines incurs costs. While significant efficiency improvements are underway, the DA will likely need to provide guidance on responsible resource utilization for maintainers.

The DA is currently covering the cost of running GitLab CI pipelines for Drupal contributed modules. However, as the number of modules using GitLab CI increases, the costs will also rise. The DA will need to find a way to balance the need for affordability with the need to provide a robust CI platform.

Is GitLab CI a finished product?

The development of GitLab CI templates is an ongoing process. It is fueled by the commitment of the DA and community contributors. Regular meetings and active engagement in the Drupal Slack workspace ensure collaborative progress. Module maintainers are encouraged to participate in issue discussions, contribute patches, and actively shape the future of this powerful system.

Conclusion

GitLab CI templates mark a significant leap forward for Drupal module development. By democratizing access to powerful automated testing and code validation tools, this system empowers module maintainers to deliver higher-quality code with greater confidence. As the community continues to refine and expand this offering, GitLab CI has the potential to revolutionize the Drupal contributed module ecosystem, fostering a culture of collaboration, innovation, and excellence.

In this transformative landscape, VE3 emerges as your valuable ally. With our suite of solutions, we complement GitLab CI by providing specialized support in optimizing CI/CD pipelines, ensuring seamless integration with Drupal development workflows. Our robust testing infrastructure and performance monitoring capabilities enhance the efficiency of GitLab CI, enabling developers to identify and address issues swiftly. Together, we can create a powerful synergy that not only streamlines the web development process but also sets the stage for a new era of Drupal module development marked by efficiency, reliability, and continuous improvement. To know more, explore our innovative digital solutions or contact us directly.

EVER EVOLVING | GAME CHANGING | DRIVING GROWTH

VE3