diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2a957d10c070865148a960f8cffd65e61ee7fbc7..33edc5fd7700770f7c4fb14f4b8735cd0b40e33b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,13 +12,15 @@ stages: variables: GIT_STRATEGY: fetch - GIT_DEPTH: 3 - CARGO_HOME: "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_JOB_NAME}" + GIT_DEPTH: "100" + CARGO_HOME: "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}" CARGO_TARGET_DIR: "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}" - CI_SERVER_NAME: "GitLab CI" - REGISTRY: "paritytech" - RUSTUP_TOOLCHAIN: nightly - RUST_LIB_BACKTRACE: 0 + RUST_LIB_BACKTRACE: "0" + +workflow: + rules: + - if: $CI_COMMIT_TAG + - if: $CI_COMMIT_BRANCH .collect-artifacts: &collect-artifacts artifacts: @@ -29,28 +31,29 @@ variables: - artifacts/ .docker-env: &docker-env - image: ${REGISTRY}/contracts-ci-linux:latest + image: paritytech/contracts-ci-linux:latest before_script: - cargo -vV - rustc -vV - rustup show - bash --version - - mkdir -p ${CARGO_HOME}; touch ${CARGO_HOME}/config - - mkdir -p ${CARGO_TARGET_DIR} + - ./scripts/pre_cache.sh # global RUSTFLAGS overrides the linker args so this way is better to pass the flags - - printf '[build]\nrustflags = ["-C", "link-dead-code"]\n' | tee ${CARGO_HOME}/config + - printf '[build]\nrustflags = ["-C", "link-dead-code"]\n' > ${CARGO_HOME}/config - sccache -s - git show - only: - - master - - /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 - - schedules - - web - - /^[0-9]+$/ # PRs + rules: + - if: $CI_PIPELINE_SOURCE == "web" + - if: $CI_PIPELINE_SOURCE == "schedule" + - if: $CI_COMMIT_REF_NAME == "master" + - if: $CI_COMMIT_REF_NAME == "tags" + - if: $CI_COMMIT_BRANCH + - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs + - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 dependencies: [] interruptible: true retry: - max: 2 + max: 2 when: - runner_system_failure - unknown_failure @@ -74,7 +77,7 @@ test: stage: test <<: *docker-env script: - - cargo test --verbose --all --all-features + - cargo test --verbose --workspace --all-features #### stage: build (default features) @@ -82,9 +85,11 @@ build: stage: build <<: *docker-env <<: *collect-artifacts - only: - - schedules - - master + rules: + - if: $CI_PIPELINE_SOURCE == "web" + - if: $CI_PIPELINE_SOURCE == "schedule" + - if: $CI_COMMIT_REF_NAME == "master" + - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 script: - cargo build --verbose --release after_script: diff --git a/scripts/pre_cache.sh b/scripts/pre_cache.sh new file mode 100755 index 0000000000000000000000000000000000000000..76723c2fb2f40473433ac99c9513e06e8544d78a --- /dev/null +++ b/scripts/pre_cache.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -u + +# if there is no directory for this $CI_COMMIT_REF_NAME/$CI_JOB_NAME +# create such directory and +# copy recursively all the files from the newest dir which has $CI_JOB_NAME, if it exists + +# caches are in /ci-cache/${CI_PROJECT_NAME}/${2}/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME} + +function prepopulate { + if [[ ! -d $1 ]]; then + mkdir -p "$1"; + FRESH_CACHE=$(find "/ci-cache/$CI_PROJECT_NAME/$2" -mindepth 2 -maxdepth 2 \ + -type d -name "$CI_JOB_NAME" -not -path "$1" -exec stat --printf="%Y\t%n\n" {} \; |sort -n -r |head -1 |cut -f2); + if [[ -d "$FRESH_CACHE" ]]; then + echo "____Using" "$FRESH_CACHE" "to prepopulate the cache____"; + time cp -r "$FRESH_CACHE" "$1"; + else + echo "_____No such $2 dir, proceeding from scratch_____"; + fi + else + echo "____No need to prepopulate $2 cache____"; + fi +} + +# CARGO_HOME cache was moved to the same "project/cache_type/branch_name/job_name" level as +# CARGO_TARGET_DIR because of frequent weird data-race issues. This just means that the same cache that +# would have been used for the entire pipeline will be duplicated for the each job. +prepopulate "$CARGO_HOME" cargo +prepopulate "$CARGO_TARGET_DIR" targets