浏览代码

add CI workflow and scripts to rebuild search index

Dan Allen 3 年之前
父节点
当前提交
a3024326a3

+ 20 - 0
.github/actions/algolia-config.json

@@ -0,0 +1,20 @@
+{
+  "index_name": "security-docs",
+  "start_urls": [
+    "https://docs.spring.io/spring-security/reference/"
+  ],
+  "selectors": {
+    "lvl0": {
+      "selector": "//nav[@class='crumbs']//li[@class='crumb'][last()-1]",
+      "type": "xpath",
+      "global": true,
+      "default_value": "Home"
+    },
+    "lvl1": ".doc h1",
+    "lvl2": ".doc h2",
+    "lvl3": ".doc h3",
+    "lvl4": ".doc h4",
+    "text": ".doc p, .doc td.content, .doc th.tableblock"
+  }
+}
+

+ 21 - 0
.github/actions/algolia-docsearch-scraper.sh

@@ -0,0 +1,21 @@
+#!/bin/bash
+
+###
+# Docs
+# config.json https://docsearch.algolia.com/docs/config-file
+# Run the crawler https://docsearch.algolia.com/docs/run-your-own/#run-the-crawl-from-the-docker-image
+
+### USAGE
+if [ "$#" -ne 3 ]; then
+  echo -e "not enough arguments USAGE:\n\n$0 \$ALGOLIA_APPLICATION_ID \$ALGOLIA_API_KEY \$CONFIG_FILE\n\n" >&2
+  exit 1
+fi
+
+# Script Parameters
+APPLICATION_ID=$1
+API_KEY=$2
+CONFIG_FILE=$3
+
+#### Script
+script_dir=$(dirname $0)
+docker run -e "APPLICATION_ID=$APPLICATION_ID" -e "API_KEY=$API_KEY" -e "CONFIG=$(cat $CONFIG_FILE | jq -r tostring)" algolia/docsearch-scraper

+ 1 - 1
.github/workflows/deploy-docs.yml

@@ -4,8 +4,8 @@ on:
 permissions: read-all
 jobs:
   build:
-    runs-on: ubuntu-latest
     #if: github.repository_owner == 'spring-projects'
+    runs-on: ubuntu-latest
     steps:
     - name: Checkout
       uses: actions/checkout@v2

+ 15 - 0
.github/workflows/rebuild-search-index.yml

@@ -0,0 +1,15 @@
+name: Rebuild Search Index
+on:
+  workflow_dispatch:
+permissions: read-all
+jobs:
+  build:
+    #if: github.repository_owner == 'spring-projects'
+    runs-on: ubuntu-latest
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v2
+      with:
+        fetch-depth: 5
+    - name: Run Docsearch Scraper
+      run: $GITHUB_WORKSPACE/.github/actions/algolia-docsearch-scraper.sh "${{ secrets.ALGOLIA_APPLICATION_ID }}" "${{ secrets.ALGOLIA_WRITE_API_KEY }}" $GITHUB_WORKSPACE/.github/actions/algolia-config.json