|
21 | 21 | uses: actions/checkout@v4 |
22 | 22 | with: |
23 | 23 | fetch-depth: 0 |
| 24 | + ref: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} |
24 | 25 |
|
25 | 26 | - name: Shallow clone visitor counter logic |
26 | 27 | run: git clone --depth=1 https://github.com/brown9804/github-visitor-counter.git |
@@ -63,24 +64,22 @@ jobs: |
63 | 64 | env: |
64 | 65 | TOKEN: ${{ secrets.GITHUB_TOKEN }} |
65 | 66 | run: | |
66 | | - git fetch origin |
67 | | - git checkout ${{ github.head_ref }} |
68 | | - git pull origin ${{ github.head_ref }} || echo "No merge needed" |
| 67 | + BRANCH="${{ github.head_ref }}" |
| 68 | + git pull origin "$BRANCH" || echo "No merge needed" |
69 | 69 | git add -A |
70 | 70 | git commit -m "Update visitor count" || echo "No changes to commit" |
71 | 71 | git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }} |
72 | | - git push origin HEAD:${{ github.head_ref }} |
| 72 | + git push origin HEAD:"$BRANCH" |
73 | 73 |
|
74 | 74 | # Commit and push logic for non-PR events (merge, not rebase) |
75 | 75 | - name: Commit and push changes (non-PR) |
76 | 76 | if: github.event_name != 'pull_request' |
77 | 77 | env: |
78 | 78 | TOKEN: ${{ secrets.GITHUB_TOKEN }} |
79 | 79 | run: | |
80 | | - git fetch origin |
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" |
| 80 | + BRANCH="${{ github.ref_name }}" |
| 81 | + git pull origin "$BRANCH" || echo "No merge needed" |
83 | 82 | git add -A |
84 | 83 | git commit -m "Update visitor count" || echo "No changes to commit" |
85 | 84 | git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }} |
86 | | - git push origin HEAD:${{ github.ref_name }} |
| 85 | + git push origin HEAD:"$BRANCH" |
0 commit comments