Skip to content

Website Template Automation #19

Website Template Automation

Website Template Automation #19

Workflow file for this run

name: Website Template Automation
on:
workflow_dispatch:
inputs:
git-url:
description: 'GitHub Repository URL to clone'
required: false
default: 'https://github.com/learning-zone/website-templates.git'
run-tests:
description: 'Run tests after modification'
required: false
type: boolean
default: true
jobs:
modify-templates:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository with submodules
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install gitpython beautifulsoup4 pytest
- name: Initialize and update submodules (if any)
run: |
if [ -f .gitmodules ]; then
git submodule update --init --recursive
else
echo ".gitmodules not found, skipping submodule initialization."
fi
git submodule sync || echo "No submodules to sync."
continue-on-error: true # Allow workflow to continue even if submodule update fails
- name: Run template modification
id: modify
run: |
echo "Starting template modification process..."
python clone_and_add_ads.py "${{ github.event.inputs.git-url }}"
- name: Run tests
if: inputs.run-tests == true
run: |
echo "Running tests..."
python -m pytest test_clone_and_add_ads.py -v
- name: Configure Git
run: |
git config --global user.name "Rekt-Developer"
git config --global user.email "[email protected]"
- name: Check for changes
id: git-check
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes
if: steps.git-check.outputs.changes == 'true'
run: |
git add -A
git commit -m "feat: Add advertisement placeholders to templates
- Added responsive ad containers
- Automated via GitHub Actions
- Timestamp: $(date -u +'%Y-%m-%d %H:%M:%S UTC')"
git push origin ${{ github.ref }}
- name: Clean up
if: always()
run: |
echo "Cleaning up temporary files..."
find . -type d -name "website-templates" -exec rm -rf {} +
find . -type d -name "__pycache__" -exec rm -rf {} +
- name: Create status report
if: always()
run: |
echo "### Template Modification Report" > $GITHUB_STEP_SUMMARY
echo "- Repository: ${{ github.event.inputs.git-url || 'Default templates repository' }}" >> $GITHUB_STEP_SUMMARY
echo "- Run Date: $(date -u +'%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
echo "- Changes Made: ${{ steps.git-check.outputs.changes == 'true' && 'Yes' || 'No' }}" >> $GITHUB_STEP_SUMMARY
if [[ "${{ steps.git-check.outputs.changes }}" == "true" ]]; then
echo "- Modified Files:" >> $GITHUB_STEP_SUMMARY
git diff --name-only HEAD~1 HEAD | sed 's/^/ - /' >> $GITHUB_STEP_SUMMARY
fi