name: solana-js-test
on:
  push:
    branches:
      - main
    paths:
      - ".github/workflows/**"
      - "javascript/solana.js/src/**"
      - "javascript/solana.js/test/**"
      - "javascript/solana.js/package.json"
      - "javascript/solana.js/package-lock.json"

env:
  ANCHOR_VERSION: 0.25.0
  CARGO_TERM_COLOR: always
  SOLANA_VERSION: 1.13.5

jobs:
  solana_js_test:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    steps:
      # Setup Deps
      - uses: actions/checkout@v3
      - name: Setup Linux Build Deps
        uses: ./.github/actions/install-linux-build-deps
      - name: Install Solana
        uses: ./.github/actions/install-solana
        with:
          solana_version: ${{ env.SOLANA_VERSION }}
      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: "npm"
          cache-dependency-path: "**/package-lock.json"
      - name: Build solana.js
        working-directory: javascript/solana.js
        run: npm install && npm run build
      - name: Start Local Validator & Run Tests
        working-directory: javascript/solana.js
        run: |
          solana-keygen new --no-bip39-passphrase --outfile ~/.config/solana/id.json --silent
          mkdir -p .anchor/test-ledger
          npm run localnet:up
