stages:
  - build
variables:
  GIT_DEPTH: "3"
  SIMPLECOV: "true"
  RUST_BACKTRACE: "1"
  RUSTFLAGS: ""
  CARGOFLAGS: ""
cache:
  key: "$CI_BUILD_NAME/$CI_BUILD_REF_NAME"
  untracked: true
linux-stable:
  stage: build
  image: ethcore/rust:stable
  only:
    - master
    - beta
    - tags
    - stable
  script:
    - cargo build --release $CARGOFLAGS
    - strip target/release/parity
    - md5sum target/release/parity >> parity.md5
    - sh scripts/deb-build.sh amd64
    - cp target/release/parity deb/usr/bin/parity
    - export VER=$(grep -m 1 version Cargo.toml | awk '{print $3}' | tr -d '"' | tr -d "\n")
    - dpkg-deb -b deb "parity_"$VER"_amd64.deb"
    - md5sum "parity_"$VER"_amd64.deb" >> "parity_"$VER"_amd64.deb.md5"
    - aws configure set aws_access_key_id $s3_key
    - aws configure set aws_secret_access_key $s3_secret
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/x86_64-unknown-linux-gnu/parity --body target/release/parity
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/x86_64-unknown-linux-gnu/parity.md5 --body parity.md5
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/x86_64-unknown-linux-gnu/"parity_"$VER"_amd64.deb" --body "parity_"$VER"_amd64.deb"
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/x86_64-unknown-linux-gnu/"parity_"$VER"_amd64.deb.md5" --body "parity_"$VER"_amd64.deb.md5"
  tags:
    - rust
    - rust-stable
  artifacts:
    paths:
    - target/release/parity
    name: "stable-x86_64-unknown-linux-gnu_parity"
linux-stable-14.04:
  stage: build
  image: ethcore/rust-14.04:latest
  only:
    - master
    - beta
    - tags
    - stable
  script:
    - cargo build --release $CARGOFLAGS
    - strip target/release/parity
    - md5sum target/release/parity >> parity.md5
    - sh scripts/deb-build.sh amd64
    - cp target/release/parity deb/usr/bin/parity
    - export VER=$(grep -m 1 version Cargo.toml | awk '{print $3}' | tr -d '"' | tr -d "\n")
    - dpkg-deb -b deb "parity_"$VER"_amd64.deb"
    - md5sum "parity_"$VER"_amd64.deb" >> "parity_"$VER"_amd64.deb.md5"
    - aws configure set aws_access_key_id $s3_key
    - aws configure set aws_secret_access_key $s3_secret
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/x86_64-unknown-ubuntu_14_04-gnu/parity --body target/release/parity
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/x86_64-unknown-ubuntu_14_04-gnu/parity.md5 --body parity.md5
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/x86_64-unknown-ubuntu_14_04-gnu/"parity_"$VER"_amd64.deb" --body "parity_"$VER"_amd64.deb"
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/x86_64-unknown-ubuntu_14_04-gnu/"parity_"$VER"_amd64.deb.md5" --body "parity_"$VER"_amd64.deb.md5"
  tags:
    - rust
    - rust-14.04
  artifacts:
    paths:
    - target/release/parity
    name: "stable-x86_64-unknown-ubuntu_14_04-gnu_parity"
linux-beta:
  stage: build
  image: ethcore/rust:beta
  only:
    - master
    - beta
    - tags
    - stable
  script:
    - cargo build --release $CARGOFLAGS
    - strip target/release/parity
  tags:
    - rust
    - rust-beta
  artifacts:
    paths:
    - target/release/parity
    name: "beta-x86_64-unknown-linux-gnu_parity"
  allow_failure: true
linux-nightly:
  stage: build
  image: ethcore/rust:nightly
  only:
    - master
    - beta
    - tags
    - stable
  script:
    - cargo build --release $CARGOFLAGS
    - strip target/release/parity
  tags:
    - rust
    - rust-nightly
  artifacts:
    paths:
    - target/release/parity
    name: "nigthly-x86_64-unknown-linux-gnu_parity"
  allow_failure: true
linux-centos:
  stage: build
  image: ethcore/rust-centos:latest
  only:
    - master
    - beta
    - tags
    - stable
  script:
    - export CXX="g++"
    - export CC="gcc"
    - cargo build --release $CARGOFLAGS
    - strip target/release/parity
    - md5sum target/release/parity >> parity.md5
    - aws configure set aws_access_key_id $s3_key
    - aws configure set aws_secret_access_key $s3_secret
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/x86_64-unknown-centos-gnu/parity --body target/release/parity
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/x86_64-unknown-centos-gnu/parity.md5 --body parity.md5
  tags:
    - rust
    - rust-centos
  artifacts:
    paths:
    - target/release/parity
    name: "x86_64-unknown-centos-gnu_parity"
