name: "Validations"
on:
  workflow_dispatch:
  push:
# TODO: re-enable this once we're done with testing
#    branches:
#      - main
  pull_request:


jobs:

  Static-Analysis:
    # Note: changing this job name requires making the same update in the .github/workflows/release.yaml pipeline
    name: "Static analysis"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Bootstrap environment
        uses: ./.github/actions/bootstrap

      - name: Run static analysis
        run: make static-analysis


  Unit-Test:
    # Note: changing this job name requires making the same update in the .github/workflows/release.yaml pipeline
    name: "Unit tests"
    strategy:
      matrix:
        # todo: support windows
        platform: [ubuntu-latest, macos-latest]
        # platform: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.platform }}
    steps:

      - uses: actions/checkout@v3

      - name: Bootstrap environment
        uses: ./.github/actions/bootstrap

      - name: Run unit tests
        run: make unit


  Build-Snapshot-Artifacts:
    name: "Build snapshot artifacts"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Bootstrap environment
        uses: ./.github/actions/bootstrap

      - name: Build snapshot artifacts
        run: make snapshot

      # why not use actions/upload-artifact? It is very slow (3 minutes to upload ~600MB of data, vs 10 seconds with this approach).
      # see https://github.com/actions/upload-artifact/issues/199 for more info
      - name: Upload snapshot artifacts
        uses: actions/cache/save@v3
        with:
          path: snapshot
          key: snapshot-build-${{ github.run_id }}


  Acceptance-Linux:
    needs: [ build-artifacts ]
    runs-on: ubuntu-latest
    steps:

      - uses: actions/checkout@master

      - name: Download snapshot build
        uses: actions/cache/restore@v3
        with:
          path: snapshot
          key: snapshot-build-${{ github.run_id }}

      - name: Test linux run
        run: make ci-test-linux-run

      - name: Test DEB package installation
        run: make ci-test-deb-package-install

      - name: Test RPM package installation
        run: make ci-test-rpm-package-install


  Acceptance-Mac:
    needs: [ build-artifacts ]
    runs-on: macos-latest
    steps:

      - uses: actions/checkout@master

      - name: Download snapshot build
        uses: actions/cache/restore@v3
        with:
          path: snapshot
          key: snapshot-build-${{ github.run_id }}

      - name: Test darwin run
        run: make ci-test-mac-run


  Acceptance-Windows:
    needs: [ build-artifacts ]
    runs-on: windows-latest
    steps:

      - uses: actions/checkout@master

      - name: Download snapshot build
        uses: actions/cache/restore@v3
        with:
          path: snapshot
          key: snapshot-build-${{ github.run_id }}

      - name: Test windows run
        run: make ci-test-windows-run
