Merge pull request #55 from IamBisrutPyne/IamBisrutPyne-factorial-swift #79
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 snippets index | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| types: [closed] | |
| # Allows manual triggering | |
| workflow_dispatch: | |
| # allow pushes | |
| permissions: | |
| contents: write | |
| jobs: | |
| generate-index: | |
| # Run on pushes or when a PR is merged — but skip runs triggered by the bot itself | |
| if: > | |
| (github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)) | |
| && github.actor != 'github-actions[bot]' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository (full history & credentials) | |
| uses: actions/checkout@v4 | |
| with: | |
| # Fetch depth 0 is crucial for proper rebase/merge history | |
| fetch-depth: 0 | |
| persist-credentials: true | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.x' | |
| - name: Install requirements (if needed) | |
| run: | | |
| python -m pip install --upgrade pip | |
| # Install any minimal deps needed by tools/generate_index.py | |
| pip install PyGithub || true | |
| - name: Generate index | |
| run: python tools/generate_index.py | |
| - name: Commit and push index (Safe Rebase Strategy) | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -e | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Only track the generated index file | |
| git add snippets/README.md | |
| # If nothing staged -> nothing to do | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit" | |
| exit 0 | |
| fi | |
| git commit -m "chore: update snippets index" | |
| # --- SAFE PUSH STRATEGY --- | |
| # 1. Pull remote changes and reapply the local commit on top (rebase). | |
| # This is the simplest way to avoid non-fast-forward push rejections. | |
| echo "Syncing with remote main before push..." | |
| git pull origin main --rebase | |
| # 2. Push the result back to main. | |
| git push origin main |