linux-armv7:
  stage: build
  image: ethcore/rust-armv7:latest
  only:
    - beta
    - tags
    - stable
  script:
    - export CC=arm-linux-gnueabihf-gcc
    - export CXX=arm-linux-gnueabihf-g++
    - export HOST_CC=gcc
    - export HOST_CXX=g++
    - rm -rf .cargo
    - mkdir -p .cargo
    - echo "[target.armv7-unknown-linux-gnueabihf]" >> .cargo/config
    - echo "linker= \"arm-linux-gnueabihf-gcc\"" >> .cargo/config
    - cat .cargo/config
    - cargo build --target armv7-unknown-linux-gnueabihf --release $CARGOFLAGS
    - arm-linux-gnueabihf-strip target/armv7-unknown-linux-gnueabihf/release/parity
    - md5sum target/armv7-unknown-linux-gnueabihf/release/parity >> parity.md5
    - sh scripts/deb-build.sh armhf
    - cp target/armv7-unknown-linux-gnueabihf/release/parity deb/usr/bin/parity
    - export VER=$(grep -m 1 version Cargo.toml | awk '{print $3}' | tr -d '"' | tr -d "\n")
    - dpkg-deb -b deb "parity_"$VER"_armhf.deb"
    - md5sum "parity_"$VER"_armhf.deb" >> "parity_"$VER"_armhf.deb.md5"
    - aws configure set aws_access_key_id $s3_key
    - aws configure set aws_secret_access_key $s3_secret
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/armv7-unknown-linux-gnueabihf/parity --body target/armv7-unknown-linux-gnueabihf/release/parity
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/armv7-unknown-linux-gnueabihf/parity.md5 --body parity.md5
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/armv7-unknown-linux-gnueabihf/"parity_"$VER"_armhf.deb" --body "parity_"$VER"_armhf.deb"
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/armv7-unknown-linux-gnueabihf/"parity_"$VER"_armhf.deb.md5" --body "parity_"$VER"_armhf.deb.md5"
  tags:
    - rust
    - rust-arm
  artifacts:
    paths:
    - target/armv7-unknown-linux-gnueabihf/release/parity
    name: "armv7_unknown_linux_gnueabihf_parity"
  allow_failure: true
linux-arm:
  stage: build
  image: ethcore/rust-arm:latest
  only:
    - beta
    - tags
    - stable
  script:
    - export CC=arm-linux-gnueabihf-gcc
    - export CXX=arm-linux-gnueabihf-g++
    - export HOST_CC=gcc
    - export HOST_CXX=g++
    - rm -rf .cargo
    - mkdir -p .cargo
    - echo "[target.arm-unknown-linux-gnueabihf]" >> .cargo/config
    - echo "linker= \"arm-linux-gnueabihf-gcc\"" >> .cargo/config
    - cat .cargo/config
    - cargo build --target arm-unknown-linux-gnueabihf --release $CARGOFLAGS
    - arm-linux-gnueabihf-strip target/arm-unknown-linux-gnueabihf/release/parity
    - md5sum target/arm-unknown-linux-gnueabihf/release/parity >> parity.md5
    - sh scripts/deb-build.sh armhf
    - cp target/arm-unknown-linux-gnueabihf/release/parity deb/usr/bin/parity
    - export VER=$(grep -m 1 version Cargo.toml | awk '{print $3}' | tr -d '"' | tr -d "\n")
    - dpkg-deb -b deb "parity_"$VER"_armhf.deb"
    - md5sum "parity_"$VER"_armhf.deb" >> "parity_"$VER"_armhf.deb.md5"
    - aws configure set aws_access_key_id $s3_key
    - aws configure set aws_secret_access_key $s3_secret
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/arm-unknown-linux-gnueabihf/parity --body target/arm-unknown-linux-gnueabihf/release/parity
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/arm-unknown-linux-gnueabihf/parity.md5 --body parity.md5
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/arm-unknown-linux-gnueabihf/"parity_"$VER"_armhf.deb" --body "parity_"$VER"_armhf.deb"
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/arm-unknown-linux-gnueabihf/"parity_"$VER"_armhf.deb.md5" --body "parity_"$VER"_armhf.deb.md5"
  tags:
    - rust
    - rust-arm
  artifacts:
    paths:
    - target/arm-unknown-linux-gnueabihf/release/parity
    name: "arm-unknown-linux-gnueabihf_parity"
  allow_failure: true
