.gitlab-ci.yml 8.21 KB
Newer Older
Tristan Maat's avatar
Tristan Maat committed
1
image: buildstream/testsuite-debian:9-master-119-552f5fc6
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: 'python3 setup.py test --index-url invalid://uri --addopts --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
  # Unpack
72 73 74
  - cd dist && ./unpack.sh
  - cd buildstream

75 76 77 78
  script:
  - useradd -Um buildstream
  - chown -R buildstream:buildstream .

79 80
  # Run the tests from the source distribution, We run as a simple
  # user to test for permission issues
81
  - su buildstream -c "${TEST_COMMAND}"
82

83 84 85 86 87 88
  after_script:
  # Collect our reports
  - mkdir -p ${COVERAGE_DIR}
  - cp dist/buildstream/.coverage ${COVERAGE_DIR}/coverage."${CI_JOB_NAME}"
  except:
  - schedules
89 90
  artifacts:
    paths:
91
    - ${COVERAGE_DIR}
92

93
tests-debian-9:
Valentin David's avatar
Valentin David committed
94
  image: buildstream/testsuite-debian:9-master-123-7ce6581b
95
  <<: *tests
96

97
tests-fedora-27:
Valentin David's avatar
Valentin David committed
98
  image: buildstream/testsuite-fedora:27-master-123-7ce6581b
99
  <<: *tests
100

101
tests-fedora-28:
Valentin David's avatar
Valentin David committed
102
  image: buildstream/testsuite-fedora:28-master-123-7ce6581b
103
  <<: *tests
104

105
tests-ubuntu-18.04:
Valentin David's avatar
Valentin David committed
106
  image: buildstream/testsuite-ubuntu:18.04-master-123-7ce6581b
107
  <<: *tests
Valentin David's avatar
Valentin David committed
108

109
overnight-fedora-28-aarch64:
Valentin David's avatar
Valentin David committed
110 111 112
  image: buildstream/testsuite-fedora:aarch64-28-master-123-7ce6581b
  tags:
    - aarch64
113 114 115 116
  <<: *tests
  # We need to override the exclusion from the template
  # in order to run on schedules
  except: []
117 118
  only:
  - schedules
119

120
tests-unix:
121 122
  # 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
Valentin David's avatar
Valentin David committed
123
  image: buildstream/testsuite-fedora:27-master-123-7ce6581b
124
  <<: *tests
125 126
  variables:
    BST_FORCE_BACKEND: "unix"
127
    COVERAGE_DIR: coverage-unix
128

129
  script:
130

131
    # We remove the Bubblewrap and OSTree packages here so that we catch any
132 133 134
    # 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
135
    - dnf erase -y bubblewrap ostree
136 137

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

140

141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
tests-fedora-missing-deps:
  # Ensure that tests behave nicely while missing bwrap and ostree
  image: buildstream/testsuite-fedora:28-master-119-552f5fc6
  <<: *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 .

156
    - ${TEST_COMMAND}
157 158


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

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

217
# Check code quality with gitlab's built-in feature.
218
#
219
code_quality:
220
  image: docker:stable
221
  stage: test
222 223 224 225 226 227 228 229 230 231 232 233
  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
234 235
  except:
  - schedules
236
  artifacts:
237
    paths: [gl-code-quality-report.json]
238

239 240 241 242
#####################################################
#                    Post stage                     #
#####################################################

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
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

265 266
  except:
  - schedules
267 268 269 270
  artifacts:
    paths:
    - analysis/

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

295
# Deploy, only for merges which land on master branch.
296
#
297
pages:
298 299 300 301
  stage: post
  dependencies:
  - source_dist
  - docs
Tiago Gomes's avatar
Tiago Gomes committed
302 303
  variables:
    ACME_DIR: public/.well-known/acme-challenge
304
  script:
305
  - mkdir -p ${ACME_DIR}
Tiago Gomes's avatar
Tiago Gomes committed
306 307 308 309
    # 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)
310 311 312 313
  artifacts:
    paths:
    - public/
  only:
314 315 316 317 318 319 320 321 322
  #
  # 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
  #
323
  - master
324 325
  except:
  - schedules