|
| 1 | +# .github/workflows/update_readme.yml |
| 2 | +name: Update README Project Structure |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + pull_request: |
| 7 | + branches: [ master ] |
| 8 | +jobs: |
| 9 | + update-readme: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - uses: actions/checkout@v4 |
| 13 | + with: |
| 14 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 15 | + |
| 16 | + - name: Install tree |
| 17 | + run: sudo apt-get install tree |
| 18 | + |
| 19 | + - name: Generate project structure |
| 20 | + run: | |
| 21 | + # Generate tree structure excluding common ignore patterns |
| 22 | + tree -I 'node_modules|.git|.github|__pycache__|*.pyc|.env|.venv|dist|build|.DS_Store' | sed 's/^\./nvim/' > temp_structure.txt |
| 23 | + |
| 24 | + # Create the updated README section |
| 25 | + cat > temp_section.md << 'EOF' |
| 26 | + ### Project Structure |
| 27 | + ``` |
| 28 | + EOF |
| 29 | + |
| 30 | + cat temp_structure.txt >> temp_section.md |
| 31 | + |
| 32 | + cat >> temp_section.md << 'EOF' |
| 33 | + ``` |
| 34 | + EOF |
| 35 | + |
| 36 | + - name: Update README |
| 37 | + run: | |
| 38 | + # Check if README exists |
| 39 | + if [ ! -f README.md ]; then |
| 40 | + echo "README.md not found!" |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + |
| 44 | + # Replace the project structure section |
| 45 | + # This assumes you have markers in your README like: |
| 46 | + # <!-- PROJECT_STRUCTURE_START --> |
| 47 | + # <!-- PROJECT_STRUCTURE_END --> |
| 48 | + |
| 49 | + awk ' |
| 50 | + /<!-- PROJECT_STRUCTURE_START -->/ { |
| 51 | + print $0 |
| 52 | + while ((getline line < "temp_section.md") > 0) { |
| 53 | + print line |
| 54 | + } |
| 55 | + skip = 1 |
| 56 | + next |
| 57 | + } |
| 58 | + /<!-- PROJECT_STRUCTURE_END -->/ { |
| 59 | + skip = 0 |
| 60 | + print $0 |
| 61 | + next |
| 62 | + } |
| 63 | + !skip { print } |
| 64 | + ' README.md > README_new.md |
| 65 | + |
| 66 | + mv README_new.md README.md |
| 67 | + rm temp_structure.txt temp_section.md |
| 68 | + |
| 69 | + - name: Commit changes |
| 70 | + run: | |
| 71 | + git config --local user.email "action@github.com" |
| 72 | + git config --local user.name "GitHub Action" |
| 73 | + git add README.md |
| 74 | + if git diff --staged --quiet; then |
| 75 | + echo "No changes to commit" |
| 76 | + else |
| 77 | + git commit -m "Auto-update project structure in README" |
| 78 | + git push |
| 79 | + fi |
0 commit comments