.gitlab-ci.yml 6.22 KB
Newer Older
1
image: buildstream/testsuite-debian:8-master-57-be5a863
2

Tristan Maat's avatar
Tristan Maat committed
3
cache:
4
  key: "$CI_JOB_NAME-"
Tristan Maat's avatar
Tristan Maat committed
5
  paths:
6
    - cache/
Tristan Maat's avatar
Tristan Maat committed
7

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

13 14 15 16
#####################################################
#                  Prepare stage                    #
#####################################################

17 18
# Create a source distribution
#
19 20
source_dist:
  stage: prepare
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  script:

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

  # Create an installer script
  - |
    cat > dist/install.sh << EOF
    #!/bin/sh
    tar -zxf ${tarball}
    cd ${tarball%.tar.gz}
    pip3 install --no-index .
    EOF

  # 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/install.sh
  - chmod +x dist/unpack.sh
  artifacts:
    paths:
    - dist/

53

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

58 59
# Run premerge commits
#
60
.linux-tests-template: &linux-tests
61
  stage: test
62 63
  variables:
    PYTEST_ADDOPTS: "--color=yes"
64
  script:
65 66 67 68 69 70
  # Diagnostics
  - mount
  - df -h

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

72
  - export INTEGRATION_CACHE="$(pwd)/cache/integration-cache"
73

74 75 76 77 78 79 80
  # Unpack and get into dist/buildstream
  - cd dist && ./unpack.sh
  - chown -R buildstream:buildstream buildstream
  - cd buildstream

  # Run the tests from the source distribution, We run as a simple
  # user to test for permission issues
81
  - su buildstream -c 'python3 setup.py test --index-url invalid://uri --addopts --integration'
82

83 84
  # Go back to the toplevel and collect our reports
  - cd ../..
85
  - mkdir -p coverage-linux/
86
  - cp dist/buildstream/.coverage.* coverage-linux/coverage."${CI_JOB_NAME}"
87 88 89
  artifacts:
    paths:
    - coverage-linux/
90

91
tests-debian-8:
92 93
  <<: *linux-tests

94 95 96 97
tests-debian-9:
  image: buildstream/buildstream-debian:master-81-caa5241
  <<: *linux-tests

98
tests-fedora-27:
99 100 101
  image: buildstream/buildstream-fedora:master-56-5d7ee17
  <<: *linux-tests

102

103
tests-unix:
104 105 106
  # 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
  image: buildstream/buildstream-fedora:master-56-5d7ee17
107 108 109
  stage: test
  variables:
    BST_FORCE_BACKEND: "unix"
110
    PYTEST_ADDOPTS: "--color=yes"
111
  script:
112

113
    - export INTEGRATION_CACHE="$(pwd)/cache/integration-cache"
114

115
    # We remove the Bubblewrap and OSTree packages here so that we catch any
116 117 118
    # 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
119
    - dnf erase -y bubblewrap ostree
120

121 122 123
    # Unpack and get into dist/buildstream
    - cd dist && ./unpack.sh && cd buildstream

124
    # Since the unix platform is required to run as root, no user change required
125
    - python3 setup.py test --index-url invalid://uri --addopts --integration
126

127 128
    # Go back to the toplevel and collect our reports
    - cd ../..
129
    - mkdir -p coverage-unix/
130
    - cp dist/buildstream/.coverage.* coverage-unix/coverage.unix
131 132
  artifacts:
    paths:
133 134
    - coverage-unix/
    - logs-unix/
135

136 137 138

# Automatically build documentation for every commit, we want to know
# if building documentation fails even if we're not deploying it.
139 140
# Note: We still do not enforce a consistent installation of python3-sphinx,
#       as it will significantly grow the backing image.
141 142 143
docs:
  stage: test
  script:
144
  - pip3 install sphinx==1.7.1
145
  - pip3 install sphinx-click
146
  - pip3 install sphinx_rtd_theme
147 148 149 150 151 152 153 154 155 156 157 158 159
  - cd dist && ./unpack.sh && cd buildstream
  - pip3 install .
  - make -C doc
  - cd ../..
  - mv dist/buildstream/doc/build/html public
  artifacts:
    paths:
    - public/


#####################################################
#                    Post stage                     #
#####################################################
160

161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
# Check code quality with codeclimate
# This needs some refactoring; we probably just want to provide the codeclimate.json directly
# as an output of radon, with some conversion
#
codequality:
  image: docker:stable
  stage: post
  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
  artifacts:
    paths: [codeclimate.json]

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
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

  artifacts:
    paths:
    - analysis/

209 210 211
# Collate coverage reports
#
coverage:
212
  stage: post
213
  coverage: '/TOTAL +\d+ +\d+ +(\d+\.\d+)%/'
214
  script:
215
    - cd dist && ./unpack.sh && cd buildstream
216
    - pip3 install --no-index .
217 218
    - mkdir report
    - cd report
219
    - cp ../../../coverage-unix/coverage.unix .
220
    - cp ../../../coverage-linux/coverage.* .
221
    - ls coverage.*
222
    - coverage combine --rcfile=../.coveragerc -a coverage.*
223
    - coverage report --rcfile=../.coveragerc -m
224
  dependencies:
225
  - tests-debian-8
226
  - tests-debian-9
227 228
  - tests-fedora-27
  - tests-unix
229
  - source_dist
230

231
# Deploy, only for merges which land on master branch.
232
#
233
pages:
234 235 236 237
  stage: post
  dependencies:
  - source_dist
  - docs
238
  script:
239
  - find public/
240 241 242 243
  artifacts:
    paths:
    - public/
  only:
244 245 246 247 248 249 250 251 252
  #
  # 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
  #
253
  - master