
name: Stage Runner

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the stage branch
on:
  push:
    branches: [ stage ]

# 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"
  build:
    # 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
    - name: Checkout action repo
      uses: actions/checkout@v2

    # Checks-out NodeJS, get version 10.x
    - name: Use NodeJS 10.x
      uses: actions/setup-node@v2
      with:
        node-version: '10'

    # Start install the npm
    - name: NPM Install
      run: npm install

    # Build the script
    - name: Build the script
      run: npm run staging

    # Deploy the script to DO Spaces, first checks-out s3-sync repo
    - name: Deploy to DO Spaces
      uses: jakejarvis/s3-sync-action@master
      with: 
        args: --acl public-read --follow-symlinks --delete
      env:
        AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        AWS_S3_ENDPOINT: ${{ secrets.AWS_ENDPOINT }}
        SOURCE_DIR: 'dist'
        DEST_DIR: 'public'
