Website Template Automation #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
cache: 'pip' | |
- name: Initialize and update submodules (if any) | |
run: | | |
git submodule update --init --recursive || echo "No submodules to initialize." | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install gitpython beautifulsoup4 pytest | |
- 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 |