Contributing to GitLab and Lighthouse CI

While running Lighthouse CI on GitLab CI, I came across a problem: Lighthouse CI wants information about the current git commit, but it couldn’t get all of that information. In that case, Lighthouse CI falls back to running the git command; however, in my docker images, I don’t have git installed nor did I want to do so. So, I set out to fix this shortcoming in both Lighthouse and GitLab by adding the necessary environment variable to GitLab CI and having Lighthouse use it. The result is that I submitted a PR to Lighthouse that was merged and included in Lighthouse CI 0.7.1 and an MR to GitLab that was merged and included in GitLab 13.11. Now users (including my future self) will have a smooth, Just Works™ experience with these two tools.

Encountering the Issue

Lighthouse analyzes web apps and web pages, collecting modern performance metrics and insights on developer best practices.

https://github.com/GoogleChrome/lighthouse

The ideal way to run Lighthouse, or any test, is to do so as often as possible. Therefore, I prefer to run Lighthouse tests as part of Continuous Integration (CI) so every commit (and every merge request) gets evaluated by Lighthouse, allowing for quick identification of performance regressions.

To get Lighthouse reports as part of continuous integration, the Lighthouse projects offers Lighthouse CI:

Lighthouse CI is a suite of tools that make continuously running, saving, retrieving, and asserting against Lighthouse results as easy as possible.

https://github.com/GoogleChrome/lighthouse-ci

Lighthouse CI includes git commit information when it submits reports to the Lighthouse server. It can get commit information from the environment variables provided by many popular CI runners, including GitHub Actions, Jenkins, Travis CI, and GitLab CI. If it can’t get the information it needs from environment variables, it falls back to running the git command. If that doesn’t work, Lighthouse CI exits with a failure. Using environment variables means that git doesn’t have to be installed. That’s important because the best practice for docker images is to have them be as small as possible, meaning most, such as the commonly used node image, don’t have git installed.

When I first configured my project to run Lighthouse CI using GitLab CI, it failed due to not being able to run the git command: Lighthouse is not getting all of the information in needs from environment variables so it is falling back to git.

Submitting the Improvement to Lighthouse CI

Diving into the Lighthouse CI source code, I noticed that while Lighthouse CI did check for some GitLab CI environment variables, it didn’t check for them in all cases. As I started adding environment variables to check, I noticed a problem: GitLab CI has a number of CI_COMMIT_* environment variables, but it doesn’t have one that contains the commit’s author. Following the established convention, it would be named CI_COMMIT_AUTHOR. Therefore, I submitted a pull request to Lighthouse CI so it would check for all the necessary GitLab CI environment variables, including the one for author (which didn’t yet exist): https://github.com/GoogleChrome/lighthouse-ci/pull/568

Submitting the Improvement to GitLab

I found that a request in GitLab’s issue tracker for an environment variable containing the commit author. The issue was reported 4 months earlier; I could either wait and hope that someone else fulfills the request, or I could get to work and do it myself. I took the latter approach and got to work examining the GitLab code. The result was a merge request (MR): Add GIT_COMMIT_AUTHOR predefined variable.

Following my initial merge request submission, GitLab contributors (I believe at least some are GitLab employees) reviewed the MR and provided suggestions. Seeing as how GitLab is a large project written in a language unfamiliar to me (Ruby), I was very appreciative of those reviews. I added tests, improved the code, and eventually, the MR was approved and merged.

Skipping ahead a few weeks, GitLab 13.11 is released, and GitLab mentioned the newly added GIT_COMMIT_AUTHOR and prominently credited me for my contribution:

screenshot of GitLab 13.11 release notes

Closing Thoughts

  • The process from PR submission to released version including the improvement was less than 2 months for both projects.
  • Both projects were very welcoming and responsive.
  • In a fun surprise, I ran into my old colleague Paul Irish in the Lighthouse CI pull request. It’s nice to run into people; such chance encounters encourage me to continue contributing in hopes of more surprises occurring in the future.
  • I’m particularly appreciative to GitLab for so nicely mentioning me in their version 13.11 release notes.

CC BY-SA 4.0 Contributing to GitLab and Lighthouse CI by Craig Andrews is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.