linux-armv6:
  stage: build
  image: ethcore/rust-armv6:latest
  only:
    - beta
    - tags
    - stable
  script:
    - export CC=arm-linux-gnueabi-gcc
    - export CXX=arm-linux-gnueabi-g++
    - export HOST_CC=gcc
    - export HOST_CXX=g++
    - rm -rf .cargo
    - mkdir -p .cargo
    - echo "[target.arm-unknown-linux-gnueabi]" >> .cargo/config
    - echo "linker= \"arm-linux-gnueabi-gcc\"" >> .cargo/config
    - cat .cargo/config
    - cargo build --target arm-unknown-linux-gnueabi --release $CARGOFLAGS
    - arm-linux-gnueabi-strip target/arm-unknown-linux-gnueabi/release/parity
    - md5sum target/arm-unknown-linux-gnueabi/release/parity >> parity.md5
    - aws configure set aws_access_key_id $s3_key
    - aws configure set aws_secret_access_key $s3_secret
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/arm-unknown-linux-gnueabi/parity --body target/arm-unknown-linux-gnueabi/release/parity
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/arm-unknown-linux-gnueabi/parity.md5 --body parity.md5
  tags:
    - rust
    - rust-arm
  artifacts:
    paths:
    - target/arm-unknown-linux-gnueabi/release/parity
    name: "arm-unknown-linux-gnueabi_parity"
  allow_failure: true
linux-aarch64:
  stage: build
  image: ethcore/rust-aarch64:latest
  only:
    - beta
    - tags
    - stable
  script:
    - export CC=aarch64-linux-gnu-gcc
    - export CXX=aarch64-linux-gnu-g++
    - export HOST_CC=gcc
    - export HOST_CXX=g++
    - rm -rf .cargo
    - mkdir -p .cargo
    - echo "[target.aarch64-unknown-linux-gnu]" >> .cargo/config
    - echo "linker= \"aarch64-linux-gnu-gcc\"" >> .cargo/config
    - cat .cargo/config
    - cargo build --target aarch64-unknown-linux-gnu --release $CARGOFLAGS
    - aarch64-linux-gnu-strip target/aarch64-unknown-linux-gnu/release/parity
    - md5sum target/aarch64-unknown-linux-gnu/release/parity >> parity.md5
    - sh scripts/deb-build.sh arm64
    - cp target/aarch64-unknown-linux-gnu/release/parity deb/usr/bin/parity
    - export VER=$(grep -m 1 version Cargo.toml | awk '{print $3}' | tr -d '"' | tr -d "\n")
    - dpkg-deb -b deb "parity_"$VER"_arm64.deb"
    - md5sum "parity_"$VER"_arm64.deb" >> "parity_"$VER"_arm64.deb.md5"
    - aws configure set aws_access_key_id $s3_key
    - aws configure set aws_secret_access_key $s3_secret
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/aarch64-unknown-linux-gnu/parity --body target/aarch64-unknown-linux-gnu/release/parity
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/aarch64-unknown-linux-gnu/parity.md5 --body parity.md5
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/aarch64-unknown-linux-gnu/"parity_"$VER"_arm64.deb" --body "parity_"$VER"_arm64.deb"
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/aarch64-unknown-linux-gnu/"parity_"$VER"_arm64.deb.md5" --body "parity_"$VER"_arm64.deb.md5"
  tags:
    - rust
    - rust-arm
  artifacts:
    paths:
    - target/aarch64-unknown-linux-gnu/release/parity
    name: "aarch64-unknown-linux-gnu_parity"
  allow_failure: true
darwin:
  stage: build
  only:
    - beta
    - tags
    - stable
  script:
    - cargo build --release $CARGOFLAGS
    - rm -rf parity.md5
    - md5sum target/release/parity >> parity.md5
    - aws configure set aws_access_key_id $s3_key
    - aws configure set aws_secret_access_key $s3_secret
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/x86_64-apple-darwin/parity --body target/release/parity
    - aws s3api put-object --bucket builds-parity --key $CI_BUILD_REF_NAME/x86_64-apple-darwin/parity.md5 --body parity.md5
  tags:
    - osx
  artifacts:
    paths:
    - target/release/parity
    name: "x86_64-apple-darwin_parity"
