Done Changes #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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..." | |
| python3 << 'PY' | |
| import json, os | |
| paths = [] | |
| for root, dirs, files in os.walk("."): | |
| if ".git" in root.split(os.sep): | |
| continue | |
| for f in files: | |
| if f.endswith(".php"): | |
| rel = os.path.relpath(os.path.join(root, f), ".").replace("\\", "/") | |
| paths.append(rel) | |
| paths.sort() | |
| with open("files-manifest.json", "w", encoding="utf-8") as out: | |
| json.dump({"version": 1, "files": paths}, out, separators=(",", ":")) | |
| print("files-manifest.json:", len(paths), "PHP files") | |
| PY | |
| # Find all .php files, sort them, and format as Markdown links | |
| # Format: - [Filename](URL) | |
| FILES=$(find . -path './.git' -prune -o -name '*.php' -type f -print | 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 files-manifest.json | |
| # Only commit if there are changes | |
| git diff --quiet && git diff --staged --quiet || (git commit -m "docs: sync README and files-manifest for PHP portfolio" && git push) |