.gitlab-ci.yml 8.15 KB
Newer Older
1
image: buildstream/testsuite-debian:9-5da27168-32c47d1c
2

3
cache:
4
  key: "$CI_JOB_NAME-"
5
  paths:
6
    - cache/
7

8
stages:
9
  - prepare
10
  - test
11
  - post
12

13 14 15
variables:
  PYTEST_ADDOPTS: "--color=yes"
  INTEGRATION_CACHE: "${CI_PROJECT_DIR}/cache/integration-cache"
16
  TEST_COMMAND: "tox -- --color=yes --integration"
17

18 19 20 21
#####################################################
#                  Prepare stage                    #
#####################################################

22 23
# Create a source distribution
#
24 25
source_dist:
  stage: prepare
26 27 28 29 30 31 32 33
  script:

  # Generate the source distribution tarball
  #
  - python3 setup.py sdist
  - tar -ztf dist/*
  - tarball=$(cd dist && echo $(ls *))

34 35 36 37 38
  # Verify that the source distribution tarball can be installed correctly
  #
  - pip3 install dist/*.tar.gz
  - bst --version

39 40 41 42 43 44 45 46 47 48 49 50 51 52
  # unpack tarball as `dist/buildstream` directory
  - |
    cat > dist/unpack.sh << EOF
    #!/bin/sh
    tar -zxf ${tarball}
    mv ${tarball%.tar.gz} buildstream
    EOF

  # Make our helpers executable
  - chmod +x dist/unpack.sh
  artifacts:
    paths:
    - dist/

53

54 55 56 57
#####################################################
#                    Test stage                     #
#####################################################

58 59
# Run premerge commits
#
60
.tests-template: &tests
61
  stage: test
62

63 64 65 66
  variables:
    COVERAGE_DIR: coverage-linux

  before_script:
67 68 69 70
  # Diagnostics
  - mount
  - df -h

71 72 73 74
  script:
  - useradd -Um buildstream
  - chown -R buildstream:buildstream .

75 76
  # Run the tests from the source distribution, We run as a simple
  # user to test for permission issues
77
  - su buildstream -c "${TEST_COMMAND}"
78

79 80 81
  after_script:
  # Collect our reports
  - mkdir -p ${COVERAGE_DIR}
82
  - cp .coverage ${COVERAGE_DIR}/coverage."${CI_JOB_NAME}"
83 84
  except:
  - schedules
85 86
  artifacts:
    paths:
87
    - ${COVERAGE_DIR}
88

89
tests-debian-9:
90
  image: buildstream/testsuite-debian:9-5da27168-32c47d1c
91
  <<: *tests
92

93
tests-fedora-27:
94
  image: buildstream/testsuite-fedora:27-5da27168-32c47d1c
95
  <<: *tests
96

97
tests-fedora-28:
98
  image: buildstream/testsuite-fedora:28-5da27168-32c47d1c
99
  <<: *tests
100

101
tests-ubuntu-18.04:
102
  image: buildstream/testsuite-ubuntu:18.04-5da27168-32c47d1c
103
  <<: *tests
Valentin David's avatar
Valentin David committed
104

105
overnight-fedora-28-aarch64:
106
  image: buildstream/testsuite-fedora:aarch64-28-06bab030-32a101f6
Valentin David's avatar
Valentin David committed
107 108
  tags:
    - aarch64
109 110 111 112
  <<: *tests
  # We need to override the exclusion from the template
  # in order to run on schedules
  except: []
113 114
  only:
  - schedules
115

116
tests-unix:
117 118
  # Use fedora here, to a) run a test on fedora and b) ensure that we
  # can get rid of ostree - this is not possible with debian-8
119
  image: buildstream/testsuite-fedora:27-5da27168-32c47d1c
120
  <<: *tests
121 122
  variables:
    BST_FORCE_BACKEND: "unix"
123
    COVERAGE_DIR: coverage-unix
124

125
  script:
126

127
    # We remove the Bubblewrap and OSTree packages here so that we catch any
128 129 130
    # codepaths that try to use them. Removing OSTree causes fuse-libs to
    # disappear unless we mark it as user-installed.
    - dnf mark install fuse-libs
131
    - dnf erase -y bubblewrap ostree
132 133

    # Since the unix platform is required to run as root, no user change required
134
    - ${TEST_COMMAND}
135

136

137 138
tests-fedora-missing-deps:
  # Ensure that tests behave nicely while missing bwrap and ostree
139
  image: buildstream/testsuite-fedora:28-5da27168-32c47d1c
140 141 142 143 144 145 146 147 148 149 150 151
  <<: *tests

  script:
    # We remove the Bubblewrap and OSTree packages here so that we catch any
    # codepaths that try to use them. Removing OSTree causes fuse-libs to
    # disappear unless we mark it as user-installed.
    - dnf mark install fuse-libs
    - dnf erase -y bubblewrap ostree

    - useradd -Um buildstream
    - chown -R buildstream:buildstream .

152
    - ${TEST_COMMAND}
153 154


155 156
# Automatically build documentation for every commit, we want to know
# if building documentation fails even if we're not deploying it.
157 158
# Note: We still do not enforce a consistent installation of python3-sphinx,
#       as it will significantly grow the backing image.
159 160 161
docs:
  stage: test
  script:
162
  - export BST_SOURCE_CACHE="$(pwd)/cache/integration-cache/sources"
163 164
  # Currently sphinx_rtd_theme does not support Sphinx >1.8, this breaks search functionality
  - pip3 install sphinx==1.7.9
165
  - pip3 install sphinx-click
166
  - pip3 install sphinx_rtd_theme
167
  - cd dist && ./unpack.sh && cd buildstream
168
  - make BST_FORCE_SESSION_REBUILD=1 -C doc
169 170
  - cd ../..
  - mv dist/buildstream/doc/build/html public
171 172
  except:
  - schedules
173 174 175 176
  artifacts:
    paths:
    - public/

177 178 179
.overnight-tests: &overnight-tests-template
  stage: test
  variables:
Tiago Gomes's avatar
Tiago Gomes committed
180
    BST_EXT_URL: git+https://gitlab.com/BuildStream/bst-external.git
181 182
    BST_EXT_REF: 573843768f4d297f85dc3067465b3c7519a8dcc3 # 0.7.0
    FD_SDK_REF: 612f66e218445eee2b1a9d7dd27c9caba571612e # freedesktop-sdk-18.08.19-54-g612f66e2
183
  before_script:
184 185 186 187 188 189
  - |
    mkdir -p "${HOME}/.config"
    cat <<EOF >"${HOME}/.config/buildstream.conf"
    scheduler:
      fetchers: 2
    EOF
190
  - (cd dist && ./unpack.sh && cd buildstream && pip3 install .)
Tiago Gomes's avatar
Tiago Gomes committed
191
  - pip3 install --user -e ${BST_EXT_URL}@${BST_EXT_REF}#egg=bst_ext
192
  - git clone https://gitlab.com/freedesktop-sdk/freedesktop-sdk.git
Tiago Gomes's avatar
Tiago Gomes committed
193
  - git -C freedesktop-sdk checkout ${FD_SDK_REF}
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
  only:
  - schedules

overnight-tests:
  <<: *overnight-tests-template
  script:
  - make -C freedesktop-sdk
  tags:
  - overnight-tests

overnight-tests-no-cache:
  <<: *overnight-tests-template
  script:
  - sed -i '/artifacts:/,+1 d' freedesktop-sdk/bootstrap/project.conf
  - sed -i '/artifacts:/,+1 d' freedesktop-sdk/project.conf
  - make -C freedesktop-sdk
  tags:
  - overnight-tests
212

213
# Check code quality with gitlab's built-in feature.
214
#
215
code_quality:
216
  image: docker:stable
217
  stage: test
218 219 220 221 222 223 224 225 226 227 228 229
  variables:
    DOCKER_DRIVER: overlay2
  allow_failure: true
  services:
    - docker:stable-dind
  script:
    - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
    - docker run
        --env SOURCE_CODE="$PWD"
        --volume "$PWD":/code
        --volume /var/run/docker.sock:/var/run/docker.sock
        "registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
230 231
  except:
  - schedules
232
  artifacts:
233
    paths: [gl-code-quality-report.json]
234

235 236 237 238
#####################################################
#                    Post stage                     #
#####################################################

239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
analysis:
  stage: post
  script:
  - |
    pip3 install radon
    mkdir analysis

  - |
    echo "Calculating Maintainability Index"
    radon mi -s -j buildstream > analysis/mi.json
    radon mi -s buildstream

  - |
    echo "Calculating Cyclomatic Complexity"
    radon cc -a -s -j buildstream > analysis/cc.json
    radon cc -a -s buildstream

  - |
    echo "Calculating Raw Metrics"
    radon raw -s -j buildstream > analysis/raw.json
    radon raw -s buildstream

261 262
  except:
  - schedules
263 264 265 266
  artifacts:
    paths:
    - analysis/

267 268 269
# Collate coverage reports
#
coverage:
270
  stage: post
271
  coverage: '/TOTAL +\d+ +\d+ +(\d+\.\d+)%/'
272
  script:
273
    - cd dist && ./unpack.sh && cd buildstream
274
    - pip3 install -r tools/requirements.txt -r tools/dev-requirements.txt
275
    - pip3 install --no-index .
276 277
    - mkdir report
    - cd report
278
    - cp ../../../coverage-unix/coverage.* .
279
    - cp ../../../coverage-linux/coverage.* .
280
    - ls coverage.*
281
    - coverage combine --rcfile=../.coveragerc -a coverage.*
282
    - coverage report --rcfile=../.coveragerc -m
283
  dependencies:
284
  - tests-debian-9
285
  - tests-fedora-27
286
  - tests-fedora-28
287
  - tests-unix
288
  - source_dist
289 290
  except:
  - schedules
291

292
# Deploy, only for merges which land on master branch.
293
#
294
pages:
295 296 297 298
  stage: post
  dependencies:
  - source_dist
  - docs
Tiago Gomes's avatar
Tiago Gomes committed
299 300
  variables:
    ACME_DIR: public/.well-known/acme-challenge
301
  script:
302
  - mkdir -p ${ACME_DIR}
Tiago Gomes's avatar
Tiago Gomes committed
303 304 305 306
    # Required to finish the creation of the Let's Encrypt certificate,
    # which allows using https://docs.buildstream.build/ for accessing
    # the documentation.
  - echo ${ACME_CHALLENGE} > ${ACME_DIR}/$(echo ${ACME_CHALLENGE} | cut -c1-43)
307 308 309 310
  artifacts:
    paths:
    - public/
  only:
311 312 313 314 315 316 317 318 319
  #
  # FIXME:
  #
  # Ideally we want to publish to a different subdir of
  # pages depending on which stable branch we are building here,
  # not currently automatically supported but can be worked around.
  #
  # See https://gitlab.com/gitlab-org/gitlab-ce/issues/35141
  #
320
  - master
321 322
  except:
  - schedules