name: Catalog

on:
  push:
    branches:
      - master
    paths:
      - 'catalog/**'
  pull_request:
    branches:
      - master
    paths:
      - 'catalog/**'

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
      with:
        fetch-depth: 1
        submodules: false
    - name: Set up Python
      uses: actions/setup-python@v1
      with:
        python-version: 3.x
        architecture: x64
    - name: Set up Node.js
      uses: actions/setup-node@v1
      with:
        node-version: 12.x
    - run: yarn catalog:install
    - run: yarn catalog:test
    - run: yarn catalog:pack
    - name: Push metadata to Algolia
      run: yarn catalog:publish
      env:
        ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
        ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }}
      if: github.event_name != 'pull_request'
    - name: Upload icons to S3
      uses: jakejarvis/s3-sync-action@v0.5.0
      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_REGION: 'us-east-1'
        SOURCE_DIR: 'catalog/dist'
        DEST_DIR: 'apps'
      if: github.event_name != 'pull_request'