cache:
  key: txoo-global
  paths:
    - bin
    - .cache/cargo

variables:
  CARGO_HOME: "$CI_PROJECT_DIR/.cache/cargo"

before_script:
  - ls -al
  - mkdir -p bin

stages:
  - build

rust-latest:
  tags: [ saas-linux-large-amd64 ]
  stage: build
  image: rust:latest
  script:
    - cargo build --no-default-features --features no-std
    - cargo build --no-default-features --features no-std,use-serde
    - cargo build -p bitcoin-push-decoder --no-default-features --features no-std
    - cargo build --workspace --features test-utils
    - cargo build --workspace
    - cargo test --workspace

rust-latest-extras:
  tags: [ saas-linux-large-amd64 ]
  stage: build
  image: rust:latest
  cache:
    key: txoo-compile-latest-extras
    paths:
      - bin
      - .cache/cargo
  script:
    # bitcoind-client system test
    - ls -l bin
    - if [ ! -e bin/bitcoind ]; then
      wget --no-verbose https://bitcoin.org/bin/bitcoin-core-0.21.0/bitcoin-0.21.0-x86_64-linux-gnu.tar.gz &&
      echo da7766775e3f9c98d7a9145429f2be8297c2672fe5b118fd3dc2411fb48e0032  bitcoin-0.21.0-x86_64-linux-gnu.tar.gz | sha256sum -c &&
      tar xzf bitcoin-0.21.0-x86_64-linux-gnu.tar.gz &&
      mv bitcoin-0.21.0/bin/{bitcoin-cli,bitcoind} bin/ &&
      rm -rf bitcoin-0.21.0 ;
      fi
    - ./bin/bitcoind --regtest --daemon --rpcuser=user --rpcpassword=pass && sleep 5
    - ./bin/bitcoin-cli --regtest --rpcuser=user --rpcpassword=pass getblockchaininfo
    - cargo test -p txoo-bitcoind-client --features system-test
