Skip to content

Commit

Permalink
automate automation readme
Browse files Browse the repository at this point in the history
  • Loading branch information
asucrews authored Jul 5, 2024
1 parent a2c4de6 commit d7d960e
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/generate_automation_readme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Update README

on:
schedule:
- cron: '0 0 * * *' # This runs every day at midnight
workflow_dispatch: # Allows manual triggering

jobs:
update-readme:
runs-on: ubuntu-latest

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

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: pip install pyyaml

- name: Run script
run: python scripts/generate_automation_readme.py

- name: Check for changes
id: changes
run: |
git diff --quiet
echo "changes=$?" >> $GITHUB_ENV
- name: Commit and push changes
if: env.changes != 0
env:
GIT_AUTHOR_EMAIL: [email protected]
GIT_AUTHOR_NAME: GitHub Action
GIT_COMMITTER_EMAIL: [email protected]
GIT_COMMITTER_NAME: GitHub Action
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
git add automations/README.md
git commit -m "Update Automation Readme"
git push
49 changes: 49 additions & 0 deletions scripts/generate_automation_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os

def generate_readme():
base_url = "https://github.com/asucrews/ha-blueprints/blob/main/automations/"
import_base_url = "https://my.home-assistant.io/redirect/blueprint_import/?blueprint_url="
readme_content = """# Home Assistant Blueprints
Welcome to the **Home Assistant Blueprints** repository! This collection of automation blueprints is created by **asucrews** to help you set up automations for various Home Assistant setups. Each blueprint is designed to simplify and enhance your Home Assistant experience.
## Available Blueprints
"""

for root, dirs, files in os.walk("automations"):
# Skip 'dev' folders
if 'dev' in root.split(os.sep):
continue
for file in files:
if file.endswith(".yaml"):
blueprint_path = os.path.join(root, file)
blueprint_name = os.path.splitext(file)[0].replace('_', ' ').title()
blueprint_url = base_url + blueprint_path.replace("\\", "/")
import_url = import_base_url + blueprint_url

readme_content += f"""
### [{blueprint_name}]({blueprint_url})
[![Import Blueprint](https://my.home-assistant.io/badges/blueprint_import.svg)]({import_url})
Description for {blueprint_name} blueprint.
---
"""

readme_content += """
## Usage
1. **Select a Blueprint:** Browse the list of available blueprints and select the one that matches your needs.
2. **Copy the YAML:** Click on the blueprint link to view the YAML file. Copy the YAML content.
3. **Import into Home Assistant:** In Home Assistant, navigate to `Configuration > Blueprints` and click on "Import Blueprint". Paste the YAML content and save.
4. **Create Automation:** Use the imported blueprint to create a new automation and configure it as needed.
## Contributions
We welcome contributions to this repository! If you would like to add new blueprints or improve existing ones, please follow the guidelines provided in the [repository](https://github.com/asucrews/ha-blueprints).
"""

with open("automations/README.md", "w") as f:
f.write(readme_content)

if __name__ == "__main__":
generate_readme()

0 comments on commit d7d960e

Please sign in to comment.