11name : Generate Template
2+
3+ on :
4+ workflow_dispatch :
5+
26permissions :
37 contents : write
48 pull-requests : write
5- on :
6- workflow_dispatch :
9+
710jobs :
811 generate-template :
912 runs-on : ubuntu-latest
13+
1014 steps :
1115 - name : Checkout main branch
1216 uses : actions/checkout@v4
1317 with :
1418 ref : main
1519 token : ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
1620 persist-credentials : true
17- fetch-depth : ' 0 '
21+ fetch-depth : 0
1822
19- - name : Prepare branch for generated template
23+ - name : Prepare or reuse generated- template branch
2024 id : prepare_branch
2125 run : |
2226 BRANCH="generated-template"
23- echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
2427 git fetch origin
28+ git config user.email "github-actions[bot]@users.noreply.github.com"
29+ git config user.name "github-actions[bot]"
30+
2531 if git show-ref --verify --quiet refs/remotes/origin/$BRANCH; then
32+ echo "Branch exists — checking out and pulling latest"
2633 git checkout $BRANCH
2734 git pull origin $BRANCH
2835 else
36+ echo "Branch does not exist — creating new one"
2937 git checkout -b $BRANCH
38+ git push --set-upstream origin $BRANCH
3039 fi
40+ echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
3141
3242 - name : Make script executable
3343 run : chmod +x ./generate-cookiecutter-template-from-example-project.sh
@@ -39,44 +49,21 @@ jobs:
3949 run : |
4050 rsync -a --delete --exclude='.git' ./example-template/ ./{{cookiecutter.app_name}}/
4151
42- # Use EndBug's add-and-commit Action instead of manual git commands
4352 - name : Commit changes
4453 id : commit
45- uses : EndBug/add-and-commit@v9
46- with :
47- message : " ci: update generated cookiecutter template from example"
48- add : " ."
49- push : true
50- author_name : GitHub Actions Bot
51- author_email : github-actions[bot]@users.noreply.github.com
52- default_author : github_actions
53- cwd : " ."
54-
55- # Verify commit exists on GitHub
56- - name : Verify commit exists on GitHub
57- if : steps.commit.outputs.committed == 'true'
58- env :
59- BRANCH_NAME : ${{ steps.prepare_branch.outputs.branch }}
6054 run : |
61- echo "Step outputs from commit action:"
62- echo "Commit SHA: ${{ steps.commit.outputs.commit_long_sha }}"
63- echo "Waiting 5 seconds for GitHub to process commit..."
64- sleep 5
65-
66- git fetch origin ${BRANCH_NAME}
67- REMOTE_SHA=$(git rev-parse "origin/${BRANCH_NAME}")
68- echo "Remote HEAD: $REMOTE_SHA"
69-
70- if [[ "$REMOTE_SHA" == "${{ steps.commit.outputs.commit_long_sha }}" ]]; then
71- echo "✅ Verified: Commit is on GitHub"
55+ git add .
56+ if git diff --cached --quiet; then
57+ echo "no_changes=true" >> $GITHUB_OUTPUT
58+ echo "✅ No changes detected."
7259 else
73- echo "⚠️ Warning: Commit verification failed, but continuing... "
74- # Don't fail the workflow if verification fails,
75- # the commit might still be processing on GitHub's side
60+ git commit -m "ci: update generated cookiecutter template from example "
61+ git push origin generated-template
62+ echo "no_changes=false" >> $GITHUB_OUTPUT
7663 fi
7764
78- - name : Create Pull Request
79- if : steps.commit.outputs.committed == 'true '
65+ - name : Create or Update Pull Request
66+ if : steps.commit.outputs.no_changes == 'false '
8067 uses : peter-evans/create-pull-request@v7
8168 with :
8269 token : ${{ secrets.GITHUB_TOKEN }}
8572 title : " ci: update generated cookiecutter template from example"
8673 body : |
8774 This PR was created automatically by the Generate Template workflow.
88- Contains updates generated from the example project.
75+ It contains updates generated from the example project.
76+ commit-message : " ci: update generated cookiecutter template from example"
8977 labels : automated-pr
9078 delete-branch : false
0 commit comments