Generate Template #5
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 | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| generate-template: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout main | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Prepare branch | |
| id: prepare_branch | |
| run: | | |
| BRANCH="generated-template" | |
| git fetch origin | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git config user.name "github-actions[bot]" | |
| if git show-ref --verify --quiet refs/remotes/origin/$BRANCH; then | |
| echo "Branch $BRANCH exists — checking it out." | |
| git checkout $BRANCH | |
| git pull origin $BRANCH | |
| else | |
| echo "Branch $BRANCH does not exist — creating it." | |
| git checkout -b $BRANCH | |
| git push --set-upstream origin $BRANCH | |
| fi | |
| 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}}/ | |
| - name: Commit & push generated changes | |
| env: | |
| BRANCH: ${{ steps.prepare_branch.outputs.branch }} | |
| run: | | |
| git config --local user.name "github-actions[bot]" | |
| git add . | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit." | |
| else | |
| git commit -m "ci: update generated cookiecutter template from example" | |
| git push origin "${BRANCH}" | |
| fi | |
| - name: Create Pull Request | |
| 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: true |