name: CryptoPRO tests

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]


jobs:
  buildAndTest:
    runs-on: ubuntu-20.04

    strategy:
      matrix:
        node-version: [ lts/*, latest ]

    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}

      - name: Override NODE options for the most recent version
        if: matrix.node-version == 'latest'
        run: echo "NODE_OPTIONS=--openssl-legacy-provider" >> $GITHUB_ENV

      - name: Clean install, build, test
        run: |
          npm ci
          npm run build --if-present
          npm test

      - name: Coveralls
        uses: coverallsapp/github-action@master
        with:
          github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}

  lint:
    runs-on: ubuntu-20.04

    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js latest
        uses: actions/setup-node@v3
        with:
          node-version: latest
      - name: Clean install, lint
        run: |
          npm ci
          npm run lint
