66 - main
77 schedule :
88 - cron : ' 0 0 * * *' # Runs daily at midnight
9- workflow_dispatch : # Allows manual triggering
9+ workflow_dispatch : # Allows manual triggering
1010
1111permissions :
1212 contents : write
1313 pull-requests : write
1414
1515jobs :
16- use-counter-logic :
16+ update-visitor-count :
1717 runs-on : ubuntu-latest
1818
1919 steps :
@@ -22,61 +22,62 @@ jobs:
2222 with :
2323 fetch-depth : 0
2424
25- - name : Clone github- visitor- counter repository temporarily
26- run : git clone https://github.com/brown9804/github-visitor-counter.git
25+ - name : Shallow clone visitor counter logic
26+ run : git clone --depth=1 https://github.com/brown9804/github-visitor-counter.git
2727
2828 - name : Set up Node.js
29- uses : actions/setup-node@v3
29+ uses : actions/setup-node@v4
3030 with :
3131 node-version : ' 20'
3232
3333 - name : Install dependencies for github-visitor-counter
3434 run : |
3535 cd github-visitor-counter
36- npm install
36+ npm ci
3737
38- - name : Run visitor counter logic
39- run : |
40- cd github-visitor-counter
41- node update_repo_views_counter.js
38+ - name : Run visitor counter logic (updates markdown badges and metrics.json)
39+ run : node github-visitor-counter/update_repo_views_counter.js
4240 env :
4341 TRAFFIC_TOKEN : ${{ secrets.TRAFFIC_TOKEN }}
4442 REPO : ${{ github.repository }}
4543
46- - name : Move generated files to current repository
44+ - name : Move generated metrics.json to root
45+ run : mv github-visitor-counter/metrics.json .
46+
47+ - name : List files for debugging
4748 run : |
48- mv github-visitor-counter/metrics.json .
49- mv github-visitor-counter/README.md .
49+ ls -l
50+ ls -l github-visitor-counter
5051
51- - name : Clean up temporary files
52+ - name : Clean up visitor counter logic
5253 run : rm -rf github-visitor-counter
5354
54- - name : Configure Git
55+ - name : Configure Git author
5556 run : |
5657 git config --global user.name "github-actions[bot]"
5758 git config --global user.email "github-actions[bot]@users.noreply.github.com"
5859
59- - name : Commit and push to PR branch
60+ - name : Commit and push changes (PR)
6061 if : github.event_name == 'pull_request'
6162 env :
6263 TOKEN : ${{ secrets.GITHUB_TOKEN }}
6364 run : |
6465 git fetch origin
6566 git checkout -b ${{ github.event.pull_request.head.ref }} origin/${{ github.event.pull_request.head.ref }}
66- git add README .md metrics.json
67+ git add "* .md" metrics.json
6768 git commit -m "Update visitor count" || echo "No changes to commit"
6869 git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
6970 git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed"
7071 git push origin HEAD:${{ github.event.pull_request.head.ref }}
7172
72- - name : Commit and push to new branch (non-PR)
73+ - name : Commit and push changes (non-PR)
7374 if : github.event_name != 'pull_request'
7475 env :
7576 TOKEN : ${{ secrets.GITHUB_TOKEN }}
7677 run : |
7778 git fetch origin
7879 git checkout ${{ github.event.pull_request.head.ref }} || git checkout -b ${{ github.event.pull_request.head.ref }} origin/${{ github.event.pull_request.head.ref }}
79- git add README .md metrics.json
80+ git add "* .md" metrics.json
8081 git commit -m "Update visitor count" || echo "No changes to commit"
8182 git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
8283 git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed"
0 commit comments