Skip to content

Index TED Developer Docs #195

Index TED Developer Docs

Index TED Developer Docs #195

Workflow file for this run

name: Index TED Developer Docs
on:
workflow_dispatch:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '0 4 * * *'
env:
JOBS_REPO: github.com/OP-TED/OP-TED.github.io
BUILD_JOB: Build and publish TED Developer Docs
INDEX_JOB: Index TED Developer Docs
jobs:
check_if_should_index:
name: Check if site should be indexed
runs-on: [ubuntu-latest]
outputs:
shouldIndex: ${{ steps.checkShouldIndex.outputs.shouldIndex }}
steps:
- name: Find latest successful site build
env:
GH_TOKEN: ${{ github.token }}
run: |
lastBuildDate=$(gh run list -R $JOBS_REPO -w "$BUILD_JOB" --json conclusion,status,updatedAt --jq '.[] | select((.conclusion=="success") and (.status="completed")).updatedAt'|head -1); \
echo "lastBuildDate=${lastBuildDate}" >> $GITHUB_ENV
- name: Find latest successful site indexing
env:
GH_TOKEN: ${{ github.token }}
run: |
lastIndexDate=$(gh run list -R $JOBS_REPO -w "$INDEX_JOB" --json conclusion,status,updatedAt --jq '.[] | select((.conclusion=="success") and (.status="completed")).updatedAt'|head -1); \
echo "lastIndexDate=${lastIndexDate}" >> $GITHUB_ENV
- name: Check if indexing should run
id: checkShouldIndex
run: |
if [ -z "${{ env.lastIndexDate }}" ]; then \
shouldIndex=true;
else
[ -n "${{ env.lastBuildDate }}" ] \
&& [[ "$(date -d "${{ env.lastBuildDate }}" "+%Y%m%d%H%M%S")" > "$(date -d "${{ env.lastIndexDate }}" "+%Y%m%d%H%M%S")" ]] \
&& shouldIndex=true || shouldIndex=false; \
fi; \
echo "shouldIndex=${shouldIndex}" >> ${GITHUB_OUTPUT}
delete_site_index:
name: "Delete existing site index"
runs-on: [ubuntu-latest]
needs: check_if_should_index
if: needs.check_if_should_index.outputs.shouldIndex == 'true'
steps:
- name: Download Algolia CLI
run: 'mkdir -p algolia-cli; curl -L "https://github.com/algolia/cli/releases/download/v1.2.1/algolia_1.2.1_linux_386.tar.gz"|tar xpz -C algolia-cli --strip-components=1'
- name: Create Algolia profile
run: ./algolia-cli/algolia profile add --name ted-profile --app-id ${{ secrets.ALGOLIA_APPLICATION_ID }} --admin-api-key ${{ secrets.ALGOLIA_API_KEY }} --default
- name: Delete index ${{ secrets.ALGOLIA_INDEX_NAME }}
run: ./algolia-cli/algolia indices delete -y ${{ secrets.ALGOLIA_INDEX_NAME }}
index_site:
name: "Index site using Docsearch Crawler"
needs: delete_site_index
runs-on: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get the content of docsearch-config.json as config
id: docsearch_config
run: echo "docsearch_config=$(cat config/docsearch-config.json | jq -r tostring)" >> ${GITHUB_ENV}
- 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: ${{ env.docsearch_config }}