name: Build/Deploy to AWS S3 Staging

on:
  # Runs on pushes targeting the default branch
  push:
    branches: ['stage']
    paths-ignore:
      - 'README.md'
      - '.github/**'

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Allow one concurrent deployment
concurrency:
  group: 'aws'
  cancel-in-progress: true

env:
  BASE_URL: '/'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Check out repo
        uses: actions/checkout@v3
      # Node is required for npm
      - name: Set up Node
        uses: actions/setup-node@v3
        with:
          node-version: '16'
      # Install and build Developer Community site
      - name: Build Developer Community site
        run: |
          export NODE_OPTIONS="--max_old_space_size=4096"
          npm ci 
          npm run gen-api-docs-all
          npm run build
      - name: Configure AWS credentials from Test account
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{secrets.SITE_AWS_ACCESS_KEY_ID}}
          aws-secret-access-key: ${{secrets.SITE_AWS_SECRET_ACCESS_KEY}}
          aws-region: us-east-1

      # push these files to AWS
      - name: Copy files to the test website with the AWS CLI
        run: |
          aws s3 sync ./build s3://spt-developer

