Skip to content

Commit

Permalink
ci: more robust :help indexing workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Oct 30, 2024
1 parent 03ce16f commit 88cc381
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 31 deletions.
54 changes: 32 additions & 22 deletions .github/help-index/create-index.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
#!/usr/bin/env zsh

baseHelpURL="https://neovim.io/doc/user/"
baseRawURL="https://raw.githubusercontent.com/neovim/neovim/master/runtime/doc/"
#───────────────────────────────────────────────────────────────────────────────

mkdir -p "./tmp"
cd "./tmp" || return 1
trap 'rm -rf "./tmp"' EXIT
cd "./tmp" || exit 1

#───────────────────────────────────────────────────────────────────────────────

# DOWNLOAD
curl -sL 'https://api.github.com/repos/neovim/neovim/git/trees/master?recursive=1' |
grep -Eo "runtime/doc/.*.txt" |
# SIC without token, will hit rate limit when running on Github Actions
# (token set via GitHub Actions secrets)
repoTree="https://api.github.com/repos/neovim/neovim/git/trees/master?recursive=1"
baseRawURL="https://raw.githubusercontent.com/neovim/neovim/master/runtime/doc/"
curl "$repoTree" --silent --show-error --header "authorization: Bearer $GITHUB_TOKEN" |
grep --extended-regexp --only-matching "runtime/doc/.*.txt" |
cut -d/ -f3 |
while read -r file; do
curl -sL "$baseRawURL$file" >"./$file"
echo "Downloading $file..."
curl --silent --show-error "$baseRawURL$file" > "./$file"
done

#───────────────────────────────────────────────────────────────────────────────
baseHelpURL="https://neovim.io/doc/user/"

# OPTIONS
vimoptions=$(grep -Eo "\*'[.A-Za-z-]{2,}'\*(.*'.*')?" options.txt |
vimoptions=$(grep --extended-regexp --only-matching "\*'[.A-Za-z-]{2,}'\*(.*'.*')?" options.txt |
tr -d "*'" |
while read -r line; do
opt=$(echo "$line" | cut -d" " -f1)
Expand All @@ -29,9 +34,13 @@ vimoptions=$(grep -Eo "\*'[.A-Za-z-]{2,}'\*(.*'.*')?" options.txt |
fi
echo "${baseHelpURL}options.html#'$opt',$synonyms"
done)
if [[ -z "$vimoptions" ]]; then
echo "Vim options creation failed."
exit 1
fi
# ANCHORS
anchors=$(grep -REo "\*([()_.:A-Za-z-]+|[0-9E]+)\*(.*\*.*\*)?" |
anchors=$(grep --extended-regexp --only-matching --recursive "\*([()_.:A-Za-z-]+|[0-9E]+)\*(.*\*.*\*)?" |
tr -d "*" |
sed 's/txt:/html#/' |
cut -c3- |
Expand All @@ -44,27 +53,28 @@ anchors=$(grep -REo "\*([()_.:A-Za-z-]+|[0-9E]+)\*(.*\*.*\*)?" |
fi
echo "${baseHelpURL}$url,$synonyms"
done)
if [[ -z "$anchors" ]]; then
echo "Anchors creation failed."
exit 1
fi
# SECTIONS
sections=$(grep -Eo "\|[.0-9]*\|.*" usr_toc.txt |
sections=$(grep --extended-regexp --only-matching "\|[.0-9]*\|.*" usr_toc.txt |
tr -d "|" |
while read -r line; do
file=$(echo "$line" | cut -c-2)
title="$line"
echo "${baseHelpURL}usr_$file.html#$title"
done)
#───────────────────────────────────────────────────────────────────────────────
# VALIDATE that the index was actually created
if [[ -z "$vimoptions" ]] || [[ -z "$anchors" ]] || [[ -z "$sections" ]]; then
echo "Attempt failed."
if [[ -z "$sections" ]]; then
echo "Section creation failed."
exit 1
fi
cd .. || exit 1
echo "$vimoptions" > ./.github/help-index/neovim-help-index-urls.txt
echo "$anchors" >> ./.github/help-index/neovim-help-index-urls.txt
echo "$sections" >> ./.github/help-index/neovim-help-index-urls.txt
#───────────────────────────────────────────────────────────────────────────────
rm -rf "./tmp"
cd .. || exit 1
output=.github/help-index/neovim-help-index-urls.txt
echo "$vimoptions" > "$output"
echo "$anchors" >> "$output"
echo "$sections" >> "$output"
21 changes: 12 additions & 9 deletions .github/workflows/update-help-index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ on:
schedule:
- cron: "35 4 2,15 * *"

# allow triggering manually
# triggering manually
workflow_dispatch: {}

# when this file or the script for re-indexing is changed
push:
paths:
- .github/workflows/update-help-index.yml
- .github/help-index/create-index.sh

permissions:
contents: write

Expand All @@ -19,14 +25,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Update :help Search Index
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication
run: |
for i in {1..5}; do
echo "Attempt #$i"
zsh ./.github/help-index/create-index.sh && exit 0
sleep 30
done
echo "Multiple attempts to update the index failed. Aborting."
exit 1
zsh ./.github/help-index/create-index.sh
exit $? # inherit exit code
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore: Updated :help index"
commit_message: "chore: Updated `:help` index"

0 comments on commit 88cc381

Please sign in to comment.