|
| 1 | +image: "ubuntu:bionic" |
| 2 | + |
| 3 | +variables: |
| 4 | + DOCKER_DRIVER: overlay2 |
| 5 | + |
| 6 | +cache: |
| 7 | + # Cache by branch/tag and job name |
| 8 | + # Gitlab can't use caches from parent pipelines when doing the first build in a PR, so we use artifacts to copy |
| 9 | + # caches into PRs |
| 10 | + key: ${CI_COMMIT_REF_SLUG}-${CI_JOB_NAME}${CI_EXTERNAL_PULL_REQUEST_IID} |
| 11 | + paths: |
| 12 | + - $CI_PROJECT_DIR/cache |
| 13 | + |
| 14 | +stages: |
| 15 | + - build |
| 16 | + |
| 17 | +.build_template: &build_template |
| 18 | + stage: build |
| 19 | + before_script: |
| 20 | + - export BUILD_TARGET="$CI_JOB_NAME" |
| 21 | + - echo BUILD_TARGET=$BUILD_TARGET |
| 22 | + - source ./ci/matrix.sh |
| 23 | + |
| 24 | + # The ubuntu base image has apt configured to delete caches after each invocation, which is something that is not desirable for us |
| 25 | + - rm /etc/apt/apt.conf.d/docker-clean |
| 26 | + - apt-get update |
| 27 | + - apt-get install -y wget unzip |
| 28 | + |
| 29 | + # Init cache |
| 30 | + - export CACHE_DIR=$CI_PROJECT_DIR/cache |
| 31 | + - mkdir -p $CACHE_DIR |
| 32 | + - | |
| 33 | + if [ "$CI_COMMIT_REF_SLUG" != "develop" -a "$CI_COMMIT_TAG" == "" ]; then |
| 34 | + if [ ! -d $CACHE_DIR/ccache ]; then |
| 35 | + echo "Downloading cache from develop branch" |
| 36 | + if wget -O cache-artifact.zip https://gitlab.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME/-/jobs/artifacts/develop/download?job=$CI_JOB_NAME; then |
| 37 | + unzip cache-artifact.zip |
| 38 | + rm cache-artifact.zip |
| 39 | + mv cache-artifact/* $CACHE_DIR/ |
| 40 | + else |
| 41 | + echo "Failed to download cache" |
| 42 | + fi |
| 43 | + else |
| 44 | + echo "Not touching cache (was initialized from previous build)" |
| 45 | + fi |
| 46 | + else |
| 47 | + echo "Not touching cache (building develop branch or tag)" |
| 48 | + fi |
| 49 | + # Create missing cache dirs |
| 50 | + - mkdir -p $CACHE_DIR/ccache && mkdir -p $CACHE_DIR/depends && mkdir -p $CACHE_DIR/sdk-sources && mkdir -p $CACHE_DIR/apt |
| 51 | + # Keep this as it makes caching related debugging easier |
| 52 | + - ls -lah $CACHE_DIR && ls -lah $CACHE_DIR/depends && ls -lah $CACHE_DIR/ccache && ls -lah $CACHE_DIR/apt |
| 53 | + - mv $CACHE_DIR/apt/* /var/cache/apt/archives/ || true |
| 54 | + |
| 55 | + # Install base packages |
| 56 | + - apt-get dist-upgrade -y |
| 57 | + - apt-get install -y git g++ autotools-dev libtool m4 automake autoconf pkg-config zlib1g-dev libssl1.0-dev curl ccache bsdmainutils cmake |
| 58 | + - apt-get install -y python3 python3-dev python3-pip |
| 59 | + |
| 60 | + # jinja2 is needed for combine_logs.py |
| 61 | + - pip3 install jinja2 |
| 62 | + |
| 63 | + # Setup some environment variables |
| 64 | + - if [ "$CI_EXTERNAL_PULL_REQUEST_IID" != "" ]; then export PULL_REQUEST="true"; else export PULL_REQUEST="false"; fi |
| 65 | + - export COMMIT_RANGE="$CI_COMMIT_BEFORE_SHA..$CI_COMMIT_SHA" |
| 66 | + - export JOB_NUMBER="$CI_JOB_ID" |
| 67 | + - export HOST_SRC_DIR=$CI_PROJECT_DIR |
| 68 | + - echo PULL_REQUEST=$PULL_REQUEST COMMIT_RANGE=$COMMIT_RANGE HOST_SRC_DIR=$HOST_SRC_DIR CACHE_DIR=$CACHE_DIR |
| 69 | + - echo "Commit log:" && git log --format=fuller -1 |
| 70 | + |
| 71 | + # Build dash_hash |
| 72 | + - git clone https://github.com/dashpay/dash_hash |
| 73 | + - cd dash_hash && python3 setup.py install |
| 74 | + |
| 75 | + # Install build target specific packages |
| 76 | + - echo PACKAGES=$PACKAGES |
| 77 | + - if [ -n "$DPKG_ADD_ARCH" ]; then dpkg --add-architecture "$DPKG_ADD_ARCH" ; fi |
| 78 | + - if [ -n "$PACKAGES" ]; then apt-get update && apt-get install -y --no-install-recommends --no-upgrade $PACKAGES; fi |
| 79 | + |
| 80 | + # Move apt packages into cache |
| 81 | + - mv /var/cache/apt/archives/* $CACHE_DIR/apt/ || true |
| 82 | + |
| 83 | + # Make mingw use correct threading libraries |
| 84 | + - update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix || true |
| 85 | + - update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix || true |
| 86 | + - update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix || true |
| 87 | + - update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix || true |
| 88 | + |
| 89 | + script: |
| 90 | + - export BUILD_TARGET="$CI_JOB_NAME" |
| 91 | + - cd $CI_PROJECT_DIR |
| 92 | + - ./ci/build_depends.sh |
| 93 | + - ./ci/build_src.sh |
| 94 | + - ./ci/test_unittests.sh |
| 95 | + - ./ci/test_integrationtests.sh |
| 96 | + |
| 97 | + after_script: |
| 98 | + # Copy all cache files into cache-artifact so that they get uploaded. We only do this for develop so that artifacts |
| 99 | + # stay minimal for PRs and branches (we never need them) |
| 100 | + - mkdir $CI_PROJECT_DIR/cache-artifact |
| 101 | + - mkdir -p $CI_PROJECT_DIR/testlogs |
| 102 | + - | |
| 103 | + if [ "$CI_COMMIT_REF_SLUG" = "develop" ]; then |
| 104 | + cp -ra $CACHE_DIR/* $CI_PROJECT_DIR/cache-artifact/ |
| 105 | + fi |
| 106 | +
|
| 107 | + # We're actually only interested in the develop branch creating the cache artifact, but there is no way to control this |
| 108 | + # until https://gitlab.com/gitlab-org/gitlab-foss/issues/25478 gets implemented. Until then, we use an expiration time of |
| 109 | + # 3 days and rely on daily builds to refresh the cache artifacts. We also keep non-develop artifacts at minimum size |
| 110 | + artifacts: |
| 111 | + name: cache-artifact |
| 112 | + when: always |
| 113 | + paths: |
| 114 | + - $CI_PROJECT_DIR/cache-artifact |
| 115 | + - $CI_PROJECT_DIR/testlogs |
| 116 | + expire_in: 3 days |
| 117 | + |
| 118 | +arm-linux: |
| 119 | + <<: *build_template |
| 120 | + |
| 121 | +win32: |
| 122 | + <<: *build_template |
| 123 | + |
| 124 | +win64: |
| 125 | + <<: *build_template |
| 126 | + |
| 127 | +linux32: |
| 128 | + <<: *build_template |
| 129 | + |
| 130 | +linux64: |
| 131 | + <<: *build_template |
| 132 | + |
| 133 | +linux64_nowallet: |
| 134 | + <<: *build_template |
| 135 | + |
| 136 | +linux64_release: |
| 137 | + <<: *build_template |
| 138 | + |
| 139 | +mac: |
| 140 | + <<: *build_template |
0 commit comments