name: release

on:
  push:
    tags:
      - v*

env:
  CARGO_TERM_COLOR: always

jobs:
  publish-crate:
    name: Publish Crate
    runs-on: ubuntu-latest
    steps:
    - name: Clone
      uses: actions/checkout@v2
    - name: Cache
      uses: actions/cache@v2
      with:
        path: |
          ~/.cargo/registry
          ~/.cargo/git
          ~/.rustup
          target
        key: ${{ runner.os }}-stable
    - name: Setup
      run: |
        rustup install stable
    - name: Build
      run: cargo build --verbose
    - name: Run tests
      run: cargo test
    - name: Publish
      run: cargo publish
      env:
        CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
