Update Search Database #197
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Search Database | |
on: | |
schedule: | |
- cron: '0 4 * * *' # Run daily at 4:00 UTC | |
workflow_dispatch: # Allow manual trigger | |
push: | |
branches: [ main ] | |
paths: | |
- '**/*.md' | |
- '**/*.html' | |
- 'scripts/generate_search_db.rb' | |
- 'scripts/fetch_github_blog_content.js' | |
- 'scripts/package.json' | |
# Add permissions needed for the workflow | |
permissions: | |
contents: write # This allows the action to commit and push changes | |
packages: read # This allows the action to read from npm | |
jobs: | |
update-search: | |
runs-on: ubuntu-latest | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NPM_CONFIG_CACHE: ${{ github.workspace }}/.npm | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch all history for proper git operations | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: '3.2' | |
bundler-cache: true | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'npm' | |
cache-dependency-path: 'scripts/package.json' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Install Ruby dependencies | |
run: | | |
gem install bundler | |
bundle config path vendor/bundle | |
bundle install | |
gem install nokogiri | |
- name: Install Node.js dependencies | |
run: | | |
cd scripts | |
npm install | |
- name: Fetch blog content from GitHub repository | |
run: | | |
cd scripts | |
node fetch_github_blog_content.js | |
- name: Generate search database | |
run: ruby scripts/generate_search_db.rb | |
- name: Commit and push if changed | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add assets/js/search_db.json | |
git diff --quiet && git diff --staged --quiet || (git commit -m "Update search database" && git push) |