6868 run : |
6969 git config user.name "github-actions[bot]"
7070 git config user.email "github-actions[bot]@users.noreply.github.com"
71- git add docs/usage-metrics.csv
7271
73- if git diff --staged --quiet; then
72+ # Check for changes without staging (avoids conflicts on branch checkout)
73+ if git diff --quiet docs/usage-metrics.csv; then
7474 echo "No changes to commit"
7575 exit 0
7676 fi
@@ -79,27 +79,30 @@ jobs:
7979 MONTH=$(date +%Y-%m)
8080 BRANCH_NAME="chore/update-usage-metrics-$MONTH"
8181
82+ # Preserve the newly collected metrics before any branch switching
83+ cp docs/usage-metrics.csv /tmp/usage-metrics.csv
84+
8285 # Check if the branch already exists on the remote
8386 if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then
8487 echo "Branch $BRANCH_NAME already exists, pushing new commit to it"
85- # Preserve the newly collected metrics before switching branches
86- cp docs/usage-metrics.csv /tmp /usage-metrics.csv
88+ # Reset the working tree so checkout succeeds
89+ git checkout -- docs /usage-metrics.csv
8790 git fetch origin "$BRANCH_NAME"
8891 git checkout "$BRANCH_NAME"
89- # Restore the newly collected metrics on top of the existing branch
90- cp /tmp/usage-metrics.csv docs/usage-metrics.csv
91- git add docs/usage-metrics.csv
92- # Check again after checkout — the diff might be empty if the
93- # branch already has identical data
94- if git diff --staged --quiet; then
95- echo "No changes to commit after checking out existing branch"
96- exit 0
97- fi
9892 else
9993 echo "Creating new branch $BRANCH_NAME"
10094 git checkout -b "$BRANCH_NAME"
10195 fi
10296
97+ # Restore the newly collected metrics and stage them
98+ cp /tmp/usage-metrics.csv docs/usage-metrics.csv
99+ git add docs/usage-metrics.csv
100+
101+ if git diff --staged --quiet; then
102+ echo "No changes to commit (branch already has identical data)"
103+ exit 0
104+ fi
105+
103106 git commit -m "chore(metrics): update usage metrics ($DATE)"
104107 git push -u origin "$BRANCH_NAME"
105108
0 commit comments