Skip to content

Commit 0dfb50e

Browse files
authored
Merge pull request #19 from brown9804/changing-visit-counts
adding badge - changing counter
2 parents f0be17d + dec35e2 commit 0dfb50e

10 files changed

Lines changed: 735 additions & 272 deletions

File tree

.github/workflows/md-html-deploy.yml

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
branches:
66
- main
7+
78
# push:
89
# branches:
910
# - main # Trigger the workflow on push to the main branch
@@ -19,21 +20,30 @@ jobs:
1920
- name: Checkout repository
2021
uses: actions/checkout@v2
2122

22-
# Step 2: Set up Node.js environment
23+
# Step 2: Check for lock file
24+
- name: Check for lock file
25+
run: |
26+
if [ -f .lock ]; then
27+
echo "Another workflow is running. Exiting."
28+
exit 1
29+
fi
30+
touch .lock
31+
32+
# Step 3: Set up Node.js environment
2333
- name: Set up Node.js
2434
uses: actions/setup-node@v2
2535
with:
2636
node-version: '14' # Specify the Node.js version
2737

28-
# Step 3: Install npm dependencies
38+
# Step 4: Install npm dependencies
2939
- name: Install dependencies
3040
run: npm install
3141

32-
# Step 4: Install pandoc for Markdown to HTML conversion
42+
# Step 5: Install pandoc for Markdown to HTML conversion
3343
- name: Install pandoc
3444
run: sudo apt-get install -y pandoc
3545

36-
# Step 5: Convert all Markdown files to HTML while preserving directory structure
46+
# Step 6: Convert all Markdown files to HTML while preserving directory structure
3747
- name: Convert Markdown to HTML
3848
run: |
3949
mkdir -p _site # Create the _site directory if it doesn't exist
@@ -45,29 +55,27 @@ jobs:
4555
pandoc "$file" --standalone --toc -o "_site/${file%.md}.html"
4656
done
4757
48-
# Step 6: Deploy the generated HTML files to GitHub Pages
58+
# Step 7: Deploy the generated HTML files to GitHub Pages
4959
- name: Deploy to GitHub Pages
60+
env:
61+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
5062
run: |
5163
# Configure Git with a bot email and name
5264
git config --global user.email "github-actions[bot]@users.noreply.github.com"
5365
git config --global user.name "github-actions[bot]"
54-
# Check for local changes and stash them if present
55-
if [ -n "$(git status --porcelain)" ]; then
56-
git stash
57-
git pull origin ${{ github.ref }} --rebase
58-
git stash pop || true # Ignore error if no stash entries to pop
59-
else
60-
git pull origin ${{ github.ref }} --rebase
61-
fi
62-
# Add all changes, including untracked files
66+
# Ensure all changes are staged
6367
git add -A
64-
# Check for changes before committing
68+
# Commit changes if there are any
6569
if git diff-index --quiet HEAD --; then
6670
echo "No changes to commit"
67-
exit 0
6871
else
69-
# Commit the changes
7072
git commit -m 'Deploy static HTML files'
71-
# Push the changes to the remote branch
72-
git push origin HEAD:${{ github.ref }}
7373
fi
74+
# Push changes to the pull request branch
75+
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
76+
git push origin HEAD:${{ github.event.pull_request.head.ref }} || echo "Push failed due to conflicts"
77+
78+
# Step 8: Remove lock file
79+
- name: Remove lock file
80+
if: always()
81+
run: rm -f .lock

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Install dependencies
2424
run: pip install python-dateutil
2525

26-
- name: Configure Git
26+
- name: Configure Git
2727
run: |
2828
git config --global user.email "belindabrownr04@gmail.com"
2929
git config --global user.name "brown9804"
@@ -32,7 +32,12 @@ jobs:
3232
run: python .github/workflows/update_date.py
3333

3434
- name: Commit changes
35+
env:
36+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
3537
run: |
38+
git fetch origin
39+
git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed"
3640
git add -A
3741
git commit -m "Update last modified date in Markdown files" || echo "No changes to commit"
42+
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
3843
git push origin HEAD:${{ github.event.pull_request.head.ref }}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
use-counter-logic:
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: Clone github-visitor-counter repository temporarily
26+
run: git clone https://github.com/brown9804/github-visitor-counter.git
27+
28+
- name: Set up Node.js
29+
uses: actions/setup-node@v3
30+
with:
31+
node-version: '20'
32+
33+
- name: Install dependencies for github-visitor-counter
34+
run: |
35+
cd github-visitor-counter
36+
npm install
37+
38+
- name: Run visitor counter logic
39+
run: |
40+
cd github-visitor-counter
41+
node update_repo_views_counter.js
42+
env:
43+
TRAFFIC_TOKEN: ${{ secrets.TRAFFIC_TOKEN }}
44+
REPO: ${{ github.repository }}
45+
46+
- name: Move generated files to current repository
47+
run: |
48+
mv github-visitor-counter/metrics.json .
49+
mv github-visitor-counter/README.md .
50+
51+
- name: Clean up temporary files
52+
run: rm -rf github-visitor-counter
53+
54+
- name: Configure Git
55+
run: |
56+
git config --global user.name "github-actions[bot]"
57+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
58+
59+
- name: Commit and push to PR branch
60+
if: github.event_name == 'pull_request'
61+
env:
62+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
run: |
64+
git fetch origin
65+
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 commit -m "Update visitor count" || echo "No changes to commit"
68+
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
69+
git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed"
70+
git push origin HEAD:${{ github.event.pull_request.head.ref }}
71+
72+
- name: Commit and push to new branch (non-PR)
73+
if: github.event_name != 'pull_request'
74+
env:
75+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
run: |
77+
git fetch origin
78+
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 commit -m "Update visitor count" || echo "No changes to commit"
81+
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
82+
git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed"
83+
git push origin HEAD:${{ github.event.pull_request.head.ref }}
84+
85+
- name: Create Pull Request (non-PR)
86+
if: github.event_name != 'pull_request'
87+
uses: peter-evans/create-pull-request@v6
88+
with:
89+
token: ${{ secrets.GITHUB_TOKEN }}
90+
branch: update-visitor-count
91+
title: "Update visitor count"
92+
body: "Automated update of visitor count"
93+
base: main

