Skip to content

Commit 00c2ea6

Browse files
authored
Merge pull request #1 from MicrosoftCloudEssentials-LearningHub/automations
rules for markdown
2 parents 0137512 + 6b1d7ab commit 00c2ea6

File tree

5 files changed

+198
-45
lines changed

5 files changed

+198
-45
lines changed

.github/.markdownlint.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"default": true,
3+
"MD005": false,
4+
"MD009": false,
5+
"MD013": false,
6+
"MD028": false,
7+
"MD029": false,
8+
"MD033": false,
9+
"MD048": false,
10+
"MD040": false,
11+
"MD041": false,
12+
"MD045": false,
13+
"MD046": false
14+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Update Last Modified Date
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
update-date:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.x'
25+
26+
- name: Install dependencies
27+
run: pip install python-dateutil
28+
29+
- name: Configure Git
30+
run: |
31+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
32+
git config --global user.name "github-actions[bot]"
33+
34+
- name: Update last modified date in Markdown files
35+
run: python .github/workflows/update_date.py
36+
37+
- name: Commit changes
38+
run: |
39+
git add -A
40+
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 }}

.github/workflows/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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Validate and Fix Markdown
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
validate-and-fix-markdown:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Node.js
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: '16'
25+
26+
- name: Install Markdown Linter
27+
run: npm install -g markdownlint-cli
28+
29+
- name: Lint and Fix Markdown files
30+
run: markdownlint '**/*.md' --fix --config .github/.markdownlint.json --ignore GPT-RAG_SolutionAccelerator/
31+
32+
- name: Configure Git
33+
run: |
34+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
35+
git config --global user.name "github-actions[bot]"
36+
37+
- name: Commit changes
38+
run: |
39+
git fetch origin
40+
git checkout -b ${{ github.event.pull_request.head.ref }} origin/${{ github.event.pull_request.head.ref }}
41+
git add -A
42+
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 }}

0 commit comments

Comments
 (0)