-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import re | ||
|
||
def read_file(filename): | ||
with open(filename, 'r', encoding='utf-8') as file: | ||
return file.read() | ||
|
||
def write_file(filename, content): | ||
with open(filename, 'w', encoding='utf-8') as file: | ||
file.write(content) | ||
|
||
def update_readme(directory_tree, readme_contents): | ||
# Define the start and end markers | ||
start_marker = "<!-- DIRECTORY_TREE_START -->" | ||
end_marker = "<!-- DIRECTORY_TREE_END -->" | ||
|
||
# Define the pattern to find the existing directory tree section | ||
pattern = re.compile(re.escape(start_marker) + ".*?" + re.escape(end_marker), re.DOTALL) | ||
|
||
# Define the replacement content, including the markers | ||
replacement = f"{start_marker}\n```\n{directory_tree}\n```\n{end_marker}" | ||
|
||
# Perform the replacement | ||
updated_contents = re.sub(pattern, replacement, readme_contents) | ||
|
||
return updated_contents | ||
|
||
directory_tree = read_file('DIRECTORY_TREE.txt') | ||
readme_contents = read_file('README.md') | ||
updated_readme = update_readme(directory_tree, readme_contents) | ||
write_file('README.md', updated_readme) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Update README with Directory Tree | ||
|
||
on: | ||
push: | ||
branches: | ||
- main # or your default branch | ||
|
||
jobs: | ||
update-readme: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
persist-credentials: false # avoids persisting GitHub credentials | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install tree command or alternative | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y tree | ||
- name: Generate Directory Tree | ||
run: | | ||
tree -I '.git|node_modules|other-directories-to-exclude' > DIRECTORY_TREE.txt | ||
- name: Update README.md | ||
run: python .github/scripts/update_readme.py | ||
|
||
- name: Commit changes | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "Cdaprod" | ||
git add README.md | ||
if git diff --staged --quiet; then | ||
echo "No changes to commit." | ||
else | ||
git commit -m "Automated README update: directory tree" | ||
fi | ||
- name: Push changes | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GH_TOKEN }} | ||
branch: ${{ github.ref }} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.env |
This file contains 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