Skip to content

Commit 772f00e

Browse files
authored
counter pipeline - testing
1 parent 45c20df commit 772f00e

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
# Commit and push logic for PR events (merge, not rebase)
61+
- name: Commit and push changes (PR)
62+
if: github.event_name == 'pull_request'
63+
env:
64+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
run: |
66+
git fetch origin
67+
git checkout ${{ github.head_ref }}
68+
git pull origin ${{ github.head_ref }} || echo "No merge needed"
69+
git add -A
70+
git commit -m "Update visitor count" || echo "No changes to commit"
71+
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
72+
git push origin HEAD:${{ github.head_ref }}
73+
74+
# Commit and push logic for non-PR events (merge, not rebase)
75+
- name: Commit and push changes (non-PR)
76+
if: github.event_name != 'pull_request'
77+
env:
78+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
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"
83+
git add -A
84+
git commit -m "Update visitor count" || echo "No changes to commit"
85+
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
86+
git push origin HEAD:${{ github.ref_name }}

0 commit comments

Comments
 (0)