name: "e2e"

on:
  pull_request:
    paths-ignore:
      - "**.md"
      - ".github/**"
      - "!.github/workflows/e2e.yml"
      - "!.github/workflows/snapshot-*.yml"
    types:
      - "labeled"
      - "synchronize"
      - "opened"
      - "reopened"
  push:
    branches:
      - "master"
    paths-ignore:
      - "**.md"
      - ".github/**"
      - "!.github/workflows/e2e.yml"
      - "!.github/workflows/snapshot-*.yml"

concurrency:
  group: "${{ github.workflow }}-${{ github.ref }}"
  cancel-in-progress: true

jobs:
  marine:
    if: >
      github.event_name == 'push' ||
      (
        contains(github.event.pull_request.labels.*.name, 'e2e') &&
        !github.event.pull_request.head.repo.fork
      )
    uses: ./.github/workflows/snapshot-cargo.yml
    with:
      ref: ${{ github.ref }}

  marine-js:
    name: "marine"
    if: >
      github.event_name == 'push' ||
      (
        contains(github.event.pull_request.labels.*.name, 'e2e') &&
        !github.event.pull_request.head.repo.fork
      )
    uses: ./.github/workflows/snapshot-marine-js.yml
    with:
      ref: ${{ github.ref }}

  sqlite:
    needs:
      - marine
    uses: fluencelabs/sqlite/.github/workflows/build.yml@master

  sqlite-wasm:
    needs: sqlite
    uses: fluencelabs/sqlite-wasm-connector/.github/workflows/snapshot.yml@master

  spell:
    needs: sqlite-wasm
    uses: fluencelabs/spell/.github/workflows/snapshot.yml@main
    with:
      cargo-dependencies: |
        [
          {
            "package": "marine-sqlite-connector",
            "version": "=${{ needs.sqlite-wasm.outputs.version }}",
            "registry": "fluence"
          }
        ]

  decider:
    needs:
      - spell
    uses: fluencelabs/decider/.github/workflows/snapshot.yml@main
    with:
      cargo-dependencies: |
        [
          {
            "package": "fluence-spell-dtos",
            "version": "=${{ needs.spell.outputs.cargo-version }}",
            "registry": "fluence"
          }
        ]

  aquavm-wasm:
    name: "aquavm"
    needs:
      - marine

    uses: fluencelabs/aquavm/.github/workflows/snapshot-air-interpreter-wasm.yml@master
    with:
      cargo-dependencies: |
        [
          {
            "package": "marine-runtime",
            "manifest": "avm/server/Cargo.toml",
            "version": "=${{ needs.marine.outputs.version }}",
            "registry": "fluence"
          },
          {
            "package": "fluence-app-service",
            "manifest": "air/Cargo.toml",
            "version": "=${{ needs.marine.outputs.version }}",
            "registry": "fluence"
          }
        ]

  aquavm-crates:
    name: "aquavm"
    needs:
      - marine
      - aquavm-wasm

    uses: fluencelabs/aquavm/.github/workflows/snapshot-cargo.yml@master
    with:
      cargo-dependencies: |
        [
          {
            "package": "marine-runtime",
            "manifest": "avm/server/Cargo.toml",
            "version": "=${{ needs.marine.outputs.version }}",
            "registry": "fluence"
          },
          {
            "package": "fluence-app-service",
            "manifest": "air/Cargo.toml",
            "version": "=${{ needs.marine.outputs.version }}",
            "registry": "fluence"
          }
        ]

  aquavm-avm:
    name: "aquavm"
    needs:
      - aquavm-wasm
    uses: fluencelabs/aquavm/.github/workflows/snapshot-avm.yml@master

  nox:
    needs:
      - marine
      - aquavm-crates
      - spell
      - decider

    uses: fluencelabs/nox/.github/workflows/build.yml@debug-spell-dtos
    with:
      cargo-dependencies: |
        [
          {
            "package": "fluence-app-service",
            "version": "=${{ needs.marine.outputs.version }}",
            "registry": "fluence"
          },
          {
            "package": "avm-server",
            "version": "=${{ needs.aquavm-crates.outputs.version }}",
            "registry": "fluence"
          },
          {
            "package": "air-interpreter-wasm",
            "version": "=${{ needs.aquavm-crates.outputs.version }}",
            "registry": "fluence"
          },
          {
            "package": "decider-distro",
            "version": "=${{ needs.decider.outputs.cargo-version }}",
            "manifest": "crates/system-services/Cargo.toml",
            "registry": "fluence"
          },
          {
            "package": "fluence-spell-dtos",
            "version": "=${{ needs.spell.outputs.cargo-version }}",
            "registry": "fluence"
          },
          {
            "package": "fluence-spell-distro",
            "version": "=${{ needs.spell.outputs.cargo-version }}",
            "registry": "fluence"
          }
        ]

  aquavm-tests:
    name: "aquavm"
    needs:
      - marine

    uses: fluencelabs/aquavm/.github/workflows/tests.yml@master
    with:
      cargo-dependencies: |
        [
          {
            "package": "marine-runtime",
            "manifest": "avm/server/Cargo.toml",
            "version": "=${{ needs.marine.outputs.version }}",
            "registry": "fluence"
          },
          {
            "package": "fluence-app-service",
            "manifest": "air/Cargo.toml",
            "version": "=${{ needs.marine.outputs.version }}",
            "registry": "fluence"
          }
        ]

  nox-snapshot:
    name: "nox"
    needs:
      - nox

    uses: fluencelabs/nox/.github/workflows/container.yml@master
    with:
      image-name: "docker.fluence.dev/marine"
      flavour: "minimal"
      nox-sha: "${{ needs.nox.outputs.nox-sha }}"

  nox-tests:
    name: "nox"
    needs:
      - marine
      - aquavm-crates
      - spell
      - decider

    uses: fluencelabs/nox/.github/workflows/tests.yml@master
    with:
      cargo-dependencies: |
        [
          {
            "package": "fluence-app-service",
            "version": "=${{ needs.marine.outputs.version }}",
            "registry": "fluence"
          },
          {
            "package": "avm-server",
            "version": "=${{ needs.aquavm-crates.outputs.version }}",
            "registry": "fluence"
          },
          {
            "package": "air-interpreter-wasm",
            "version": "=${{ needs.aquavm-crates.outputs.version }}",
            "registry": "fluence"
          },
          {
            "package": "decider-distro",
            "version": "=${{ needs.decider.outputs.cargo-version }}",
            "manifest": "crates/system-services/Cargo.toml",
            "registry": "fluence"
          },
          {
            "package": "fluence-spell-dtos",
            "version": "=${{ needs.spell.outputs.cargo-version }}",
            "registry": "fluence"
          },
          {
            "package": "fluence-spell-distro",
            "version": "=${{ needs.spell.outputs.cargo-version }}",
            "registry": "fluence"
          }
        ]

  js-client-tests:
    name: "js-client"
    needs:
      - marine-js
      - aquavm-avm
      - nox-snapshot

    uses: fluencelabs/js-client/.github/workflows/tests.yml@master
    with:
      marine-js-version: "${{ needs.marine-js.outputs.version }}"
      avm-version: "${{ needs.aquavm-avm.outputs.version }}"
      nox-image: "${{ needs.nox-snapshot.outputs.nox-image }}"

  js-client:
    needs:
      - marine-js
      - aquavm-avm

    uses: fluencelabs/js-client/.github/workflows/snapshot.yml@master
    with:
      marine-js-version: "${{ needs.marine-js.outputs.version }}"
      avm-version: "${{ needs.aquavm-avm.outputs.version }}"

  flox-snapshot:
    name: "flox"
    needs:
      - js-client

    uses: fluencelabs/flox/.github/workflows/snapshot.yml@main
    with:
      js-client-snapshots: "${{ needs.js-client.outputs.js-client-snapshots }}"

  aqua:
    needs:
      - js-client
      - nox-snapshot

    uses: fluencelabs/aqua/.github/workflows/tests.yml@main
    with:
      js-client-snapshots: "${{ needs.js-client.outputs.js-client-snapshots }}"
      nox-image: "${{ needs.nox-snapshot.outputs.nox-image }}"

  spell-aqua-tests:
    name: "spell"
    needs:
      - nox-snapshot
      - flox-snapshot
    uses: fluencelabs/spell/.github/workflows/tests.yml@main
    with:
      nox-image: "${{ needs.nox-snapshot.outputs.nox-image }}"
      flox-version: "${{ needs.flox-snapshot.outputs.version }}"

  registry:
    needs:
      - nox-snapshot
      - flox-snapshot
      - sqlite-wasm

    uses: fluencelabs/registry/.github/workflows/tests.yml@main
    with:
      nox-image: "${{ needs.nox-snapshot.outputs.nox-image }}"
      flox-version: "${{ needs.flox-snapshot.outputs.version }}"
      cargo-dependencies: |
        [
          {
            "package": "marine-sqlite-connector",
            "version": "=${{ needs.sqlite-wasm.outputs.version }}",
            "registry": "fluence"
          }
        ]

  flox:
    needs:
      - js-client
      - marine
      - nox-snapshot

    uses: fluencelabs/flox/.github/workflows/tests.yml@main
    with:
      marine-version: "${{ needs.marine.outputs.version }}"
      mrepl-version: "${{ needs.marine.outputs.version }}"
      nox-image: "${{ needs.nox-snapshot.outputs.nox-image }}"
      js-client-snapshots: "${{ needs.js-client.outputs.js-client-snapshots }}"