Skip to content

Commit 23f1644

Browse files
authored
Merge pull request #9 from MicrosoftCloudEssentials-LearningHub/upgrade-pipelines-counter-logic
Upgrade pipelines counter logic
2 parents 079c70a + 1645201 commit 23f1644

File tree

6 files changed

+157
-13
lines changed

6 files changed

+157
-13
lines changed

.github/workflows/update-md-date.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ on:
77

88
permissions:
99
contents: write
10+
pull-requests: write
1011

1112
jobs:
1213
update-date:
1314
runs-on: ubuntu-latest
1415

1516
steps:
16-
- name: Checkout repository
17+
- name: Checkout PR branch
1718
uses: actions/checkout@v4
1819
with:
1920
fetch-depth: 0
21+
ref: ${{ github.event.pull_request.head.ref }}
2022

2123
- name: Set up Python
2224
uses: actions/setup-python@v4
@@ -34,8 +36,13 @@ jobs:
3436
- name: Update last modified date in Markdown files
3537
run: python .github/workflows/update_date.py
3638

37-
- name: Commit changes
39+
- name: Pull (merge) remote changes, commit, and push if needed
40+
env:
41+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
3842
run: |
43+
BRANCH="${{ github.event.pull_request.head.ref }}"
44+
git pull origin "$BRANCH" || echo "No merge needed"
3945
git add -A
4046
git commit -m "Update last modified date in Markdown files" || echo "No changes to commit"
41-
git push origin HEAD:${{ github.event.pull_request.head.ref }}
47+
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
48+
git push origin HEAD:"$BRANCH"
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

.github/workflows/validate_and_fix_markdown.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77

88
permissions:
99
contents: write
10+
pull-requests: write
1011

1112
jobs:
1213
validate-and-fix-markdown:
@@ -34,11 +35,11 @@ jobs:
3435
git config --global user.email "github-actions[bot]@users.noreply.github.com"
3536
git config --global user.name "github-actions[bot]"
3637
37-
- name: Commit changes
38+
- name: Commit and rebase changes
39+
env:
40+
PR_BRANCH: ${{ github.head_ref || github.ref_name }}
3841
run: |
39-
git fetch origin
40-
git checkout -b ${{ github.event.pull_request.head.ref }} origin/${{ github.event.pull_request.head.ref }}
4142
git add -A
4243
git commit -m "Fix Markdown syntax issues" || echo "No changes to commit"
43-
git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed"
44-
git push origin HEAD:${{ github.event.pull_request.head.ref }}
44+
git pull --rebase origin "$PR_BRANCH" || echo "No rebase needed"
45+
git push origin HEAD:"$PR_BRANCH"

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Costa Rica
88
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
99
[brown9804](https://github.com/brown9804)
1010

11-
Last updated: 2025-06-03
11+
Last updated: 2025-07-17
1212

1313
----------
1414

@@ -158,6 +158,7 @@ Last updated: 2025-06-03
158158
> In the context of Azure Function Apps, a `hosting option refers to the plan you choose to run your function app`. This choice affects how your function app is scaled, the resources available to each function app instance, and the support for advanced functionalities like virtual network connectivity and container support.
159159
160160
> [!TIP]
161+
>
161162
> - `Scale to Zero`: Indicates whether the service can automatically scale down to zero instances when idle.
162163
> - **IDLE** stands for:
163164
> - **I** – Inactive
@@ -954,7 +955,9 @@ If you need further assistance with the code, please click [here to view all the
954955
955956
<img width="550" alt="image" src="https://github.com/user-attachments/assets/27309a6d-c654-4c76-bbc1-990a9338973c">
956957
958+
<!-- START BADGE -->
957959
<div align="center">
958-
<h3 style="color: #4CAF50;">Total Visitors</h3>
959-
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
960+
<img src="https://img.shields.io/badge/Total%20views-14-limegreen" alt="Total views">
961+
<p>Refresh Date: 2025-07-17</p>
960962
</div>
963+
<!-- END BADGE -->

metrics.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[
2+
{
3+
"date": "2025-07-07",
4+
"count": 330,
5+
"uniques": 20
6+
},
7+
{
8+
"date": "2025-07-08",
9+
"count": 159,
10+
"uniques": 6
11+
},
12+
{
13+
"date": "2025-07-10",
14+
"count": 482,
15+
"uniques": 1
16+
},
17+
{
18+
"date": "2025-07-11",
19+
"count": 170,
20+
"uniques": 4
21+
},
22+
{
23+
"date": "2025-07-12",
24+
"count": 7,
25+
"uniques": 1
26+
},
27+
{
28+
"date": "2025-07-14",
29+
"count": 130,
30+
"uniques": 2
31+
},
32+
{
33+
"date": "2025-07-15",
34+
"count": 2,
35+
"uniques": 1
36+
}
37+
]

terraform-infrastructure/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ graph TD;
107107

108108
<img width="550" alt="image" src="https://github.com/user-attachments/assets/f2089d03-3a3d-431d-b462-8148ef519104">
109109

110+
<!-- START BADGE -->
110111
<div align="center">
111-
<h3 style="color: #4CAF50;">Total Visitors</h3>
112-
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
112+
<img src="https://img.shields.io/badge/Total%20views-14-limegreen" alt="Total views">
113+
<p>Refresh Date: 2025-07-17</p>
113114
</div>
115+
<!-- END BADGE -->

0 commit comments

Comments
 (0)