Skip to content

Commit 15c688b

Browse files
committed
feat: automate README updates with config file contents
1 parent c9b062c commit 15c688b

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Update README with Config Files
2+
3+
on:
4+
push:
5+
paths:
6+
- '.gitconfig.example'
7+
- '.gitconfig-github'
8+
- '.gitconfig-gitlab'
9+
- '.github/workflows/update-readme.yml'
10+
- 'scripts/update-readme.py'
11+
12+
jobs:
13+
update-readme:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Update README with config file contents
21+
run: python3 scripts/update-readme.py
22+
23+
- name: Commit changes
24+
run: |
25+
git config user.name "github-actions[bot]"
26+
git config user.email "github-actions[bot]@users.noreply.github.com"
27+
git add README.md
28+
git diff --quiet && git diff --staged --quiet || (git commit -m "docs: update README with config file contents" && git push)

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ You'll need the following configuration files. Replace all `PLACE_HOLDER` values
1616

1717
## `.gitconfig` (Global Git Configuration)
1818

19+
<!-- GITCONFIG_EXAMPLE_START -->
20+
1921
```ini
2022
# ====================================================================
2123
# Global Git Configuration (Usually ~/.gitconfig)
@@ -46,8 +48,12 @@ You'll need the following configuration files. Replace all `PLACE_HOLDER` values
4648
path = .gitconfig-gitlab
4749
```
4850

51+
<!-- GITCONFIG_EXAMPLE_END -->
52+
4953
## `.gitconfig-github` (GitHub-Specific Configuration)
5054

55+
<!-- GITCONFIG_GITHUB_START -->
56+
5157
```ini
5258
# ====================================================================
5359
# GitHub-specific Git configuration
@@ -62,8 +68,12 @@ You'll need the following configuration files. Replace all `PLACE_HOLDER` values
6268
email = YOUR_GITHUB_ID+USERNAME@users.noreply.github.com
6369
```
6470

71+
<!-- GITCONFIG_GITHUB_END -->
72+
6573
## `.gitconfig-gitlab` (GitLab-Specific Configuration)
6674

75+
<!-- GITCONFIG_GITLAB_START -->
76+
6777
```ini
6878
# ====================================================================
6979
# GitLab-specific Git configuration
@@ -78,6 +88,8 @@ You'll need the following configuration files. Replace all `PLACE_HOLDER` values
7888
email = YOUR_GITLAB_ID-USERNAME@users.noreply.gitlab.com
7989
```
8090

91+
<!-- GITCONFIG_GITLAB_END -->
92+
8193
# How to Verify
8294

8395
1. Clone a repository from GitHub/GitLab.

scripts/update-readme.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
"""Update README.md with content from config files."""
3+
4+
import re
5+
from pathlib import Path
6+
7+
CONFIG_FILES = {
8+
'GITCONFIG_EXAMPLE': '.gitconfig.example',
9+
'GITCONFIG_GITHUB': '.gitconfig-github',
10+
'GITCONFIG_GITLAB': '.gitconfig-gitlab',
11+
}
12+
13+
def update_readme():
14+
readme_path = Path('README.md')
15+
content = readme_path.read_text()
16+
17+
for marker, config_file in CONFIG_FILES.items():
18+
config_content = Path(config_file).read_text()
19+
20+
# Replace section between markers with config file content
21+
pattern = f'(<!-- {marker}_START -->)\n\n```ini\n.*?\n```\n\n(<!-- {marker}_END -->)'
22+
replacement = f'\\1\n\n```ini\n{config_content}```\n\n\\2'
23+
24+
content = re.sub(pattern, replacement, content, flags=re.DOTALL)
25+
26+
readme_path.write_text(content)
27+
28+
if __name__ == '__main__':
29+
update_readme()

0 commit comments

Comments
 (0)