Skip to content

Commit 67bebef

Browse files
authored
+ counter pipeline
1 parent 6dc9022 commit 67bebef

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
25+
- name: Shallow clone visitor counter logic
26+
run: git clone --depth=1 https://github.com/brown9804/github-visitor-counter.git
27+
28+
- name: Set up Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: '20'
32+
33+
- name: Install dependencies for github-visitor-counter
34+
run: |
35+
cd github-visitor-counter
36+
npm ci
37+
38+
- name: Run visitor counter logic (updates markdown badges and metrics.json)
39+
run: node github-visitor-counter/update_repo_views_counter.js
40+
env:
41+
TRAFFIC_TOKEN: ${{ secrets.TRAFFIC_TOKEN }}
42+
REPO: ${{ github.repository }}
43+
44+
- name: Move generated metrics.json to root
45+
run: mv github-visitor-counter/metrics.json .
46+
47+
- name: List files for debugging
48+
run: |
49+
ls -l
50+
ls -l github-visitor-counter
51+
52+
- name: Clean up visitor counter logic
53+
run: rm -rf github-visitor-counter
54+
55+
- name: Configure Git author
56+
run: |
57+
git config --global user.name "github-actions[bot]"
58+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
59+
60+
- name: Commit and push changes (PR)
61+
if: github.event_name == 'pull_request'
62+
env:
63+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
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

0 commit comments

Comments
 (0)