-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (55 loc) · 2.25 KB
/
update_readme.yml
File metadata and controls
63 lines (55 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Update README File List
on:
push:
branches:
- main
paths:
- '**.php'
jobs:
update-readme:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Generate File List
id: file_list
run: |
echo "Generating file list..."
# Find all .php files, sort them, and format as Markdown links
# Format: - [Filename](URL)
FILES=$(find . -maxdepth 1 -name "*.php" -type f | sort | sed 's|^\./||' | while read -r file; do echo "- [📄 $file](https://github.com/${{ github.repository }}/blob/main/$file)"; done)
# Export to environment variable (multiline safe)
echo "FILES<<EOF" >> $GITHUB_ENV
echo "$FILES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Update README.md
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const readmePath = 'README.md';
const startMarker = '<!-- FILES_START -->';
const endMarker = '<!-- FILES_END -->';
if (fs.existsSync(readmePath)) {
let content = fs.readFileSync(readmePath, 'utf8');
const newContent = `${process.env.FILES}`;
const regex = new RegExp(`${startMarker}[\\s\\S]*?${endMarker}`);
if (regex.test(content)) {
const updatedContent = content.replace(regex, `${startMarker}\n${newContent}\n${endMarker}`);
fs.writeFileSync(readmePath, updatedContent);
console.log('README.md updated successfully.');
} else {
console.log('Markers not found in README.md');
}
} else {
console.log('README.md not found');
}
- name: Commit and Push changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
# Only commit if there are changes
git diff --quiet && git diff --staged --quiet || (git commit -m "docs: auto-update file list in README" && git push)