name: package:web_socket_channel

on:
  push:
    branches:
      - master
    paths:
      - '.github/workflows/web_socket_channel.yaml'
      - 'pkgs/web_socket_channel/**'
  pull_request:
    paths:
      - '.github/workflows/web_socket_channel.yaml'
      - 'pkgs/web_socket_channel/**'
  schedule:
    - cron: "0 0 * * 0"

defaults:  
  run:  
    working-directory: pkgs/web_socket_channel/

env:
  PUB_ENVIRONMENT: bot.github

jobs:
  # Check code formatting and static analysis on a single OS (linux)
  # against Dart dev.
  analyze:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        sdk: [dev]
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
      - uses: dart-lang/setup-dart@65eb853c7ba17dde3be364c3d2858773e7144260
        with:
          sdk: ${{ matrix.sdk }}
      - id: install
        name: Install dependencies
        run: dart pub get
      - name: Check formatting
        run: dart format --output=none --set-exit-if-changed .
        if: always() && steps.install.outcome == 'success'
      - name: Analyze code
        run: dart analyze
        if: always() && steps.install.outcome == 'success'

  test:
    needs: analyze
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        sdk: [3.3, dev]
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
      - uses: dart-lang/setup-dart@65eb853c7ba17dde3be364c3d2858773e7144260
        with:
          sdk: ${{ matrix.sdk }}
      - id: install
        name: Install dependencies
        run: dart pub get
      - name: Run VM tests
        run: dart test --platform vm
        if: always() && steps.install.outcome == 'success'
      - name: Run Chrome tests
        run: dart test --platform chrome
        if: always() && steps.install.outcome == 'success'
      - name: Run Chrome tests - wasm
        run: dart test --platform chrome --compiler dart2wasm
        if: always() && steps.install.outcome == 'success' && matrix.sdk == 'dev'

  # Run analysis against the oldest supported pub constraints.
  downgrade:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
      - uses: dart-lang/setup-dart@65eb853c7ba17dde3be364c3d2858773e7144260
      - run: dart pub downgrade
      - run: dart analyze
