.gitlab-ci.yml 5.47 KiB
Newer Older
default:
  interruptible:                   true
  retry:
    max: 2
    when:
      - runner_system_failure
      - unknown_failure
      - api_failure

stages:
  - lint
  - test
  - benchmark
  - check_benchmark
  - publish

variables:                         &default-vars
  GIT_STRATEGY:                    fetch
  GIT_DEPTH:                       100
  CARGO_INCREMENTAL:               0
  CARGO_TARGET_DIR:                "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
  # ci-linux with rust stable 1.65 and nightly 1.66 (2022-11-13)
  CI_IMAGE:                        "paritytech/ci-linux@sha256:c9a26c7906a85c42d1cfde8333421fcf3c719f222733b1b2cc7d0c74b33c5e21"

.common-refs:                      &common-refs
  rules:
    - if: $CI_PIPELINE_SOURCE == "web"
    - if: $CI_COMMIT_REF_NAME == "main"
    - if: $CI_COMMIT_REF_NAME == "master"
    - if: $CI_PIPELINE_SOURCE == "schedule"
      when: never
    - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/                         # PRs

# run nightly by schedule
.schedule-refs:                    &schedule-refs
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule"

.rust-info-script:                 &rust-info-script
  - rustup show
  - cargo --version
  - rustup +nightly show
  - cargo +nightly --version
  - bash --version
  - sccache -s

.docker-env:                       &docker-env
  image:                           "${CI_IMAGE}"
  before_script:
    - *rust-info-script
    - sccache -s
  tags:
    - linux-docker

.kubernetes-env:                   &kubernetes-env
  image:                           "${CI_IMAGE}"
  tags:
    - kubernetes-parity-build

.collect-artifacts:                &collect-artifacts
  artifacts:
    name:                          "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
    when:                          on_success
    expire_in:                     28 days
    paths:
      - ./artifacts/
    reports:
      dotenv: runner.env
#### stage:                        lint

fmt:
  stage:                           lint
  <<:                              *docker-env
  <<:                              *common-refs
  script:
    - cargo fmt --all -- --check

clippy:
  stage:                           lint
  <<:                              *docker-env
  <<:                              *common-refs
  script:
    - cargo clippy --all-targets

check-rustdoc-links:
  stage:                           lint
  <<:                              *docker-env
  <<:                              *common-refs
  script:
    - RUSTDOCFLAGS="--deny broken_intra_doc_links" cargo doc --workspace --no-deps --document-private-items

#### stage:                       test

check-code:
  stage:                           test
  <<:                              *docker-env
  <<:                              *common-refs
  script:
    - cargo install cargo-hack
    - cargo hack check --workspace --each-feature

test:
  stage:                           test
  <<:                              *docker-env
  <<:                              *common-refs
  script:
    - cargo test

benchmarks:
  stage:                           benchmark
  <<:                              *docker-env
  <<:                              *collect-artifacts
  <<:                              *schedule-refs
  timeout:                         3h
  variables:
    MEASUREMENT_TIME:              10
    SLOW_MEASUREMENT_TIME:         60
  script:
    - cargo bench -p jsonrpsee-benchmarks -- --output-format bencher | tee output.txt
    - mkdir artifacts
    - cp output.txt artifacts/
    - echo ${CI_RUNNER_DESCRIPTION}
    - echo "RUNNER_NAME=${CI_RUNNER_DESCRIPTION}" > runner.env
  tags:
check_bench:
  stage:                           check_benchmark
  variables:
    PROMETHEUS_URL:                "https://thanos.parity-mgmt.parity.io"
    CI_IMAGE:                      "paritytech/benchmarks:latest"
  <<:                              *kubernetes-env
  <<:                              *schedule-refs
  script:
    - check_bench_result artifacts/output.txt

publish-ghpages:
  stage:                           publish
  variables:
    CI_IMAGE:                      "paritytech/tools:latest"
  <<:                              *kubernetes-env
  <<:                              *schedule-refs
  script:
    # setup ssh
    - eval $(ssh-agent)
    - ssh-add - <<< ${GITHUB_SSH_PRIV_KEY}
    - mkdir ~/.ssh && touch ~/.ssh/known_hosts
    - ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
    # Set git config
    - rm -rf .git/config
    - git config user.email "[email protected]"
    - git config user.name "${GITHUB_USER}"
    - git config remote.origin.url "[email protected]:/paritytech/${CI_PROJECT_NAME}.git"
    - git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
    - git fetch origin gh-pages
    # Push result to github
    - git checkout gh-pages
    - mkdir -p bench/gitlab || echo "Directory exists"
    - rm -f bench/gitlab/output.txt || echo "No output.txt"
    - cp artifacts/output.txt bench/gitlab/
    - git add bench/gitlab/output.txt
    - git commit -m "Add output.txt with benchmark results for ${CI_COMMIT_REF_NAME}"
    - git push origin gh-pages
  allow_failure:                   true

publish-bench:
  stage:                           publish
  variables:
    CI_IMAGE:                      "paritytech/tools:latest"
  <<:                              *kubernetes-env
  <<:                              *schedule-refs
  script:
    - echo $RUNNER_NAME
    - ./scripts/ci/push_bench_results.sh artifacts/output.txt