GitLab CI/CD integration for automating feedback from Code PushUp
π€ Integrate Code PushUp into your GitLab CI/CD pipelines.
- π Collects a Code PushUp report on push to remote branch.
- π Uploads reports to job artifacts and/or Code PushUp portal (optional).
- π¬ When a MR is opened/updated, compares reports for source and target branches, and creates/updates a MR comment which summarizes the impact of the changes.
- π’ Supports monorepo setups - runs per project and summarizes comparisons in a single MR comment.
!Demo
Include the template in your .gitlab-ci.yml:
``yml
workflow:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
include:
- https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
`
This creates a code-pushup job, which runs the Code PushUp CLI using the config file from the repo.
Reports are then available as job artifacts.
If you integrate the Code PushUp portal, reports will be uploaded there as well.
Merge request pipelines will also trigger a comparison between reports from source and target branches, resulting in a Markdown comment being posted to the MR.
This requires access to the GitLab REST API, so a token must be configured using either of these environment variables:
- CP_GITLAB_TOKEN - for personal access tokens, group access tokens or project access tokensCP_GITLAB_OAUTH_TOKEN
- - for OAuth 2.0 tokens
You can define a CI/CD variable in project or group settings for this purpose, so that the token can be masked and hidden. Alternatively, you can set the environment variable using an external secrets management provider supported by GitLab.
By default, the code-pushup assumes a standalone npm project in root directory and runs using the Node LTS Docker image.@code-pushup/gitlab-ci
It installs all npm dependencies, before executing the underlying package.code-pushup.yml
(Refer to for the full job configuration.)
These defaults may not be the right fit for your repository. In which case you can override or add properties for the code-pushup job. For example:
- If you're using Yarn instead of npm:
`yml`
code-pushup:
before_script:
- yarn install --frozen-lockfile
- To set which stage the job runs in:
`yml`
code-pushup:
stage: report
- To use a custom Docker image (must have Node.js installed):
`yml`
code-pushup:
image: node:20
- If artifacts from a previous job are required:
`yml`
code-pushup:
needs:
- test
- To trigger job only on push to specific branches:
`yml`
code-pushup:
rules:
- if: $CI_COMMIT_BRANCH == "develop"
- if: $CI_COMMIT_BRANCH == "master"
- if: $CI_COMMIT_BRANCH =~ /^release/
Additionally, you can customize inputs when including the template. For example:
- To enable debug logs:
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
debug: true
- To run Code PushUp CLI via a package.json script (instead of the binary executable):
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
bin: npm run code-pushup --
- To run Code PushUp in a sub-folder:
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
directory: code-pushup
- To run Code PushUp in monorepo mode:
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
monorepo: true
Examples of customizing monorepo mode
- To skip auto-detection by specifying which tool you're using (options are nx, turbo, yarn, pnpm, npm):
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
monorepo: true
monorepo_tool: pnpm
- If your monorepo doesn't use any of the supported tools, you can specify a comma-separated list of folder paths instead (supports globs):
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
monorepo: true
monorepo_projects: frontend, backend/*
- If your projects' script/task/target is called something other than code-pushup:
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
monorepo: true
monorepo_task: analyze
- To run tasks in parallel for multiple projects at once:
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
monorepo: true
monorepo_parallel: true
- To customize the maximum number of parallel tasks:
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
monorepo: true
monorepo_parallel: true
monorepo_parallel_max: 3
- To optimize performance by providing configs upfront (see CI docs):
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
monorepo: true
config_patterns: |
{
"persist": {
"outputDir": ".code-pushup/{projectName}"
}
}
- To apply custom projects filter for nx show projects in Nx monorepo:
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
monorepo: nx
monorepo_nx_projects_filter: '--with-target=code-pushup --affected --projects=apps/ exclude=-e2e'
- To extend portal cache range when using --affected in Nx monorepo (see CI docs):
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
monorepo: nx
monorepo_nx_projects_filter: '--with-target=code-pushup --affected'
search_commits: true
search_commits_max: 30 # default is 10
- To disable MR comment:
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
skip_comment: true
- To compare reports for Git branches/tags other than MR source and target branches:
`yml`
include:
- remote: https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/latest/code-pushup.yml
inputs:
custom_source_ref: release/1.3.0
custom_target_ref: v1.2.3
The template is versioned using Git semver tags:
- the latest tagv1
- major tags (e.g. )v1.2
- minor tags (e.g. )v1.2.3
- full version tags (e.g. )
You can include any of these in the template URL. For example, if you're concerned about breaking changes, you can refer to a major version instead of latest:
`yml``
include:
- https://gitlab.com/code-pushup/gitlab-pipelines-template/-/raw/v1/code-pushup.yml