[Notes] [Git][BuildGrid/buildgrid][mablanch/000-refactor-gitlab-ci] .gitlab-ci.yml: Fix and refactor the whole pipeline



Title: GitLab

Martin Blanchard pushed to branch mablanch/000-refactor-gitlab-ci at BuildGrid / buildgrid

Commits:

1 changed file:

Changes:

  • .gitlab-ci.yml
    1
    -# Use a debian image with python 3.5 (and pip3) pre-installed
    
    1
    +# Debian Stretch base image with python 3.5:
    
    2
    +#
    
    2 3
     image: python:3.5-stretch
    
    3 4
     
    
    4
    -variables:
    
    5
    -  BGD: bgd
    
    6
    -
    
    7 5
     stages:
    
    8 6
       - test
    
    9 7
       - post
    
    10 8
       - deploy
    
    11 9
     
    
    12 10
     
    
    13
    -before_script:
    
    14
    -  - python3 -m pip install --upgrade setuptools pip
    
    15
    -  - export PATH=~/.local/bin:${PATH}
    
    16
    -  - python3 -m pip install --user --editable ".[tests]"
    
    11
    +# Templates and global variables.
    
    12
    +#
    
    13
    +variables:
    
    14
    +  BGD: "${CI_PROJECT_DIR}/env/bin/bgd"
    
    15
    +  PYTHON: "${CI_PROJECT_DIR}/env/bin/python"
    
    16
    +
    
    17
    +.build-template:
    
    18
    +  before_script: &install-base
    
    19
    +    - apt-get update && apt-get install -y python3 python3-venv python3-pip graphviz
    
    20
    +    - python3 -m venv env  # Creates a virtual environment
    
    21
    +    - ${PYTHON} -m pip --cache-dir=.pip install --upgrade setuptools pip wheel
    
    22
    +    - ${PYTHON} -m pip --cache-dir=.pip install --editable ".[auth,docs,tests]"
    
    23
    +  cache:
    
    24
    +    paths:
    
    25
    +      - .pip
    
    26
    +
    
    17 27
     
    
    18
    -.tests-template: &linux-tests
    
    28
    +# Test stage, build and test the code.
    
    29
    +#
    
    30
    +unit-tests:
    
    19 31
       stage: test
    
    20
    -  variables:
    
    21
    -    PYTEST_ADDOPTS: "--color=yes"
    
    32
    +  extends: .build-template
    
    22 33
       script:
    
    23
    -    - python3 -m pip install --user --editable ".[auth]"
    
    24
    -    - python3 setup.py test
    
    34
    +    - ${PYTHON} setup.py test
    
    35
    +  after_script:
    
    25 36
         - mkdir -p coverage/
    
    26 37
         - cp .coverage coverage/coverage."${CI_JOB_NAME}"
    
    38
    +  variables:
    
    39
    +    PYTEST_ADDOPTS: "--color=yes"
    
    27 40
       artifacts:
    
    28 41
         paths:
    
    29
    -    - coverage/
    
    42
    +      - coverage/
    
    30 43
     
    
    31
    -.run-dummy-job-template: &dummy-job
    
    44
    +dummy-tests:
    
    32 45
       stage: test
    
    46
    +  extends: .build-template
    
    33 47
       script:
    
    34 48
         - ${BGD} server start data/config/default.conf &
    
    35
    -    - sleep 1 # Allow server to boot
    
    49
    +    - sleep 1  # Allows server to boot
    
    36 50
         - ${BGD} bot dummy &
    
    37 51
         - ${BGD} cas upload-dummy
    
    38 52
         - ${BGD} execute request-dummy --wait-for-completion
    
    39 53
     
    
    40
    -
    
    41
    -# Test stage, build and test the code.
    
    42
    -#
    
    43
    -tests-debian-stretch:
    
    44
    -  <<: *linux-tests
    
    45
    -
    
    46
    -run-dummy-job-debian:
    
    47
    -  <<: *dummy-job
    
    48
    -
    
    49
    -buildbox-e2e:
    
    50
    -  image: registry.gitlab.com/buildgrid/buildbox/buildbox-e2e:latest
    
    54
    +e2e-tests:
    
    51 55
       stage: test
    
    52
    -  before_script: []
    
    56
    +  image: registry.gitlab.com/buildgrid/buildbox/buildbox-e2e:latest
    
    53 57
       script:
    
    54 58
         - BUILDGRID_SOURCE_ROOT=`pwd` end-to-end-test.sh
    
    55 59
     
    
    60
    +
    
    56 61
     # Post-build stage, documentation, coverage report...
    
    57 62
     #
    
    58 63
     documentation:
    
    59 64
       stage: post
    
    65
    +  extends: .build-template
    
    60 66
       script:
    
    61
    -    - apt-get update && apt-get install -y graphviz
    
    62
    -    - python3 -m pip install --user --editable ".[docs]"
    
    63 67
         - make -C docs html
    
    64 68
         - mkdir -p documentation/
    
    65 69
         - cp -a docs/build/html/. documentation/
    
    66 70
       artifacts:
    
    67 71
         paths:
    
    68
    -    - documentation/
    
    72
    +      - documentation/
    
    69 73
     
    
    70 74
     coverage:
    
    71 75
       stage: post
    
    76
    +  extends: .build-template
    
    72 77
       dependencies:
    
    73
    -  - tests-debian-stretch
    
    78
    +    - unit-tests
    
    74 79
       coverage: '/TOTAL +\d+ +\d+ +(\d+\.\d+)%/'
    
    75 80
       script:
    
    76
    -    - python3 -m pip install --user --editable ".[tests]"
    
    77
    -    - cd coverage/
    
    78
    -    - ls -l .
    
    79
    -    - python3 -m coverage combine --rcfile=../.coveragerc --append coverage.*
    
    80
    -    - python3 -m coverage html --rcfile=../.coveragerc --directory .
    
    81
    -    - python3 -m coverage report --rcfile=../.coveragerc --show-missing
    
    82
    -    - python3 -m coverage erase --rcfile=../.coveragerc
    
    81
    +    - cd coverage/ && ls -la .
    
    82
    +    - ${PYTHON} -m coverage combine --rcfile=../.coveragerc --append coverage.*
    
    83
    +    - ${PYTHON} -m coverage html --rcfile=../.coveragerc --directory .
    
    84
    +    - ${PYTHON} -m coverage report --rcfile=../.coveragerc --show-missing
    
    85
    +    - ${PYTHON} -m coverage erase --rcfile=../.coveragerc
    
    83 86
       artifacts:
    
    84 87
         paths:
    
    85
    -    - coverage/
    
    88
    +      - coverage/
    
    86 89
     
    
    87 90
     # Deployement stage, only for merges which land on master branch.
    
    88 91
     #
    
    89 92
     pages:
    
    90 93
       stage: deploy
    
    91 94
       dependencies:
    
    92
    -  - coverage
    
    93
    -  - documentation
    
    95
    +    - coverage
    
    96
    +    - documentation
    
    94 97
       script:
    
    95
    -  - mkdir -p public/coverage/
    
    96
    -  - cp -a coverage/* public/coverage/
    
    97
    -  - ls -la public/coverage/
    
    98
    -  - cp -a documentation/* public/
    
    99
    -  - ls -la public/
    
    98
    +    - mkdir -p public/coverage/
    
    99
    +    - cp -a coverage/* public/coverage/
    
    100
    +    - ls -la public/coverage/
    
    101
    +    - cp -a documentation/* public/
    
    102
    +    - ls -la public/
    
    100 103
       artifacts:
    
    101 104
         paths:
    
    102
    -    - public/
    
    105
    +      - public/
    
    103 106
       only:
    
    104
    -  - master
    
    107
    +    - master
    
    105 108
     
    
    106
    -trigger-buildbox-e2e-rebuild:
    
    109
    +triggers:
    
    107 110
       stage: deploy
    
    108
    -  variables:
    
    109
    -    GIT_STRATEGY: none
    
    110
    -  script:
    
    111
    +  before_script:
    
    111 112
         - apt-get update && apt-get install -y curl
    
    113
    +  script:
    
    112 114
         - curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=master https://gitlab.com/api/v4/projects/buildgrid%2Fbuildbox%2Fbuildbox-e2e/trigger/pipeline
    
    115
    +  variables:
    
    116
    +    GIT_STRATEGY: none
    
    113 117
       only:
    
    114 118
         - master



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]