@@ -57,38 +57,30 @@ jobs:
5757 git config --global user.name "github-actions[bot]"
5858 git config --global user.email "github-actions[bot]@users.noreply.github.com"
5959
60+ # Commit and push logic for PR events (merge, not rebase)
6061 - name : Commit and push changes (PR)
6162 if : github.event_name == 'pull_request'
6263 env :
6364 TOKEN : ${{ secrets.GITHUB_TOKEN }}
6465 run : |
6566 git fetch origin
66- git checkout -b ${{ github.event.pull_request.head.ref }} origin/${{ github.event.pull_request.head.ref }}
67- git add "*.md" metrics.json
67+ git checkout ${{ github.head_ref }}
68+ git pull origin ${{ github.head_ref }} || echo "No merge needed"
69+ git add -A
6870 git commit -m "Update visitor count" || echo "No changes to commit"
6971 git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
70- git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed"
71- git push origin HEAD:${{ github.event.pull_request.head.ref }}
72+ git push origin HEAD:${{ github.head_ref }}
7273
74+ # Commit and push logic for non-PR events (merge, not rebase)
7375 - name : Commit and push changes (non-PR)
7476 if : github.event_name != 'pull_request'
7577 env :
7678 TOKEN : ${{ secrets.GITHUB_TOKEN }}
7779 run : |
7880 git fetch origin
79- git checkout ${{ github.event.pull_request.head.ref }} || git checkout -b ${{ github.event.pull_request.head.ref }} origin/${{ github.event.pull_request.head.ref }}
80- git add "*.md" metrics.json
81+ git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} origin/${{ github.ref_name }}
82+ git pull origin ${{ github.ref_name }} || echo "No merge needed"
83+ git add -A
8184 git commit -m "Update visitor count" || echo "No changes to commit"
8285 git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
83- git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed"
84- git push origin HEAD:${{ github.event.pull_request.head.ref }}
85-
86- - name : Create Pull Request (non-PR)
87- if : github.event_name != 'pull_request'
88- uses : peter-evans/create-pull-request@v6
89- with :
90- token : ${{ secrets.GITHUB_TOKEN }}
91- branch : update-visitor-count
92- title : " Update visitor count"
93- body : " Automated update of visitor count"
94- base : main
86+ git push origin HEAD:${{ github.ref_name }}
0 commit comments