language: rust
rust:
  - stable

cache: cargo

before_install:
  - git submodule update --init --recursive

install:
  - curl -L https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip -o /tmp/protoc.zip
  - unzip /tmp/protoc.zip -d $HOME/protoc

env:
  - PATH=$HOME/protoc/bin:$PATH

script:
  - make all test

stages:
  - test
  
  - name: doc
    if: branch = master

  - name: deploy
    if: branch =~ ^release\/.*$ AND type = push
    

jobs:
  include:
    - stage: test
      script:
        - rustc --version
        - cargo --version
        - cargo test --all --verbose

    - stage: doc
      script:
        - rustc --version
        - cargo --version
        - cargo doc --no-deps
      deploy:
        provider: pages
        skip_cleanup: true
        local_dir: target/doc/
        github_token: $GITHUB_TOKEN
      
    - stage: deploy
      script:
        - rustc --version
        - cargo --version

        # Publish the crate to crates.io
        - cargo publish --token $CARGO_TOKEN

        # Generate a tag with the version we just deployed
        - git tag `cargo pkgid | sed -E 's/.*#(.*:)?(.+)/\2/'`

        # Push the tag back to the repository
        - git push https://awestlake87:$GITHUB_TOKEN@github.com/awestlake87/sc2-proto-rs.git `cargo pkgid | sed -E 's/.*#(.*:)?(.+)/\2/'`