Skip to content

Generate Template

Generate Template #15

name: Generate Template
permissions:
contents: write
pull-requests: write
on:
workflow_dispatch:
jobs:
generate-template:
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
persist-credentials: true
fetch-depth: '0'
- name: Prepare branch for generated template
id: prepare_branch
run: |
BRANCH="generated-template-$(date -u +%Y%m%d%H%M%S)"
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
- name: Make script executable
run: chmod +x ./generate-cookiecutter-template-from-example-project.sh
- name: Generate cookiecutter template
run: ./generate-cookiecutter-template-from-example-project.sh
- name: Copy generated template to {{cookiecutter.app_name}}
run: |
rsync -a --delete --exclude='.git' ./example-template/ ./{{cookiecutter.app_name}}/
# Use EndBug's add-and-commit Action instead of manual git commands
- name: Commit changes
id: commit
uses: EndBug/add-and-commit@v9
with:
message: "ci: update generated cookiecutter template from example"
add: "."
push: true
author_name: GitHub Actions Bot
author_email: github-actions[bot]@users.noreply.github.com
default_author: github_actions
cwd: "."
new_branch: ${{ steps.prepare_branch.outputs.branch }}
# Verify commit exists on GitHub
- name: Verify commit exists on GitHub
if: steps.commit.outputs.committed == 'true'
env:
BRANCH_NAME: ${{ steps.prepare_branch.outputs.branch }}
run: |
echo "Step outputs from commit action:"
echo "Commit SHA: ${{ steps.commit.outputs.commit_long_sha }}"
echo "Waiting 5 seconds for GitHub to process commit..."
sleep 5
git fetch origin ${BRANCH_NAME}
REMOTE_SHA=$(git rev-parse "origin/${BRANCH_NAME}")
echo "Remote HEAD: $REMOTE_SHA"
if [[ "$REMOTE_SHA" == "${{ steps.commit.outputs.commit_long_sha }}" ]]; then
echo "✅ Verified: Commit is on GitHub"
else
echo "⚠️ Warning: Commit verification failed, but continuing..."
# Don't fail the workflow if verification fails,
# the commit might still be processing on GitHub's side
fi
- name: Create Pull Request
if: steps.commit.outputs.committed == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: main
branch: ${{ steps.prepare_branch.outputs.branch }}
title: "ci: update generated cookiecutter template from example"
body: |
This PR was created automatically by the Generate Template workflow.
Contains updates generated from the example project.
labels: automated-pr
delete-branch: false