-
Notifications
You must be signed in to change notification settings - Fork 10
70 lines (58 loc) · 2.11 KB
/
update-index.yml
File metadata and controls
70 lines (58 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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