README.md

Lines changed: 88 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,99 @@
1-
# Cloud DevOps: <br> Learning Path - Overview
1+
# Open Source Visitor Counter
22

33
Costa Rica
44

5+
[![GitHub](https://badgen.net/badge/icon/github?icon=github&label)](https://github.com)
56
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
67
[brown9804](https://github.com/brown9804)
78

8-
Last updated: 2024-12-13
9+
Last updated: 2025-07-10
910

1011
----------
1112

12-
> Provides the essential knowledge required to work effectively within Azure and embrace DevOps/Agile methodologies. Additionally, it offers insights into fundamental cloud concepts.
13-
14-
<details>
15-
<summary><b>Table of Contents</b> (Click to expand)</summary>
16-
17-
- [Agile](https://github.com/brown9804/SDLC-Cloud_Lpath/tree/main/Agile)
18-
- [DevOps](https://github.com/brown9804/SDLC-Cloud_Lpath/tree/main/DevOps)
19-
- [Network](https://github.com/brown9804/SDLC-Cloud_Lpath/tree/main/Network)
20-
- [GitHub](https://github.com/brown9804/CloudDevOps_LPath/tree/main/GitHub)
21-
- [Cloud Principles](https://github.com/brown9804/SDLC-Cloud_Lpath/tree/main/Cloud)
22-
- [0. Linux](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/0-linux)
23-
- [Working with Users and Permissions](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/0-linux/lab0)
24-
- [System Service Management, Runlevels and Boot Targets](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/0-linux/lab1)
25-
- [Securely Accessing Your System](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/0-linux/lab2)
26-
- [Package Management and Troubleshooting](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/0-linux/lab3)
27-
- [File Management, Permissions and Backup](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/0-linux/lab4)
28-
- [Working with Text Files and Streams](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/0-linux/lab5)
29-
- [Linux Device Management](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/0-linux/lab6)
30-
- [The Linux Shell](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/0-linux/lab7)
31-
- [Networking](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/0-linux/lab8)
32-
- [Processes Management](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/0-linux/lab9)
33-
- [1. Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform)
34-
- [Installing Terraform and Working with Terraform Providers](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab0)
35-
- [Using Terraform CLI Commands (workspace and state) to Manipulate a Terraform Deployment](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab1)
36-
- [Building and Testing a Basic Terraform Module](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab2)
37-
- [Exploring Terraform State Functionality](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab3)
38-
- [Deploy an Azure Storage Account with Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab4)
39-
- [Deploy an Azure File Share and Blob Storage with Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab5)
40-
- [Deploy Azure VNETs and Subnets with Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab6)
41-
- [Create Azure NSGs with Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab7)
42-
- [Deploying an Azure VM with Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab8)
43-
- [Deploy a Web Application with Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab9)
44-
- [Deploy a MySQL Database with Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab_10)
45-
- [Migrating Terraform State to Terraform Cloud](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab_11)
46-
- [Using Terraform Provisioners to Set Up an Apache Web Server on AWS](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab_12)
47-
- [Make Changes to AWS Infrastructure Using Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab_13)
48-
- [Use Output Variables to Query Data in AWS Using Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab_14)
49-
- [Make Changes to Azure Infrastructure Using Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab_15)
50-
- [Use Output Variables to Query Data in Azure Using Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab_16)
51-
- [Use Terraform to Create a Kubernetes Deployment](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab_17)
52-
- [Manage Kubernetes Resources with Terraform](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab_18)
53-
- [Use Terraform to Create an EKS Deployment](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab_19)
54-
- [Troubleshooting a Terraform Deployment](https://github.com/brown9804/DevOps-Agile-Cloud_path/tree/main/Cloud/1-terraform/lab_20)
55-
56-
- [Automation Principles](https://github.com/brown9804/SDLC-Cloud_Lpath/tree/main/Cloud/2-automation_principles)
57-
- [Kubernetes Principles](https://github.com/brown9804/SDLC-Cloud_Lpath/tree/main/Cloud/3-kubernetes_principles)
58-
59-
</details>
60-
61-
## Overview
62-
63-
- SDLC - [What is and how it works](https://agilie.com/blog/what-is-the-software-development-life-cycle-sdlc-and-how-does-it-work)
64-
65-
![image](https://github.com/brown9804/SDLC-Cloud_Lpath/assets/24630902/e809d790-87d4-41a1-b9ea-071327ab6ef2)
66-
67-
![Benefits](https://github.com/brown9804/SDLC-Cloud_Lpath/assets/24630902/dc014629-a069-44f3-b657-7f8d39968272)
68-
69-
![image](https://github.com/brown9804/SDLC-Cloud_Lpath/assets/24630902/a3b6522f-88c2-4ede-a477-09280f5584b9)
70-
71-
- SDLC - [Methodologies](https://datarob.com/sdlc-methodologies/)
72-
73-
![image](https://github.com/brown9804/SDLC-Cloud_Lpath/assets/24630902/5ba714af-4238-48d3-9043-cbcd64a590f1)
74-
75-
13+
> This repository provides a customizable GitHub visitor counter that tracks and displays the number of visits to your GitHub profile or repository. The counter updates daily using the GitHub Traffic API and writes the total views directly into the README file.
14+
15+
## Features
16+
17+
- **Daily-updated visitor counting**: Fetches real visitor data from the GitHub Traffic API.
18+
- **Markdown-based display**: Updates the README file with the total visitor count.
19+
- **Open source and customizable**.
20+
21+
## How it works
22+
23+
> [!IMPORTANT]
24+
> This counter is updated once per day (not real-time) and shows the total number of visits (including repeat visits) as reported by GitHub.
25+
26+
- A GitHub Action workflow runs daily to fetch visitor data from the GitHub Traffic API.
27+
- The action updates the `README.md` file with the total visitor count and the refresh timestamp.
28+
29+
## How to use it
30+
31+
1. **Add the Badge to Your Repository**: Include the following markdown in your `README.md` file, between the `START BADGE` and `END BADGE` (included), as shown in the bottom.
32+
2. **Create a Personal Access Token**:
33+
- Go to **GitHub Settings** > **Developer Settings** > **Personal Access Tokens**.
34+
- Generate a new token with `repo` access.
35+
3. **Save the Token as a Secret**:
36+
- In your repository, navigate to **Settings** > **Secrets and Variables** > **Actions**.
37+
- Add a new secret named `TRAFFIC_TOKEN` and paste the generated token.
38+
4. **Add the Pipeline**: This single pipeline will fetch the visitor count, update the badge in the `README.md` file, and push the changes back to the repository.
39+
- Create a GitHub Actions workflow (`update-metrics.yml`) in your repository to handle the visitor counter logic.
40+
- Use the following content for the workflow:
41+
42+
```yaml
43+
name: Update Visitor Counter
44+
45+
on:
46+
schedule:
47+
- cron: '0 0 * * *' # Runs daily at midnight
48+
workflow_dispatch: # Allows manual triggering
49+
50+
jobs:
51+
update-counter:
52+
runs-on: ubuntu-latest
53+
54+
steps:
55+
- name: Checkout repository
56+
uses: actions/checkout@v3
57+
58+
- name: Set up Node.js
59+
uses: actions/setup-node@v3
60+
with:
61+
node-version: '16'
62+
63+
- name: Install dependencies
64+
run: npm install @brown9804/github-visitor-counter
65+
66+
- name: Run visitor counter script
67+
run: node node_modules/@brown9804/github-visitor-counter/update_repo_views_counter.js
68+
env:
69+
TRAFFIC_TOKEN: ${{ secrets.TRAFFIC_TOKEN }}
70+
REPO: ${{ github.repository }}
71+
72+
- name: Commit and push changes
73+
run: |
74+
git config --global user.name "github-actions[bot]"
75+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
76+
git add README.md metrics.json
77+
git commit -m "Update visitor count"
78+
git push
79+
```
80+
81+
## Files structure
82+
83+
- `README.md`: Contains instructions and displays the visitor count badge.
84+
- `update_repo_views_counter.js`: Script to fetch visitor count data from the GitHub Traffic API and update the `README.md` file.
85+
- `package.json`: Defines dependencies and scripts for the project.
86+
- `LICENSE`: Specifies the license for the project.
87+
88+
> [!IMPORTANT]
89+
>
90+
> - Replace `<main-repo-owner>` and `<main-repo-name>` with your actual values.
91+
> - Use a Personal Access Token (PAT) with `repo` access as `TRAFFIC_TOKEN` secret in each target repository.
92+
> - The action will trigger the visitor counter logic in the main repository and update the badge dynamically.
93+
94+
<!-- START BADGE -->
7695
<div align="center">
77-
<h3 style="color: #4CAF50;">Total Visitors</h3>
78-
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
96+
<img src="https://img.shields.io/badge/Total%20views-195-limegreen" alt="Total views">
97+
<p>Refresh Date: 2025-07-10</p>
7998
</div>
99+
<!-- END BADGE -->

0 commit comments

Comments
 (0)