name: "e2e"

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

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

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

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

  avm:
    name: "aquavm"
    needs: air-interpreter-wasm
    uses: ./.github/workflows/snapshot-avm.yml
    with:
      ref: ${{ github.ref }}

  cargo:
    name: "aquavm"
    needs: air-interpreter-wasm
    uses: ./.github/workflows/snapshot-cargo.yml
    with:
      ref: ${{ github.ref }}

  nox:
    needs:
      - cargo

    uses: fluencelabs/nox/.github/workflows/build.yml@master
    with:
      cargo-dependencies: |
        [
          {
            "package": "avm-server",
            "version": "=${{ needs.cargo.outputs.version }}",
            "registry": "fluence"
          },
          {
            "package": "air-interpreter-wasm",
            "version": "=${{ needs.cargo.outputs.version }}",
            "registry": "fluence"
          }
        ]

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

    uses: fluencelabs/nox/.github/workflows/container.yml@master
    with:
      image-name: "docker.fluence.dev/aquavm"

  nox-tests:
    name: "nox"
    needs:
      - cargo

    uses: fluencelabs/nox/.github/workflows/tests.yml@master
    with:
      cargo-dependencies: |
        [
          {
            "package": "avm-server",
            "version": "=${{ needs.cargo.outputs.version }}",
            "registry": "fluence"
          },
          {
            "package": "air-interpreter-wasm",
            "version": "=${{ needs.cargo.outputs.version }}",
            "registry": "fluence"
          }
        ]

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

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

  js-client:
    needs:
      - avm

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

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

    uses: fluencelabs/cli/.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 }}"

  registry:
    needs:
      - fcli-snapshot
      - nox-snapshot

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

  fcli:
    needs:
      - nox-snapshot
      - js-client

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