name: Node.js Application

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

jobs:
  build:

    runs-on: ${{ matrix.os }}
    permissions:
        id-token: write
        contents: read

    strategy:
      max-parallel: 3
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        node-version: [14.x, 16.x, 18.x]

    steps:
    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-region: us-east-1
        role-to-assume: arn:aws:iam::264319671630:role/GitHubActionsOidc

    - uses: actions/checkout@v2
  
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - name: Install dependencies
      run: npm install
    - name: Build & Lint
      run: npm run build

    - name: Test
      run: |
        GITHUB_SHA_SHORT=$(git rev-parse --short $GITHUB_SHA)
        npm test
        npm run integrationTest --test-ledger-suffix=${{ strategy.job-index }}-$GITHUB_SHA_SHORT
      shell: bash
