Generate Template #9
This file contains hidden or 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: 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 | |
| fetch-depth: 0 | |
| token: ${{ secrets.PAT_TOKEN || github.token }} | |
| - name: Create or checkout template branch | |
| id: prepare_branch | |
| run: | | |
| BRANCH="generated-template" | |
| echo "branch=${BRANCH}" >> $GITHUB_OUTPUT | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git config user.name "github-actions[bot]" | |
| if git ls-remote --heads origin ${BRANCH} | grep -q ${BRANCH}; then | |
| echo "Branch exists - checking out" | |
| git checkout ${BRANCH} | |
| git pull origin ${BRANCH} | |
| else | |
| echo "Creating branch" | |
| git checkout -b ${BRANCH} | |
| fi | |
| - 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 | |
| github_token: ${{ secrets.PAT_TOKEN || github.token }} | |
| 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' | |
| run: | | |
| echo "Commit SHA: ${{ steps.commit.outputs.commit_hash }}" | |
| echo "Waiting 5 seconds for GitHub to process commit..." | |
| sleep 5 | |
| git fetch origin ${{ steps.prepare_branch.outputs.branch }} | |
| REMOTE_SHA=$(git rev-parse "origin/${{ steps.prepare_branch.outputs.branch }}") | |
| echo "Remote HEAD: $REMOTE_SHA" | |
| if [[ "$REMOTE_SHA" == "${{ steps.commit.outputs.commit_hash }}" ]]; 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_push.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 |