.gitlab-ci.yml 5.67 KiB
Newer Older
Denis_P's avatar
Denis_P committed
# .gitlab-ci.yml
#
# canvas-node
Denis_P's avatar
Denis_P committed
#
# pipelines can be triggered manually in the web


stages:
  - build-linux
  - build-mac
  - publish
Denis_P's avatar
Denis_P committed
variables:
  GIT_STRATEGY:                    fetch
  GIT_DEPTH:                       100
Denis_P's avatar
Denis_P committed
  CARGO_INCREMENTAL:               0
Denis_P's avatar
Denis_P committed
  CARGO_TARGET_DIR:                "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"

Denis_P's avatar
Denis_P committed
workflow:
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH

Denis_P's avatar
Denis_P committed
.collect-artifacts:                &collect-artifacts
  artifacts:
    name:                          "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
    when:                          on_success
    expire_in:                     7 days
    paths:
      - artifacts/

.docker-env:                       &docker-env
Denis_P's avatar
Denis_P committed
  image:                           paritytech/ci-linux:production
Denis_P's avatar
Denis_P committed
  before_script:
    - cargo -vV
    - rustc -vV
    - rustup show
    - bash --version
    - mkdir -p ${CARGO_TARGET_DIR}
    - ./scripts/ci/pre_cache.sh
Denis_P's avatar
Denis_P committed
    - sccache -s
  interruptible:                   true
  retry:
    max: 2
    when:
      - runner_system_failure
      - unknown_failure
      - api_failure
  tags:
    - linux-docker

.kubernetes-env:                   &kubernetes-env
  retry:
    max: 2
    when:
      - runner_system_failure
      - unknown_failure
      - api_failure
  interruptible:                   true
  tags:
    - kubernetes-parity-build

.build-refs:                       &build-refs
  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_REF_NAME =~ /^[0-9]+$/                         # PRs
    - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/              # i.e. v1.0, v2.1rc1

.publish-refs:                     &publish-refs
  rules:
    - if: $CI_PIPELINE_SOURCE == "web"
    - if: $CI_PIPELINE_SOURCE == "schedule"
    - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/              # i.e. v1.0, v2.1rc1

### stage:                         fmt

fmt:
  stage:                           fmt
  <<:                              *docker-env
  script:
    - cargo +nightly fmt --verbose --all -- --check

### stage:                         build-linux
Denis_P's avatar
Denis_P committed

build-linux:
  stage:                           build-linux
Denis_P's avatar
Denis_P committed
  <<:                              *docker-env
  <<:                              *collect-artifacts
  <<:                              *build-refs
Denis_P's avatar
Denis_P committed
  script:
    - time cargo build --release
    - time cargo test --release --all
    - mkdir -p ./artifacts/canvas-linux/
    - cp ${CARGO_TARGET_DIR}/release/canvas ./artifacts/canvas-linux/canvas

### stage:                         build-mac
Denis_P's avatar
Denis_P committed

build-mac:
  stage:                           build-mac
Denis_P's avatar
Denis_P committed
  <<:                              *docker-env
  <<:                              *collect-artifacts
  # we run the mac build only when we actually want to publish
  <<:                              *publish-refs
  before_script:
    - unset CARGO_TARGET_DIR
  script:
    - time cargo build --release
    - mkdir -p ./artifacts/canvas-mac/
    - cp target/release/canvas ./artifacts/canvas-mac/canvas
  tags:
    - osx

publish:
  stage:                           publish
  <<:                              *kubernetes-env
  image:                           paritytech/tools:latest
  <<:                              *publish-refs
  needs:
    - job: build-linux
      artifacts: true
    - job: build-mac
      artifacts: true
Denis_P's avatar
Denis_P committed
  script:
    - git describe --tags
    - TAG_NAME=`git describe --tags`
    - echo "tag name ${TAG_NAME}"
    - tar -czvf ./canvas-linux.tar.gz ./artifacts/canvas-linux/canvas
    - tar -czvf ./canvas-mac.tar.gz ./artifacts/canvas-mac/canvas
    - 'curl https://api.github.com/repos/paritytech/canvas-node/releases
        --fail-with-body
        -H "Cookie: logged_in=no"
        -H "Authorization: token ${GITHUB_TOKEN}"'
    - 'curl https://api.github.com/repos/paritytech/canvas-node/releases
        --fail-with-body
        -H "Cookie: logged_in=no"
        -H "Authorization: token ${GITHUB_TOKEN}" | jq .'
    - 'RELEASE_ID=$(curl https://api.github.com/repos/paritytech/canvas-node/releases
Denis_P's avatar
Denis_P committed
        --fail-with-body
        -H "Cookie: logged_in=no"
        -H "Authorization: token ${GITHUB_TOKEN}"
        | jq -r ".[] | select(.tag_name == \"$TAG_NAME\") | .id");
      echo "release id if existent: ${RELEASE_ID}"'
    - 'if [ -z "$RELEASE_ID" ]; then
        RESP=$(curl -X "POST" "https://api.github.com/repos/paritytech/canvas-node/releases"
          --fail-with-body
          -H "Cookie: logged_in=no"
          -H "Authorization: token ${GITHUB_TOKEN}"
          -H "Content-Type: application/json; charset=utf-8"
          -d $"{
              \"tag_name\": \"${TAG_NAME}\",
              \"name\": \"${TAG_NAME}\",
              \"prerelease\": false,
              \"draft\": true
          }");
          echo "api response ${RESP}";
          RELEASE_ID=$(echo $RESP | jq -r .id);
          echo "release id of created release ${RELEASE_ID}";
        fi'
    - echo "release id ${RELEASE_ID}"
Denis_P's avatar
Denis_P committed
    - 'curl -X "POST" "https://uploads.github.com/repos/paritytech/canvas-node/releases/$RELEASE_ID/assets?name=canvas-linux.tar.gz"
        --fail-with-body
        -H "Cookie: logged_in=no"
        -H "Authorization: token ${GITHUB_TOKEN}"
        -H "Content-Type: application/octet-stream"
        --data-binary @"./canvas-linux.tar.gz"'
    - 'curl -X "POST" "https://uploads.github.com/repos/paritytech/canvas-node/releases/$RELEASE_ID/assets?name=canvas-mac.tar.gz"
        --fail-with-body
        -H "Cookie: logged_in=no"
        -H "Authorization: token ${GITHUB_TOKEN}"
        -H "Content-Type: application/octet-stream"
        --data-binary @"./canvas-mac.tar.gz"'