Skip to content

Commit 5de109e

Browse files
authored
simplifying logic
1 parent 9c91423 commit 5de109e

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

.github/workflows/use-visitor-counter.yml

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
uses: actions/checkout@v4
2222
with:
2323
fetch-depth: 0
24+
ref: ${{ github.head_ref || github.ref_name }}
2425

2526
- name: Shallow clone visitor counter logic
2627
run: git clone --depth=1 https://github.com/brown9804/github-visitor-counter.git
@@ -57,38 +58,23 @@ jobs:
5758
git config --global user.name "github-actions[bot]"
5859
git config --global user.email "github-actions[bot]@users.noreply.github.com"
5960
60-
- name: Commit and push changes (PR)
61-
if: github.event_name == 'pull_request'
61+
- name: Commit and merge changes
6262
env:
63-
TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
PR_BRANCH: ${{ github.head_ref || github.ref_name }}
64+
GIT_AUTHOR_NAME: github-actions[bot]
65+
GIT_AUTHOR_EMAIL: github-actions[bot]@users.noreply.github.com
66+
GIT_COMMITTER_NAME: github-actions[bot]
67+
GIT_COMMITTER_EMAIL: github-actions[bot]@users.noreply.github.com
6468
run: |
65-
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
68-
git commit -m "Update visitor count" || echo "No changes to commit"
69-
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-
73-
- name: Commit and push changes (non-PR)
74-
if: github.event_name != 'pull_request'
75-
env:
76-
TOKEN: ${{ secrets.GITHUB_TOKEN }}
77-
run: |
78-
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 commit -m "Update visitor count" || echo "No changes to commit"
82-
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
69+
# Ensure we're on the correct branch
70+
git switch -c "$PR_BRANCH" || git switch "$PR_BRANCH"
71+
72+
# Stage and commit changes if any
73+
git add -A
74+
git diff --staged --quiet || git commit -m "Update visitor count"
75+
76+
# Pull and merge existing changes
77+
git pull origin "$PR_BRANCH" --no-rebase
78+
79+
# Push all changes
80+
git push origin "$PR_BRANCH"

0 commit comments

Comments
 (0)