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

changes for readme at root of repo with tree structure #11

Merged
merged 1 commit into from
Sep 21, 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
32 changes: 32 additions & 0 deletions .github/workflows/create-root-readme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: create-root-readme

on:
workflow_run:
workflows: ["generate-terraform-docs"] # Runs after completion of generate-terraform-docs workflow
types:
- completed

jobs:
create-root-readme:

runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}

steps:
- name: Check out the repository
uses: actions/checkout@v4

- name: Ensure tree command is installed
run: sudo apt update && apt-get install -y tree

- name: Run the tree generation script
run: |
bash create-readme.sh

- name: Commit and Push Changes
run: |
git config user.name 'github-actions'
git config user.email 'actions@github.com'
git add .
git commit -m "Update documentation"
git push
54 changes: 54 additions & 0 deletions create-readme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

#!/bin/bash

# Ensure the 'tree' command is installed
if ! command -v tree &> /dev/null; then
echo "'tree' command not found. Please install it to use this script."
exit 1
fi

# Define the output file (README.md in the root directory)
readme_file="README.md"

# Define the default content you want to keep at the top of the README.md
default_content=$(cat << EOF
# Azure Terraform Modules

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.

## Report an Issue

If you encounter any issues, please report them on the [Issues page](https://github.com/devwithkrishna/azure-terraform-modules/issues/new).

EOF
)

# Remove the old directory structure, if it exists
# It assumes the old structure starts from '# Available Modules' until the end of the file
sed -i '/# Available Modules/,$d' "$readme_file"

# Write the default content back to the README.md
echo "$default_content" > "$readme_file"

# List module names based on subdirectories
MODULES_SECTION="## Available Modules\n\n"
for dir in */; do
module_name=$(basename "$dir")
MODULES_SECTION+="* **${module_name}**: Located in \`${dir}\`\n"
done

# Append the modules section to the README.md
echo -e "$MODULES_SECTION" >> "$readme_file"

# Start a Markdown code block for the directory structure
echo '## Project Directory Structure' >> "$readme_file"
echo '```' >> "$readme_file"

# Generate the directory structure and append to README.md, ignoring certain files
tree -I 'LICENSE|create-readme.sh|.github|.git' --charset utf-8 >> "$readme_file"

# End the Markdown code block
echo '```' >> "$readme_file"

# Print success message
echo "README.md has been successfully updated with the directory structure and issue reporting section."
Loading