windows:
  stage: build
  only:
    - beta
    - tags
    - stable
  script:
    - set INCLUDE=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include;C:\vs2015\VC\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt
    - set LIB=C:\vs2015\VC\lib;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64
    - set RUST_BACKTRACE=1
    - set RUSTFLAGS=%RUSTFLAGS% -Zorbit=off
    - rustup default stable-x86_64-pc-windows-msvc
    - cargo build --release %CARGOFLAGS%
    - curl -sL --url "https://github.com/ethcore/win-build/raw/master/SimpleFC.dll" -o nsis\SimpleFC.dll
    - curl -sL --url "https://github.com/ethcore/win-build/raw/master/vc_redist.x64.exe" -o nsis\vc_redist.x64.exe
    - signtool sign /f %keyfile% /p %certpass% target\release\parity.exe
    - msbuild windows\ptray\ptray.vcxproj /p:Platform=x86 /p:Configuration=Release
    - signtool sign /f %keyfile% /p %certpass% windows\ptray\release\ptray.exe
    - cd nsis
    - makensis.exe installer.nsi
    - copy installer.exe InstallParity.exe
    - signtool sign /f %keyfile% /p %certpass% InstallParity.exe
    - md5sums InstallParity.exe > InstallParity.exe.md5
    - zip win-installer.zip InstallParity.exe InstallParity.exe.md5
    - md5sums win-installer.zip > win-installer.zip.md5
    - cd ..\target\release\
    - md5sums parity.exe parity.pdb > parity.md5
    - md5sums parity.exe > parity.exe.md5
    - zip parity.zip parity.exe parity.pdb parity.md5
    - md5sums parity.zip > parity.zip.md5
    - cd ..\..
    - aws configure set aws_access_key_id %s3_key%
    - aws configure set aws_secret_access_key %s3_secret%
    - aws s3api put-object --bucket builds-parity --key %CI_BUILD_REF_NAME%/x86_64-pc-windows-msvc/parity.exe --body target\release\parity.exe
    - aws s3api put-object --bucket builds-parity --key %CI_BUILD_REF_NAME%/x86_64-pc-windows-msvc/parity.exe.md5 --body target\release\parity.exe.md5
    - aws s3api put-object --bucket builds-parity --key %CI_BUILD_REF_NAME%/x86_64-pc-windows-msvc/parity.zip --body target\release\parity.zip
    - aws s3api put-object --bucket builds-parity --key %CI_BUILD_REF_NAME%/x86_64-pc-windows-msvc/parity.zip.md5 --body target\release\parity.zip.md5
    - aws s3api put-object --bucket builds-parity --key %CI_BUILD_REF_NAME%/x86_64-pc-windows-msvc/InstallParity.exe --body nsis\InstallParity.exe
    - aws s3api put-object --bucket builds-parity --key %CI_BUILD_REF_NAME%/x86_64-pc-windows-msvc/InstallParity.exe.md5 --body nsis\InstallParity.exe.md5
    - aws s3api put-object --bucket builds-parity --key %CI_BUILD_REF_NAME%/x86_64-pc-windows-msvc/win-installer.zip --body nsis\win-installer.zip
    - aws s3api put-object --bucket builds-parity --key %CI_BUILD_REF_NAME%/x86_64-pc-windows-msvc/win-installer.zip.md5 --body nsis\win-installer.zip.md5
  tags:
   - rust-windows
  artifacts:
    paths:
    - target/release/parity.exe
    - target/release/parity.pdb
    - nsis/InstallParity.exe
    name: "x86_64-pc-windows-msvc_parity"
#test-darwin:
#  stage: build
#  before_script:
#    - git submodule update --init --recursive
#  script:
#    - export RUST_BACKTRACE=1
#    - ./test.sh $CARGOFLAGS --no-release
#  tags:
#    - osx
#test-windows:
#  stage: build
#  before_script:
#    - git submodule update --init --recursive
#  script:
#    - set RUST_BACKTRACE=1
#    - cargo test --features json-tests -p rlp -p ethash -p ethcore -p ethcore-bigint -p ethcore-dapps -p ethcore-rpc -p ethcore-signer -p ethcore-util -p ethcore-network -p ethcore-io -p ethkey -p ethstore -p ethsync -p ethcore-ipc -p ethcore-ipc-tests -p ethcore-ipc-nano -p parity %CARGOFLAGS% --verbose --release
#  tags:
#    - rust-windows
#  allow_failure: true
test-linux:
  stage: build
  before_script:
    - git submodule update --init --recursive
  script:
    - export RUST_BACKTRACE=1
    - ./test.sh $CARGOFLAGS --no-release
  tags:
    - rust-test
js-release:
  stage: build
  image: ethcore/javascript:latest
  only:
    - master
  before_script:
    - ./js/scripts/install-deps.sh
  script:
    - ./js/scripts/build.sh
    - ./js/scripts/release.sh
  tags:
    - javascript
js-tests:
  stage: build
  image: ethcore/javascript:latest
  before_script:
    - ./js/scripts/install-deps.sh
  script:
    - ./js/scripts/lint.sh
    - ./js/scripts/test.sh
    - ./js/scripts/build.sh
  tags:
    - javascript-test
