Update Docs #2
This file contains hidden or 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 Docs | |
| on: | |
| schedule: | |
| - cron: "0 3 * * *" | |
| workflow_dispatch: | |
| inputs: | |
| updater: | |
| description: "Which updater to run" | |
| required: false | |
| default: "all" | |
| type: choice | |
| options: | |
| - all | |
| - paper | |
| - bukkit | |
| - minecraft_wiki | |
| - plugins | |
| - index_only | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout updater repo | |
| uses: actions/checkout@v4 | |
| with: | |
| path: minecraft-mcp-scraper | |
| - name: Checkout docs repo | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: Vortex-SMP/minecraft-mcp-docs | |
| path: minecraft-mcp-docs | |
| token: ${{ secrets.DOCS_REPO_TOKEN }} | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| cache: "pip" | |
| cache-dependency-path: minecraft-mcp-scraper/requirements.txt | |
| - name: Install dependencies | |
| working-directory: minecraft-mcp-scraper | |
| run: pip install -r requirements.txt | |
| - name: Run updaters | |
| if: ${{ github.event.inputs.updater != 'index_only' }} | |
| working-directory: minecraft-mcp-scraper | |
| run: | | |
| UPDATER="${{ github.event.inputs.updater || 'all' }}" | |
| if [ "$UPDATER" = "plugins" ]; then | |
| python run_plugins.py | |
| else | |
| python run.py --updater "$UPDATER" --no-index | |
| fi | |
| - name: Run plugin updater (on full run) | |
| if: ${{ github.event.inputs.updater == 'all' || github.event.inputs.updater == '' }} | |
| working-directory: minecraft-mcp-scraper | |
| run: python run_plugins.py | |
| - name: Build SQLite index | |
| working-directory: minecraft-mcp-scraper | |
| run: python run.py --updater index_only | |
| - name: Check for real content changes | |
| id: changes | |
| working-directory: minecraft-mcp-docs | |
| run: | | |
| git add -A | |
| # Detect changes excluding timestamp-only modifications. | |
| # Strategy: check if any tracked file has a diff that changes | |
| # more than just "updated_at", "added_at", "built_at", or "scraped_at" fields. | |
| # Get list of changed files (staged) | |
| CHANGED_FILES=$(git diff --staged --name-only) | |
| if [ -z "$CHANGED_FILES" ]; then | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| echo "No files changed at all." | |
| exit 0 | |
| fi | |
| # For each changed file, check if the diff contains more than timestamp changes. | |
| # We strip lines that only change timestamp values and see if anything remains. | |
| REAL_CHANGES="" | |
| for f in $CHANGED_FILES; do | |
| # index.db is a binary — always count it as a real change only if .md files changed | |
| if [[ "$f" == "index.db" ]]; then | |
| continue | |
| fi | |
| DIFF=$(git diff --staged -- "$f" \ | |
| | grep "^[+-]" \ | |
| | grep -v "^[+-][+-][+-]" \ | |
| | grep -vE '"(updated_at|added_at|built_at|scraped_at)"\s*:' \ | |
| | grep -vE "^[+-]\s*$") | |
| if [ -n "$DIFF" ]; then | |
| REAL_CHANGES="$REAL_CHANGES\n$f" | |
| fi | |
| done | |
| if [ -z "$REAL_CHANGES" ]; then | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| echo "Only timestamp fields changed — no pull request needed." | |
| else | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| # Collect stats for PR body | |
| STATS=$(git diff --staged --stat | tail -1) | |
| echo "stats=$STATS" >> $GITHUB_OUTPUT | |
| SOURCES=$(git diff --staged --name-only \ | |
| | grep -oP 'sources/[^/]+' \ | |
| | sort -u | tr '\n' ', ' | sed 's/,$//') | |
| echo "changed_sources=$SOURCES" >> $GITHUB_OUTPUT | |
| # List changed .md files for PR body (max 30) | |
| MD_LIST=$(echo -e "$REAL_CHANGES" | grep "\.md$" | head -30 | sed 's/^/- /') | |
| # Escape for GitHub output (newlines → literal \n) | |
| MD_LIST_ESC="${MD_LIST//$'\n'/\\n}" | |
| echo "md_list=$MD_LIST_ESC" >> $GITHUB_OUTPUT | |
| echo "Real content changes detected in:$REAL_CHANGES" | |
| fi | |
| - name: Create Pull Request | |
| if: steps.changes.outputs.has_changes == 'true' | |
| working-directory: minecraft-mcp-docs | |
| env: | |
| GH_TOKEN: ${{ secrets.DOCS_REPO_TOKEN }} | |
| run: | | |
| BRANCH="docs/update-$(date -u '+%Y%m%d-%H%M')" | |
| UPDATER="${{ github.event.inputs.updater || 'all' }}" | |
| DATE=$(date -u '+%Y-%m-%d %H:%M UTC') | |
| STATS="${{ steps.changes.outputs.stats }}" | |
| SOURCES="${{ steps.changes.outputs.changed_sources }}" | |
| git config user.name "VortexSMP-bot" | |
| git config user.email "bot@vortex-smp.fr" | |
| git checkout -b "$BRANCH" | |
| git commit -m "docs: update documentation [$DATE]" | |
| git push origin "$BRANCH" | |
| # Determine labels based on changed sources | |
| LABELS="auto-update" | |
| if echo "$SOURCES" | grep -q "paper"; then LABELS="$LABELS,source:paper"; fi | |
| if echo "$SOURCES" | grep -q "bukkit"; then LABELS="$LABELS,source:bukkit"; fi | |
| if echo "$SOURCES" | grep -q "minecraft-wiki"; then LABELS="$LABELS,source:minecraft-wiki"; fi | |
| if echo "$SOURCES" | grep -q "plugins"; then LABELS="$LABELS,source:plugin"; fi | |
| gh pr create \ | |
| --repo Vortex-SMP/minecraft-mcp-docs \ | |
| --title "📚 Documentation update — $DATE" \ | |
| --body "## Automated documentation update | |
| **Triggered by:** \`$UPDATER\` updater | |
| **Date:** $DATE | |
| **Changes:** $STATS | |
| **Updated sources:** $SOURCES | |
| ### Changed files | |
| ${{ steps.changes.outputs.md_list }} | |
| --- | |
| *Automatically opened by [minecraft-mcp-bot](https://github.com/Vortex-SMP/minecraft-mcp-scraper).* | |
| *Review the changes and merge if they look correct.*" \ | |
| --base main \ | |
| --head "$BRANCH" \ | |
| --label "$LABELS" | |
| - name: No real changes | |
| if: steps.changes.outputs.has_changes == 'false' | |
| run: echo "✓ Documentation content is already up to date." | |
| - name: Notify Discord on failure | |
| if: failure() | |
| run: | | |
| # curl -X POST "${{ secrets.DISCORD_WEBHOOK }}" \ | |
| # -H "Content-Type: application/json" \ | |
| # -d "{\"content\":\"⚠️ minecraft-mcp updater failed! ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" | |
| echo "::error::Updater failed." |