name: Build & Test

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-Ctarget-feature=+aes,+ssse3"
  RUST_LOG: "shadowsocks=trace"

jobs:
  build-linux:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/cache@v2
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      - name: Install Rust nightly
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
      - name: Build & Test (Default)
        run: cargo test --verbose --no-fail-fast
      - name: Build & Test (--no-default-features)
        run: cargo test --verbose --no-default-features --no-fail-fast
      - name: Build with All Features Enabled
        run: cargo build --verbose --features "local-redir local-dns dns-over-tls dns-over-https stream-cipher"

  build-windows:
    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/cache@v2
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      - name: Install Rust nightly
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
      - name: Build & Test (Default)
        run: cargo test --verbose --no-fail-fast
      - name: Build & Test (--no-default-features)
        run: cargo test --verbose --no-default-features --no-fail-fast
      - name: Build with All Features Enabled
        run: cargo build --verbose --features "local-dns dns-over-tls dns-over-https stream-cipher"

  build-macos:
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v2
      - name: Install GNU tar
        run: |
          brew install gnu-tar
          # echo "::add-path::/usr/local/opt/gnu-tar/libexec/gnubin"
          echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
      - uses: actions/cache@v2
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      - name: Install Rust nightly
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
      - name: Build & Test (Default)
        run: cargo test --verbose --no-fail-fast
      - name: Build & Test (--no-default-features)
        run: cargo test --verbose --no-default-features --no-fail-fast
      - name: Build with All Features Enabled
        run: cargo build --verbose --features "local-redir local-dns dns-over-tls dns-over-https stream-cipher"
