Skip to content

Commit 6a51c1a

Browse files
authored
Add Azure AI Search trigger for ops-runbook index (#678)
* Add Azure AI Search trigger for ops-runbook index Add .ci scripts (install-htmlq, install-azcopy, upload, trigger-index) and wire them into the Pages deploy workflow, mirroring the pattern used in hmcts.github.io for the-hmcts-way index. Uploads built HTML to the ops-runbook blob container and triggers the ops-runbook indexer after each deploy. * adding spelling to exceptions file
1 parent 00dafca commit 6a51c1a

6 files changed

Lines changed: 109 additions & 0 deletions

File tree

.ci/install-azcopy.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
sudo apt-get update
5+
sudo apt-get install -y wget curl
6+
7+
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb
8+
sudo dpkg -i packages-microsoft-prod.deb
9+
sudo apt-get update
10+
sudo apt-get install -y azcopy
11+
rm -f packages-microsoft-prod.deb

.ci/install-htmlq.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
wget https://github.com/mgdm/htmlq/releases/download/v0.4.0/htmlq-x86_64-linux.tar.gz
6+
tar -xzf htmlq-x86_64-linux.tar.gz
7+
sudo install htmlq /usr/bin/htmlq
8+
rm -f htmlq-x86_64-linux.tar.gz

.ci/trigger-index.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
API_KEY=$(az search admin-key show \
6+
--service-name platops-slack-help-bot-ptl \
7+
--resource-group slack-help-bot-cftptl-intsvc-rg \
8+
--subscription DTS-CFTPTL-INTSVC \
9+
--query primaryKey \
10+
-o tsv)
11+
12+
curl --fail-with-body \
13+
-X POST \
14+
-H "api-key: ${API_KEY}" \
15+
"https://platops-slack-help-bot-ptl.search.windows.net/indexers('ops-runbook')/search.run?api-version=2024-07-01" \
16+
-d ''
17+
18+
echo "Index triggered"

.ci/upload.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
rm -rf dist
6+
mkdir dist/
7+
8+
function extractMain () {
9+
local path=$1
10+
11+
DIRECTORY=$(dirname "$path")
12+
mkdir -p dist/$DIRECTORY
13+
14+
cat $path | htmlq --text 'main' --remove-nodes '[data-module="page-expiry"]' > dist/$path
15+
}
16+
17+
export -f extractMain
18+
19+
find build -name "*.html" -not -path "build/search/*" -exec bash -c "extractMain \"{}\"" \;
20+
21+
export STORAGE_ACCOUNT_NAME=platopslackhelpbotai
22+
export CONTAINER_NAME=ops-runbook
23+
export AZCOPY_AUTO_LOGIN_TYPE=AZCLI
24+
export AZCOPY_TENANT_ID=531ff96d-0ae9-462a-8d2d-bec7c0b42082
25+
26+
# we use sync here so that deleted files get removed
27+
azcopy sync --compare-hash=md5 \
28+
--delete-destination=true \
29+
--include-pattern="*.html" \
30+
"dist/" "https://$STORAGE_ACCOUNT_NAME.blob.core.windows.net/$CONTAINER_NAME/"
31+
32+
function setTitle() {
33+
local path=$1
34+
35+
TITLE=$(cat ../$path | htmlq 'h1' --text)
36+
37+
echo "Setting title to $TITLE for $path"
38+
39+
az storage blob metadata update --auth-mode login --account-name $STORAGE_ACCOUNT_NAME --container-name $CONTAINER_NAME --name $path --metadata title="$TITLE"
40+
}
41+
42+
export -f setTitle
43+
44+
pushd dist
45+
# another pass over to set the file title as a metadata attribute
46+
find . -name "*.html" -exec bash -c "setTitle \"{}\"" \;
47+
48+
popd

.github/actions/spelling/allow.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,11 @@ sas
793793
FLUSHALL
794794
PDB
795795
PDBs
796+
AZCLI
797+
azcopy
798+
platopslackhelpbotai
799+
popd
800+
pushd
796801
XPOST
797802
sitamp
798803
sitamp01

.github/workflows/deploy.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,22 @@ jobs:
4747
- name: Deploy to GitHub Pages
4848
id: deployment
4949
uses: actions/deploy-pages@v4
50+
51+
# For Azure AI Search used in hmcts/slack-help-bot
52+
- name: Azure login
53+
uses: azure/login@v3
54+
with:
55+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
56+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
57+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
58+
- name: Install dependencies
59+
run: |
60+
./.ci/install-htmlq.sh
61+
./.ci/install-azcopy.sh
62+
- name: Process content
63+
run: |
64+
./.ci/upload.sh
65+
- name: Trigger index
66+
run: |
67+
./.ci/trigger-index.sh
68+
# end of Azure AI Search

0 commit comments

Comments
 (0)