name: All Tests and Builds

on:
  push:
    branches: [main, 0.4.x]
  pull_request:
    paths:
      - "**.rs"
      - .github/**
      - .ci/**
      - Cargo.toml

jobs:
  timezones_linux:
    strategy:
      matrix:
        os: [ubuntu-latest]
        tz: ["ACST-9:30", "EST4", "UTC0", "Asia/Katmandu"]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v1
      - run: cargo test --all-features --color=always -- --color=always

  timezones_other:
    strategy:
      matrix:
        os: [macos-latest, windows-latest]
        tz: ["ACST-9:30", "EST4", "UTC0", "Asia/Katmandu"]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v1
      - run: cargo test --lib --all-features --color=always -- --color=always
      - run: cargo test --doc --all-features --color=always -- --color=always

  # later this may be able to be included with the below
  # kept seperate for now as the following don't compile on 1.38.0
  # * rkyv
  # * criterion
  rust_msrv:
    strategy:
      matrix:
        os: [ubuntu-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: 1.38.0
      - uses: Swatinem/rust-cache@v1
      # run --lib and --doc to avoid the long running integration tests which are run elsewhere
      - run: cargo test --lib --features unstable-locales,wasmbind,oldtime,clock,rustc-serialize,serde,winapi --color=always -- --color=always
      - run: cargo test --doc --features unstable-locales,wasmbind,oldtime,clock,rustc-serialize,serde,winapi --color=always -- --color=always

  rust_versions:
    strategy:
      matrix:
        os: [ubuntu-latest]
        rust_version: ["stable", "beta", "nightly"]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust_version }}
      - uses: Swatinem/rust-cache@v1
      # run --lib and --doc to avoid the long running integration tests which are run elsewhere
      - run: cargo test --lib --all-features --color=always -- --color=always
      - run: cargo test --doc --all-features --color=always -- --color=always

  features_check:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - uses: dtolnay/rust-toolchain@stable
      - uses: taiki-e/install-action@cargo-hack
      - uses: Swatinem/rust-cache@v1
      - run: cargo hack check --feature-powerset --optional-deps serde,rkyv --skip default --skip __internal_bench --skip __doctest --skip iana-time-zone --skip pure-rust-locales

  no_std:
    strategy:
      matrix:
        os: [ubuntu-latest]
        target: [thumbv6m-none-eabi, x86_64-fortanix-unknown-sgx]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - uses: Swatinem/rust-cache@v1
      - run: cargo build --target ${{ matrix.target }} --color=always
        working-directory: ./ci/core-test

  alternative_targets:
    strategy:
      matrix:
        os: [ubuntu-latest]
        target: [wasm32-unknown-unknown, wasm32-wasi, wasm32-unknown-emscripten, aarch64-apple-ios, aarch64-linux-android]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - uses: Swatinem/rust-cache@v1
      - uses: actions/setup-node@v1
        with:
          node-version: "12"
      - run: |
          export RUST_BACKTRACE=1
          curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
          wasm-pack --version
      - run: cargo build --target ${{ matrix.target }}  --color=always
  
  features_check_wasm:
    strategy:
      matrix:
        os: [ubuntu-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-unknown-unknown
      - uses: taiki-e/install-action@cargo-hack
      - uses: Swatinem/rust-cache@v1
      - run: cargo hack check --feature-powerset --optional-deps serde,rkyv --skip default --skip __internal_bench --skip __doctest --skip iana-time-zone --skip pure-rust-locales

  cross-targets:
    strategy:
      matrix:
        target:
          - x86_64-sun-solaris
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: cargo install cross
      - uses: Swatinem/rust-cache@v1
      - run: cross check --target ${{ matrix.target }}

  check-docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: dtolnay/rust-toolchain@nightly
      - run: cargo +nightly doc --all-features --no-deps
        env:
          RUSTDOCFLAGS: "-D warnings --cfg docsrs"
