Skip to content

Commit c243c05

Browse files
authored
Merge pull request #9 from MicrosoftCloudEssentials-LearningHub/update-date
Update date
2 parents 93d86fc + d308147 commit c243c05

3 files changed

Lines changed: 110 additions & 17 deletions

File tree

.github/update_date.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
import subprocess
3+
from datetime import datetime, timezone
4+
5+
# Get the list of modified files
6+
result = subprocess.run(['git', 'diff', '--name-only', 'HEAD~1'], stdout=subprocess.PIPE)
7+
modified_files = result.stdout.decode('utf-8').split()
8+
9+
# Debugging: Print the list of modified files
10+
print("Modified files:", modified_files)
11+
12+
# Filter for Markdown files
13+
modified_md_files = [f for f in modified_files if f.endswith('.md')]
14+
15+
# Debugging: Print the list of modified Markdown files
16+
print("Modified Markdown files:", modified_md_files)
17+
18+
# Current date
19+
current_date = datetime.now(timezone.utc).strftime('%Y-%m-%d')
20+
21+
# Function to update the last modified date in a file
22+
def update_date_in_file(file_path):
23+
with open(file_path, 'r') as file:
24+
lines = file.readlines()
25+
26+
updated = False
27+
with open(file_path, 'w') as file:
28+
for line in lines:
29+
if line.startswith('Last updated:'):
30+
file.write(f'Last updated: {current_date}\n')
31+
updated = True
32+
else:
33+
file.write(line)
34+
if not updated:
35+
file.write(f'\nLast updated: {current_date}\n')
36+
37+
# Check if there are any modified Markdown files
38+
if not modified_md_files:
39+
print("No modified Markdown files found.")
40+
exit(0)
41+
42+
# Update the date in each modified Markdown file
43+
for file_path in modified_md_files:
44+
print(f"Updating file: {file_path}") # Debugging: Print the file being updated
45+
update_date_in_file(file_path)
46+
47+
# Add and commit changes
48+
subprocess.run(['git', 'add', '-A'])
49+
subprocess.run(['git', 'commit', '-m', 'Update last modified date in Markdown files'])
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Update Last Modified Date
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
update-date:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout PR branch
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
ref: ${{ github.event.pull_request.head.ref }}
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: '3.x'
27+
28+
- name: Install dependencies
29+
run: pip install python-dateutil
30+
31+
- name: Configure Git
32+
run: |
33+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
34+
git config --global user.name "github-actions[bot]"
35+
36+
- name: Update last modified date in Markdown files
37+
run: python .github/workflows/update_date.py
38+
39+
- name: Pull (merge) remote changes, commit, and push if needed
40+
env:
41+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
run: |
43+
BRANCH="${{ github.event.pull_request.head.ref }}"
44+
git pull origin "$BRANCH" || echo "No merge needed"
45+
git add -A
46+
git commit -m "Update last modified date in Markdown files" || echo "No changes to commit"
47+
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
48+
git push origin HEAD:"$BRANCH"

README.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ Costa Rica
55
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
66
[brown9804](https://github.com/brown9804)
77

8-
Last updated: 2025-05-13
8+
Last updated: 2026-02-11
99

1010
----------
1111

1212
> This repository holds the public **GitHub profile content** for *Microsoft Cloud Sandbox - Unofficial* and a small **GitHub Actions automation** that refreshes the visitor/view counter badge.
1313
14+
> E.g
15+
16+
<img width="903" height="599" alt="image" src="https://github.com/user-attachments/assets/8be272c2-d1f1-43c2-b4cf-a724e5233871" />
17+
1418
## What this is for
1519

1620
- **Profile hub**: the content in `profile/README.md` is intended to be displayed on the GitHub profile page (when this repository is the special `.github` repo for an organization).
@@ -27,23 +31,15 @@ Last updated: 2025-05-13
2731

2832
## How to update
2933

30-
### Update the profile text
31-
32-
Edit `profile/README.md`.
33-
34-
### Refresh the visitor counter badge / metrics
35-
36-
- Run the workflow manually from GitHub: **Actions****Use Visitor Counter Logic****Run workflow**.
37-
- Or let it run automatically on the configured cron schedule.
38-
39-
## Secrets / permissions
40-
41-
The workflow expects a repository secret named `TRAFFIC_TOKEN` so it can read repository traffic insights.
42-
43-
## Notes
34+
- Update the profile text. Edit `profile/README.md`.
35+
- Refresh the visitor counter badge / metrics:
36+
- Run the workflow manually from GitHub: **Actions****Use Visitor Counter Logic****Run workflow**.
37+
- Or let it run automatically on the configured cron schedule.
38+
- Secrets / permissions: The workflow expects a repository secret named `TRAFFIC_TOKEN` so it can read repository traffic insights.
4439

45-
- The workflow uses an external tool repo (`brown9804/github-visitor-counter`) to generate the badge and `metrics.json`.
46-
- Manual edits to `metrics.json` are not recommended because the workflow will replace it on the next run.
40+
> [!NOTE]
41+
> - The workflow uses an external tool repo (`brown9804/github-visitor-counter`) to generate the badge and `metrics.json`.
42+
> - Manual edits to `metrics.json` are not recommended because the workflow will replace it on the next run.
4743
4844
<!-- START BADGE -->
4945
<div align="center">

0 commit comments

Comments
 (0)