Skip to content

Merge pull request #1794 from neondatabase/dprice-update-contribution… #436

Merge pull request #1794 from neondatabase/dprice-update-contribution…

Merge pull request #1794 from neondatabase/dprice-update-contribution… #436

name: Reindex Algolia Crawler on new doc file added
on:
push:
branches:
- main # Ensures the workflow runs only on pushes to the main branch.
paths:
- 'content/docs/**/*.md'
- 'content/changelog/**/*.md'
- '!content/docs/README.md' # Exclude the README.md file
- '!content/docs/shared-content/**/*.md' # Exclude the shared-content folder
jobs:
check-new-file:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0 # Fetches all history for all branches and tags, necessary for the correct working of git diff.
- name: Check for new file
id: file-check
run: |
git diff --name-status ${{ github.event.before }} ${{ github.sha }} > changes.txt
echo "Added files:"
added_files=$(cat changes.txt | grep '^A' | awk '{print $2}') # Filters out only the added files.
echo $added_files
if [ -z "$added_files" ]; then
echo "::set-output name=new_file::false" # Sets the output variable 'new_file' to false if no new files are added.
else
echo "::set-output name=new_file::true" # Sets it to true if new files are added.
fi
- name: Reindex Algolia Crawler if new file added
if: steps.file-check.outputs.new_file == 'true' # Conditionally runs this step only if new files are added.
env:
CRAWLER_USER_ID: ${{ secrets.CRAWLER_USER_ID }}
CRAWLER_API_KEY: ${{ secrets.CRAWLER_API_KEY }}
CRAWLER_ID: ${{ secrets.CRAWLER_ID }}
run: |
curl -H "Content-Type: application/json" -X POST \
--user $CRAWLER_USER_ID:$CRAWLER_API_KEY \
"https://crawler.algolia.com/api/1/crawlers/$CRAWLER_ID/reindex" # Executes the curl command to reindex Algolia Crawler.