# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x]

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: ls
    - run: cd frontend && npm ci
    - run: cd frontend && CI=false npm run build --if-present # set CI=false to avoid halting build on typescript warnings
    #- run: cd frontend && npm test
    - name: Deploy
      run: |
        cd frontend
        echo "sha=${sha},ref=${ref}"
        git config --global user.name ${user_name}-${sha}
        git config --global user.email ${user_email}
        git remote set-url origin https://${github_token}@github.com/${repository}
        npm run deploy
      env:
        user_name: 'github-actions[bot]'
        user_email: 'github-actions[bot]@users.noreply.github.com'
        github_token: ${{ secrets.ACTIONS_DEPLOY_ACCESS_TOKEN }}
        repository: ${{ github.repository }}
        sha: ${{ github.sha }}
        ref: ${{ github.ref }}