Game Index - Rebuild Indexes #95
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: Game Index - Rebuild Indexes | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| rebuild_all: | |
| description: 'Rebuild all game indexes' | |
| required: false | |
| type: boolean | |
| default: false | |
| push: | |
| branches: [gui-changes] | |
| paths: | |
| - 'game_index/**' | |
| - 'tools/game_indexing/**' | |
| # Trigger when new worlds are added (after CI workflow completes) | |
| workflow_run: | |
| workflows: ["CI - Build and Test"] | |
| types: [completed] | |
| branches: [gui-changes] | |
| env: | |
| PYTHON_VERSION: '3.12' | |
| jobs: | |
| rebuild-game-indexes: | |
| name: Rebuild Game Indexes | |
| runs-on: ubuntu-latest | |
| continue-on-error: true | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| path: src | |
| fetch-depth: 2 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| cache: 'pip' | |
| - name: Create virtual environment | |
| run: | | |
| python -m venv venv | |
| source venv/bin/activate | |
| pip install --upgrade pip | |
| - name: Install game indexing dependencies | |
| run: | | |
| source venv/bin/activate | |
| pip install -r src/tools/game_indexing/requirements.txt | |
| - name: Detect changed game indexes | |
| id: detect_changed | |
| if: github.event_name != 'workflow_dispatch' || !inputs.rebuild_all | |
| run: | | |
| cd src | |
| # Check if this was triggered by new worlds | |
| if [ "${{ github.event_name }}" == "workflow_run" ]; then | |
| echo "Triggered by workflow_run - rebuilding all indexes" | |
| echo "rebuild_all=true" >> $GITHUB_OUTPUT | |
| else | |
| # Get changed files | |
| CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD | grep -E '(game_index/|tools/game_indexing/)' || true) | |
| if [ -n "$CHANGED_FILES" ]; then | |
| echo "Game index related files changed" | |
| echo "rebuild_all=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No game index changes detected" | |
| echo "rebuild_all=false" >> $GITHUB_OUTPUT | |
| fi | |
| fi | |
| - name: Find game index modules | |
| id: find_modules | |
| if: steps.detect_changed.outputs.rebuild_all == 'true' || inputs.rebuild_all | |
| run: | | |
| cd src | |
| # Find all directories in game_index with pyproject.toml | |
| MODULES=$(find game_index -mindepth 1 -maxdepth 1 -type d -exec test -e '{}/pyproject.toml' \; -print | xargs -n1 basename | tr '\n' ' ') | |
| echo "modules=$MODULES" >> $GITHUB_OUTPUT | |
| echo "Found game index modules: $MODULES" | |
| - name: Build game index wheels | |
| if: steps.find_modules.outputs.modules != '' | |
| run: | | |
| source venv/bin/activate | |
| pip install build toml | |
| cd src | |
| for module in ${{ steps.find_modules.outputs.modules }}; do | |
| echo "Building game index module: $module" | |
| cd "game_index/$module" | |
| python -m build | |
| cd ../.. | |
| done | |
| - name: Publish to PyPI | |
| if: steps.find_modules.outputs.modules != '' | |
| env: | |
| TWINE_USERNAME: ${{ vars.PYPI_USERNAME }} | |
| TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | |
| TWINE_REPOSITORY_URL: ${{ vars.PYPI_URL }} | |
| run: | | |
| source venv/bin/activate | |
| pip install twine | |
| cd src | |
| for module in ${{ steps.find_modules.outputs.modules }}; do | |
| echo "Publishing game index module: $module" | |
| python -m twine upload "game_index/$module/dist/"*.whl --verbose || echo "Failed to upload $module, continuing..." | |
| done | |