name: audrey
on: [push, pull_request]
jobs:
  rustfmt-check:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Install stable
      uses: actions-rs/toolchain@v1
      with:
        profile: minimal
        toolchain: stable
        override: true
        components: rustfmt
    - name: Run rustfmt
      uses: actions-rs/cargo@v1
      with:
        command: fmt
        args: --all -- --check

  cargo-test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Update apt
      run: sudo apt update
    - name: Install alsa dev tools
      run: sudo apt-get install libasound2-dev
    - name: Install stable
      uses: actions-rs/toolchain@v1
      with:
        profile: minimal
        toolchain: stable
        override: true
    - name: Test default features
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: --verbose
    - name: Test flac only
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: --no-default-features --features "flac" --verbose
    - name: Test ogg vorbis only
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: --no-default-features --features "ogg_vorbis" --verbose
    - name: Test wav only
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: --no-default-features --features "wav" --verbose
    - name: Test caf alac only
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: --no-default-features --features "caf_alac" --verbose
    - name: Test docs
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: --doc --verbose

  cargo-doc:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Update apt
      run: sudo apt update
    - name: Install alsa dev tools
      run: sudo apt-get install libasound2-dev
    - name: Install stable
      uses: actions-rs/toolchain@v1
      with:
        profile: minimal
        toolchain: stable
        override: true
    - name: cargo doc
      uses: actions-rs/cargo@v1
      with:
        command: doc
        args: --all-features --verbose

  cargo-publish:
    if: github.event_name == 'push' && github.ref == 'refs/heads/master'
    env:
      CRATESIO_TOKEN: ${{ secrets.CRATESIO_TOKEN }}
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Update apt
      run: sudo apt update
    - name: Install alsa dev tools
      run: sudo apt-get install libasound2-dev
    - name: Install stable
      uses: actions-rs/toolchain@v1
      with:
        profile: minimal
        toolchain: stable
        override: true
    - name: Cargo publish audrey
      continue-on-error: true
      run: cargo publish --token $CRATESIO_TOKEN
