on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: rust:1
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      
      - run: rustup component add rustfmt
      - run: cargo test
      - run: cargo fmt --all -- --check

      - name: Publish crate
        if: github.ref == 'refs/heads/master'
        run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CRATESIO_TOKEN }}
