name: "check-deploy"

on:
  push:
    # branches:
    #   - "master"

jobs:
  check-deployment:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - uses: actions/cache@v2
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            ~/.cargo/bin
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      
      - run: docker run -d --rm -e RUST_LOG="info" -p 1210:1210 -p 4310:4310 fluencelabs/fluence -t 1210 -w 4310 -k gKdiCSUr1TFGFEgu2t8Ch1XEUsrN5A2UfBLjSZvfci9SPR3NvZpACfcpPGC3eY4zma1pk7UvYv5zb1VjvPHwCjj --local
      
      - name: Download marine
        run: sudo bash $GITHUB_WORKSPACE/.github/download_marine.sh
      
      - name: Install Rust
        run: |
          rustup toolchain install nightly-2021-04-24-x86_64-unknown-linux-gnu
          rustup default nightly-2021-04-24-x86_64-unknown-linux-gnu
          rustup target add wasm32-wasi --toolchain nightly-2021-04-24-x86_64-unknown-linux-gnu
  
      - uses: actions/cache@v2
        with:
            path: ~/.npm
            key: ${{ runner.os }}-v1-node-14-${{ hashFiles('**/package-lock.json') }}
            restore-keys: |
                ${{ runner.os }}-v1-node-14
      
      - name: Setup Node.js 14
        uses: actions/setup-node@v1
        with:
            node-version: 14

      - run: npm install -g @fluencelabs/fldist

      - name: "Check call_parameters deployment"
        run: |
          set -x
          export NODE="/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3"
          SERVICE_ID=`./deploy.sh`
          fldist --node-addr $NODE run_air -d '{"service_id": "'$SERVICE_ID'"}' -p <(echo '
            (seq
                (call relay (service_id "call_parameters") [] result)
                (call %init_peer_id% (returnService "run") [result])
            )
          ')
        working-directory: marine-examples/call_parameters

