diff --git a/.github/update_date.py b/.github/update_date.py new file mode 100644 index 0000000..ab86df5 --- /dev/null +++ b/.github/update_date.py @@ -0,0 +1,49 @@ +import os +import subprocess +from datetime import datetime, timezone + +# Get the list of modified files +result = subprocess.run(['git', 'diff', '--name-only', 'HEAD~1'], stdout=subprocess.PIPE) +modified_files = result.stdout.decode('utf-8').split() + +# Debugging: Print the list of modified files +print("Modified files:", modified_files) + +# Filter for Markdown files +modified_md_files = [f for f in modified_files if f.endswith('.md')] + +# Debugging: Print the list of modified Markdown files +print("Modified Markdown files:", modified_md_files) + +# Current date +current_date = datetime.now(timezone.utc).strftime('%Y-%m-%d') + +# Function to update the last modified date in a file +def update_date_in_file(file_path): + with open(file_path, 'r') as file: + lines = file.readlines() + + updated = False + with open(file_path, 'w') as file: + for line in lines: + if line.startswith('Last updated:'): + file.write(f'Last updated: {current_date}\n') + updated = True + else: + file.write(line) + if not updated: + file.write(f'\nLast updated: {current_date}\n') + +# Check if there are any modified Markdown files +if not modified_md_files: + print("No modified Markdown files found.") + exit(0) + +# Update the date in each modified Markdown file +for file_path in modified_md_files: + print(f"Updating file: {file_path}") # Debugging: Print the file being updated + update_date_in_file(file_path) + +# Add and commit changes +subprocess.run(['git', 'add', '-A']) +subprocess.run(['git', 'commit', '-m', 'Update last modified date in Markdown files']) diff --git a/.github/workflows/update-md-date.yml b/.github/workflows/update-md-date.yml new file mode 100644 index 0000000..5b2a19b --- /dev/null +++ b/.github/workflows/update-md-date.yml @@ -0,0 +1,48 @@ +name: Update Last Modified Date + +on: + pull_request: + branches: + - main + +permissions: + contents: write + pull-requests: write + +jobs: + update-date: + runs-on: ubuntu-latest + + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.ref }} + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Install dependencies + run: pip install python-dateutil + + - name: Configure Git + run: | + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + + - name: Update last modified date in Markdown files + run: python .github/workflows/update_date.py + + - name: Pull (merge) remote changes, commit, and push if needed + env: + TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + BRANCH="${{ github.event.pull_request.head.ref }}" + git pull origin "$BRANCH" || echo "No merge needed" + git add -A + git commit -m "Update last modified date in Markdown files" || echo "No changes to commit" + git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }} + git push origin HEAD:"$BRANCH" diff --git a/README.md b/README.md index 76c6f57..28284c3 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,16 @@ Costa Rica [![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/) [brown9804](https://github.com/brown9804) -Last updated: 2025-05-13 +Last updated: 2026-02-11 ---------- > 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. +> E.g + +image + ## What this is for - **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 ## How to update -### Update the profile text - -Edit `profile/README.md`. - -### Refresh the visitor counter badge / metrics - -- Run the workflow manually from GitHub: **Actions** → **Use Visitor Counter Logic** → **Run workflow**. -- Or let it run automatically on the configured cron schedule. - -## Secrets / permissions - -The workflow expects a repository secret named `TRAFFIC_TOKEN` so it can read repository traffic insights. - -## Notes +- Update the profile text. Edit `profile/README.md`. +- Refresh the visitor counter badge / metrics: + - Run the workflow manually from GitHub: **Actions** → **Use Visitor Counter Logic** → **Run workflow**. + - Or let it run automatically on the configured cron schedule. +- Secrets / permissions: The workflow expects a repository secret named `TRAFFIC_TOKEN` so it can read repository traffic insights. -- The workflow uses an external tool repo (`brown9804/github-visitor-counter`) to generate the badge and `metrics.json`. -- Manual edits to `metrics.json` are not recommended because the workflow will replace it on the next run. +> [!NOTE] +> - The workflow uses an external tool repo (`brown9804/github-visitor-counter`) to generate the badge and `metrics.json`. +> - Manual edits to `metrics.json` are not recommended because the workflow will replace it on the next run.