image: stellarbullet/x86_64-unknown-linux-gnu:stable

stages:
  - test
  - deploy
  
cache:
  key: $CI_JOB_NAME
  paths:
    - $CARGO_HOME/registry
    - target

stable:
    stage: test
    script:
        - cargo test
        
beta:
    image: stellarbullet/x86_64-unknown-linux-gnu:beta
    stage: test
    script:
        - cargo test
        
nightly:
    image: stellarbullet/x86_64-unknown-linux-gnu:nightly
    stage: test
    allow_failure: true
    script:
        - cargo fmt -- --check
        - cargo test

badges:
  stage: deploy
  script:
    - LOC=$(cloc --json . | jq -r '.Rust.code')
    - curl -X PUT -d image_url="https://img.shields.io/badge/LOC-$LOC-blue.svg" -H "Private-Token:$ACCESS_TOKEN" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/badges/$LOC_BADGE_ID"

    - RUSTC_VERSION=$(rustc --version | awk '{ print $2 }')
    - curl -X PUT -d image_url="https://img.shields.io/badge/Rust-${RUSTC_VERSION//-/--}-orange.svg" -H "Private-Token:$ACCESS_TOKEN" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/badges/$RUST_BADGE_ID"
  only:
    - tags

publish:
  stage: deploy
  script:
    - cargo login $CARGO_LOGIN_TOKEN
    - cargo publish
  only:
    - tags
    
