name: Deploy QA

# Controls when the workflow will run
on:
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:
    inputs:
      ref:
        type: string
        description: Deploy a specific commit by hash (optional)
  push:
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Cancel previous QA deployments
        uses: styfle/cancel-workflow-action@0.9.1
        with:
          access_token: ${{ github.token }}
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.event.inputs.ref }}
      - name: Install Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 16
          cache: "npm"
      - run: npm install
      - run: npm run build:qa
        env:
          REACT_APP_BASE_PATH: ${{ github.ref_name }}
      - name: Deploy over FTP
        uses: SamKirkland/FTP-Deploy-Action@4.2.0
        with:
          # ftp server
          server: ${{ secrets.QA_ADDRESS }}
          port: ${{secrets.QA_PORT }}
          # ftp username
          username: ${{ secrets.QA_USERNAME }}
          # ftp password
          password: ${{ secrets.QA_PASSWORD }}
          # protocol to deploy with - ftp, ftps, or ftps-legacy
          protocol: ftps
          # Folder to upload from, must end with trailing slash /
          local-dir: build/
          # Path to upload to on the server. Must end with trailing slash /
          server-dir: /${{ github.ref_name }}/
          # Prints which modifications will be made with current config options, but doesnt actually make any changes
          dry-run: false
          # Deletes ALL contents of server-dir, even items in excluded with exclude argument
          dangerous-clean-slate: true
          # An array of glob patterns, these files will not be included in the publish/delete process
          # exclude:
          # How verbose should the information be - minimal, standard, or verbose
          log-level: standard
          # strict or loose
          security: loose
