Skip to content

Website Template Automation #12

Website Template Automation

Website Template Automation #12

Workflow file for this run

name: Website Template Automation
on:
workflow_dispatch:
inputs:
git-url:
description: 'GitHub Repository URL to clone'
required: true
type: string
default: 'https://github.com/learning-zone/website-templates.git'
run-tests:
description: 'Run tests after modification'
required: false
type: boolean
default: false
jobs:
modify-templates:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout main repository
uses: actions/checkout@v4
with:
fetch-depth: 1
path: main-repo
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
working-directory: main-repo
run: |
python -m pip install --upgrade pip
pip install gitpython beautifulsoup4
- name: Clone templates repository into a folder
id: clone-repo
run: |
REPO_URL="${{ inputs.git-url }}"
# Clone the repository into a folder (e.g., templates-repo)
git clone --depth 1 "$REPO_URL" templates-repo
if [ $? -ne 0 ]; then
echo "::error::Failed to clone repository: $REPO_URL"
exit 1
fi
- name: Copy specific files from the templates folder to the root
run: |
# Copy index.html, .md files, and .github workflows to the root
cp templates-repo/index.html main-repo/ || echo "index.html not found"
cp templates-repo/*.md main-repo/ || echo "Markdown files not found"
cp -r templates-repo/.github main-repo/ || echo "GitHub workflows not found"
- name: Check for changes in the repository
id: git-check
working-directory: main-repo
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Stage changes
if: steps.git-check.outputs.changes == 'true'
working-directory: main-repo
run: |
git add -A
git status
- name: Commit and push changes
if: steps.git-check.outputs.changes == 'true'
working-directory: main-repo
run: |
git config --global user.name "Rekt-Developer"
git config --global user.email "[email protected]"
git commit -m "feat: Add advertisement placeholders to templates
- Added responsive ad containers
- Automated via GitHub Actions"
git push origin ${{ github.ref_name }}
if [ $? -ne 0 ]; then
echo "::error::Failed to push changes to repository"
exit 1
fi
- name: Create status report
if: always()
run: |
{
echo "### Template Modification Report"
echo "- Repository: ${{ inputs.git-url }}"
echo "- Run Date: $(date -u +'%Y-%m-%d %H:%M:%S UTC')"
echo "- Changes Made: ${{ steps.git-check.outputs.changes == 'true' && 'Yes' || 'No' }}"
if [[ "${{ steps.git-check.outputs.changes }}" == "true" ]]; then
echo "- Modified Files:"
git diff --name-only HEAD~1 HEAD | sed 's/^/ - /'
fi
} >> $GITHUB_STEP_SUMMARY