Skip to content

Commit c877d28

Browse files
authored
use counter
1 parent 0c95d4a commit c877d28

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Use Visitor Counter Logic
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
schedule:
8+
- cron: '0 0 * * *' # Runs daily at midnight
9+
workflow_dispatch: # Allows manual triggering
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
update-visitor-count:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout current repository
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
ref: ${{ github.head_ref || github.ref_name }}
25+
26+
- name: Shallow clone visitor counter logic
27+
run: git clone --depth=1 https://github.com/brown9804/github-visitor-counter.git
28+
29+
- name: Set up Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: '20'
33+
34+
- name: Install dependencies for github-visitor-counter
35+
run: |
36+
cd github-visitor-counter
37+
npm ci
38+
39+
- name: Run visitor counter logic (updates markdown badges and metrics.json)
40+
run: node github-visitor-counter/update_repo_views_counter.js
41+
env:
42+
TRAFFIC_TOKEN: ${{ secrets.TRAFFIC_TOKEN }}
43+
REPO: ${{ github.repository }}
44+
45+
- name: Move generated metrics.json to root
46+
run: mv github-visitor-counter/metrics.json .
47+
48+
- name: List files for debugging
49+
run: |
50+
ls -l
51+
ls -l github-visitor-counter
52+
53+
- name: Clean up visitor counter logic
54+
run: rm -rf github-visitor-counter
55+
56+
- name: Configure Git author
57+
run: |
58+
git config --global user.name "github-actions[bot]"
59+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
60+
61+
- name: Commit and merge changes
62+
env:
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
68+
run: |
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)