name: ci-casper-js-sdk

on:
  workflow_dispatch:

  push:
    branches:
      - 'dev'
      - 'feat-*'
      - 'release-*'
      - 'condor'
    paths-ignore:
      - '**.md'

  pull_request:
    branches:
      - 'dev'
      - 'feat-*'
      - 'release-*'
      - 'condor'
    paths-ignore:
      - '**.md'

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
        node-version: [18.x, 22.x]
        os: [ubuntu-22.04]
    runs-on: ${{ matrix.os }}
    env:
      FAUCET_PRIV_KEY: 'MC4CAQAwBQYDK2VwBCIEIM0OhegYkU4zxgXeZggBdAR6+XkByue+3iZbznGbCUkM' #ci/test-assets/secret-key.pem
      NODE_URL: 'http://3.20.57.210:7777/rpc'
      HTTP_EVENT_STREAM_URL: 'http://3.20.57.210:9999/events'
      HTTPS_EVENT_STREAM_URL: 'https://events.mainnet.casperlabs.io/events/main'
      NETWORK_NAME: 'dev-net'
      RUST_LOG: 'INFO'
      VERSION_QUERY: '{"jsonrpc": "2.0", "id": "1", "method": "info_get_status"}'
      MAINNET_NODE_URL: 'https://rpc.mainnet.casperlabs.io/rpc'
      TESTNET_NODE_URL: 'https://rpc.testnet.casperlabs.io/rpc'

    steps:
      - name: Checkout
        uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@5b949b50c3461bbcd5a540b150c368278160234a #v3.4.0
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'

      - name: Install
        run: npm install

      - name: Audits
        run: npm audit --omit=dev

      - name: Lints
        run: npm run lint:ci

      - name: Unit Test
        run: ${{ matrix.node-version == '22.x' && 'npm run test:node:unit:node22' || 'npm run test:node:unit' }}

      - name: Test build
        run: npm run build
