# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    branches:
      - master
      - prod
      - dev
  pull_request:
    branches:
      - master
      - prod

env:
  NODE_ENV: ci
  DEBUG: "*,-babel*,-eslint*"
  DEBUG_COLORS: true
  CURRENCY_OXR_API_ID: ${{ secrets.CURRENCY_OXR_API_ID }}

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  ci:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout

      - name: Setup Node.js environment
        uses: actions/setup-node
        with:
          # Set always-auth in npmrc
          always-auth: true
          # Version Spec of the version to use.  Examples: 12.x, 10.15.1, >=10.15.0
          node-version: 14.15.1
          # Set this option if you want the action to check for the latest available version that satisfies the version spec
          check-latest: true

      - run: npm ci
      # Runs a single command using the runners shell
      - name: Run security checks (audit + lint)
        run: npm run security

      - name: Cache node modules
        uses: actions/cache
        with:
          path: ~/.npm
          key: v1-npm-deps-${{ hashFiles('**/package-lock.json') }}
          restore-keys: v1-npm-deps-

      - name: Test
        run: npm run test
