Skip to content

Commit c26e13a

Browse files
authored
Algolia webhook YML script
1 parent 7e7f2cc commit c26e13a

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# .github/workflows/call-algolia-deployment-script.yml
2+
name: Call algolia deployment script on merge
3+
4+
on:
5+
push:
6+
branches:
7+
- gh-pages # Trigger only on push to the production branch
8+
9+
jobs:
10+
log-post-titles:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
# Step 1: Checkout the repository
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 2 # Fetch the last two commits to ensure HEAD^ exists
19+
20+
# Step 2: Get the list of new, modified, and deleted files
21+
- name: Get changed files
22+
id: changes
23+
run: |
24+
# Check if there is a previous commit
25+
if git rev-parse --verify HEAD^ > /dev/null 2>&1; then
26+
# Get added, modified, and deleted files in the _posts folder
27+
echo "There is a previous commit"
28+
new_files=$(git diff --name-only --diff-filter=A HEAD^ HEAD -- _posts/)
29+
modified_files=$(git diff --name-only --diff-filter=M HEAD^ HEAD -- _posts/)
30+
deleted_files=$(git diff --name-only --diff-filter=D HEAD^ HEAD -- _posts/)
31+
else
32+
# If no previous commit, compare against the index (for the first commit)
33+
echo "There is no previous commit"
34+
new_files=$(git diff --name-only --diff-filter=A HEAD -- _posts/)
35+
modified_files=$(git diff --name-only --diff-filter=M HEAD -- _posts/)
36+
deleted_files=$(git diff --name-only --diff-filter=D HEAD -- _posts/)
37+
fi
38+
39+
# Replace newlines with commas to ensure output is valid
40+
new_files_escaped=$(echo "$new_files" | tr '\n' '|')
41+
modified_files_escaped=$(echo "$modified_files" | tr '\n' '|')
42+
deleted_files_escaped=$(echo "$deleted_files" | tr '\n' '|')
43+
44+
# Debugging: output the results to check what's captured
45+
echo "New files: $new_files_escaped"
46+
echo "Modified files: $modified_files_escaped"
47+
echo "Deleted files: $deleted_files_escaped"
48+
49+
# Set the outputs
50+
echo "new_files=$new_files_escaped" >> $GITHUB_OUTPUT
51+
echo "modified_files=$modified_files_escaped" >> $GITHUB_OUTPUT
52+
echo "deleted_files=$deleted_files_escaped" >> $GITHUB_OUTPUT
53+
54+
# Step 3: Run custom script with file lists as arguments
55+
- name: Collect post data and run script
56+
env:
57+
BLOG_POSTS_DEPLOY_TO_ALGOLIA_ENDPOINT_PRODUCTION: ${{ secrets.BLOG_POSTS_DEPLOY_TO_ALGOLIA_ENDPOINT_PRODUCTION }} # Production endpoint
58+
BLOG_POSTS_DEPLOY_TO_ALGOLIA_ENDPOINT_DEVELOP: ${{ secrets.BLOG_POSTS_DEPLOY_TO_ALGOLIA_ENDPOINT_DEVELOP }} # Develop endpoint
59+
run: |
60+
# Ensure 'gray-matter' and 'axios' are installed for front-matter parsing
61+
npm install gray-matter axios
62+
63+
# Run the custom script, passing the list of files and extracting their metadata
64+
node ./send-blogs-to-deploy-endpoint.js "${{ steps.changes.outputs.new_files }}" "${{ steps.changes.outputs.modified_files }}" "${{ steps.changes.outputs.deleted_files }}"

0 commit comments

Comments
 (0)