Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOTICKET Add Project Tree Generator Workflow #358

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/generate_project_tree_structure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Generate Project Tree

on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch: # Allows manual triggering of the workflow

jobs:
generate_tree:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Make script executable
run: chmod +x ./project_tree_directory_util.sh

- name: Delete existing project_tree_structure.txt if it exists
run: |
if [ -f project_tree_structure.txt ]; then
rm project_tree_structure.txt
fi

- name: Generate project tree structure
run: ./project_tree_directory_util.sh > project_tree_structure.txt

- name: Update README with project tree
run: |
# Define the identifier comments
IDENTIFIER="<!-- PROJECT_TREE_START -->"
END_IDENTIFIER="<!-- PROJECT_TREE_END -->"

# Remove old project tree section
sed -i.bak "/$IDENTIFIER/,/$END_IDENTIFIER/d" README.md

# Add new project tree section back in the middle
awk -v identifier="$IDENTIFIER" -v end_identifier="$END_IDENTIFIER" '
{
print $0;
if ($0 ~ identifier) {
print "<summary><h2 align=\"center\">Project Tree Structure 📁</h2> </summary>";
print "```";
system("cat project_tree_structure.txt");
print "```";
}
}' README.md > temp.md && mv temp.md README.md

- name: Commit changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add README.md project_tree_structure.txt
git commit -m "Update project tree structure in README" || echo "No changes to commit"
git push
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@


<details close>
<!-- PROJECT_TREE_START -->
<summary><h2 align="center">Project Tree Structure 📁</h2> </summary>


```

Snippets
Expand Down Expand Up @@ -804,6 +804,7 @@ Snippets

```

<!-- PROJECT_TREE_END -->
</details>

</details>
Expand Down
26 changes: 26 additions & 0 deletions project_tree_directory_util.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Function to display the directory structure
display_tree() {
local dir="$1"
local prefix="$2"

# List all files and directories in the current directory
local files=("$dir"/*)

for file in "${files[@]}"; do
# Check if the item is a directory
if [ -d "$file" ]; then
echo "${prefix}├───$(basename "$file")"
# Call the function recursively for the subdirectory
display_tree "$file" "$prefix "
else
# Replace unexpected characters in the prefix line
echo "${prefix//│/| }$(basename "$file")"
fi
done
}

# Starting point for the tree structure
echo "Snippets"
display_tree "." "│ "
Loading
Loading