name: Run Algolia Crawler

on:
  # Runs on pushes targeting the default branch
  workflow_run:
    workflows: ['Build/Deploy to GitHub Pages']
    types:
      - completed

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

# Allow one concurrent deployment
concurrency:
  group: 'algolia'
  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
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    steps:
      - uses: actions/checkout@v2

      - name: Get the content of algolia.json as config
        id: algolia_config
        run: echo "::set-output name=config::$(cat algolia/config.json | jq -r tostring)"

      - name: Push indices to Algolia
        uses: signcl/docsearch-scraper-action@master
        env:
          APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
          API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
          CONFIG: ${{ steps.algolia_config.outputs.config }}
