Skip to content

Commit 083ab52

Browse files
changes for readme at root of repo with tree structure (#11)
1 parent 0d765b0 commit 083ab52

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: create-root-readme
2+
3+
on:
4+
workflow_run:
5+
workflows: ["generate-terraform-docs"] # Runs after completion of generate-terraform-docs workflow
6+
types:
7+
- completed
8+
9+
jobs:
10+
create-root-readme:
11+
12+
runs-on: ubuntu-latest
13+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
14+
15+
steps:
16+
- name: Check out the repository
17+
uses: actions/checkout@v4
18+
19+
- name: Ensure tree command is installed
20+
run: sudo apt update && apt-get install -y tree
21+
22+
- name: Run the tree generation script
23+
run: |
24+
bash create-readme.sh
25+
26+
- name: Commit and Push Changes
27+
run: |
28+
git config user.name 'github-actions'
29+
git config user.email '[email protected]'
30+
git add .
31+
git commit -m "Update documentation"
32+
git push

create-readme.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
#!/bin/bash
3+
4+
# Ensure the 'tree' command is installed
5+
if ! command -v tree &> /dev/null; then
6+
echo "'tree' command not found. Please install it to use this script."
7+
exit 1
8+
fi
9+
10+
# Define the output file (README.md in the root directory)
11+
readme_file="README.md"
12+
13+
# Define the default content you want to keep at the top of the README.md
14+
default_content=$(cat << EOF
15+
# Azure Terraform Modules
16+
17+
This repository contains Terraform modules designed to help manage and automate the provisioning of Azure cloud resources. Each module is crafted to follow best practices and make it easier to create, configure, and manage specific Azure services in a reusable manner.
18+
19+
## Report an Issue
20+
21+
If you encounter any issues, please report them on the [Issues page](https://github.com/devwithkrishna/azure-terraform-modules/issues/new).
22+
23+
EOF
24+
)
25+
26+
# Remove the old directory structure, if it exists
27+
# It assumes the old structure starts from '# Available Modules' until the end of the file
28+
sed -i '/# Available Modules/,$d' "$readme_file"
29+
30+
# Write the default content back to the README.md
31+
echo "$default_content" > "$readme_file"
32+
33+
# List module names based on subdirectories
34+
MODULES_SECTION="## Available Modules\n\n"
35+
for dir in */; do
36+
module_name=$(basename "$dir")
37+
MODULES_SECTION+="* **${module_name}**: Located in \`${dir}\`\n"
38+
done
39+
40+
# Append the modules section to the README.md
41+
echo -e "$MODULES_SECTION" >> "$readme_file"
42+
43+
# Start a Markdown code block for the directory structure
44+
echo '## Project Directory Structure' >> "$readme_file"
45+
echo '```' >> "$readme_file"
46+
47+
# Generate the directory structure and append to README.md, ignoring certain files
48+
tree -I 'LICENSE|create-readme.sh|.github|.git' --charset utf-8 >> "$readme_file"
49+
50+
# End the Markdown code block
51+
echo '```' >> "$readme_file"
52+
53+
# Print success message
54+
echo "README.md has been successfully updated with the directory structure and issue reporting section."

0 commit comments

Comments
 (0)