name: Push

on:
  push:
    branches: [ main ]

jobs:
  push:
    name: push
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Run Antora
        uses: kameshsampath/antora-site-action@master
        with:
          antora_playbook: antora-playbook.yml

      - name: Copy landing page
        run: |
          mkdir -p $GITHUB_WORKSPACE/website/releases/latest/download
          cp -rf $GITHUB_WORKSPACE/build/site/* $GITHUB_WORKSPACE/website
          cp -rf $GITHUB_WORKSPACE/landing/* $GITHUB_WORKSPACE/website
          cp -rf $GITHUB_WORKSPACE/VERSION $GITHUB_WORKSPACE/website/releases/latest/download
          touch $GITHUB_WORKSPACE/website/.nojekyll

      - name: Deploy to GitHub Pages
        uses: JamesIves/github-pages-deploy-action@4.0.0
        with:
          folder: website
          branch: 'gh-pages'
          commit-message: "[CI] Publish Documentation for ${{ github.sha }}"

      - name: Update search index
        uses: darrenjennings/algolia-docsearch-action@master
        with:
          algolia_application_id: ${{ secrets.ALGOLIA_APPLICATION_ID }}
          algolia_api_key: ${{ secrets.ALGOLIA_ADMIN_KEY }}
          file: 'algolia-config.json'
