15
15
steps :
16
16
- name : Check out the repository
17
17
uses : actions/checkout@v4
18
+ with :
19
+ fetch-depth : 0 # Fetch full history to support rebasing
18
20
19
21
- name : Set up SSH for Git (deploy key)
20
22
run : |
@@ -33,22 +35,42 @@ jobs:
33
35
python3 -m pip install --upgrade pip
34
36
pip install -r requirements.txt
35
37
36
- - name : Fetch GitHub data
38
+ - name : Generate Merged Data
37
39
run : |
38
40
python3 gh-data.py
39
-
40
- - name : Merge data sources
41
- run : |
42
41
python3 merge-data.py
43
42
44
- - name : Commit and Push Changes to `gh-pages`
43
+ - name : Switch to `gh-pages` and Preserve Changes
45
44
run : |
46
45
git config --global user.name "github-actions[bot]"
47
46
git config --global user.email "github-actions[bot]@users.noreply.github.com"
48
- git checkout -b gh-pages
47
+
48
+ # Stash changes to preserve them
49
+ git stash --include-untracked
50
+
51
+ # Fetch and switch to `gh-pages`
52
+ git fetch origin gh-pages:gh-pages || git checkout --orphan gh-pages
53
+ git checkout gh-pages
54
+
55
+ # Rebase `gh-pages` onto `main` to ensure a linear history
56
+ git rebase main
57
+
58
+ # Apply stashed changes
59
+ git stash pop || echo "No changes to apply."
60
+
61
+ - name : Commit and Push Updates
62
+ run : |
63
+ # Add changes
49
64
git add -f merged-data.json
50
65
git add .
51
- # If there are no changes, no commit gets created, and nothing is pushed
52
- git commit -m "Update GitHub Pages with latest data"
66
+
67
+ # Commit changes if there are any
68
+ if git diff --cached --quiet; then
69
+ echo "No changes to commit."
70
+ else
71
+ git commit -m "Update GitHub Pages with latest data"
72
+ fi
73
+
74
+ # Push changes back to `gh-pages`
53
75
git remote set-url origin [email protected] :${{ github.repository }}.git
54
76
git push origin gh-pages
0 commit comments