1# To contribute improvements to CI/CD templates, please follow the Development guide at:
2# https://docs.gitlab.com/ee/development/cicd/templates.html
3# This specific template is located at:
4# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Verify/Browser-Performance.latest.gitlab-ci.yml
5
6# Read more about the feature here: https://docs.gitlab.com/ee/user/project/merge_requests/browser_performance_testing.html
7
8stages:
9  - build
10  - test
11  - deploy
12  - performance
13
14browser_performance:
15  stage: performance
16  image: docker:git
17  variables:
18    URL: ''
19    SITESPEED_IMAGE: sitespeedio/sitespeed.io
20    SITESPEED_VERSION: 14.1.0
21    SITESPEED_OPTIONS: ''
22  services:
23    - docker:stable-dind
24  script:
25    - mkdir gitlab-exporter
26    # Busybox wget does not support proxied HTTPS, get the real thing.
27    # See https://gitlab.com/gitlab-org/gitlab/-/issues/287611.
28    - (env | grep -i _proxy= 2>&1 >/dev/null) && apk --no-cache add wget
29    - wget -O ./gitlab-exporter/index.js https://gitlab.com/gitlab-org/gl-performance/raw/1.1.0/index.js
30    - mkdir sitespeed-results
31    - |
32      function propagate_env_vars() {
33        CURRENT_ENV=$(printenv)
34
35        for VAR_NAME; do
36          echo $CURRENT_ENV | grep "${VAR_NAME}=" > /dev/null && echo "--env $VAR_NAME "
37        done
38      }
39    - |
40      docker run \
41        $(propagate_env_vars \
42          auto_proxy \
43          https_proxy \
44          http_proxy \
45          no_proxy \
46          AUTO_PROXY \
47          HTTPS_PROXY \
48          HTTP_PROXY \
49          NO_PROXY \
50        ) \
51        --shm-size=1g --rm -v "$(pwd)":/sitespeed.io $SITESPEED_IMAGE:$SITESPEED_VERSION --plugins.add ./gitlab-exporter --cpu --outputFolder sitespeed-results $URL $SITESPEED_OPTIONS
52    - mv sitespeed-results/data/performance.json browser-performance.json
53  artifacts:
54    paths:
55      - sitespeed-results/
56    reports:
57      browser_performance: browser-performance.json
58