Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ updates:
time: "23:30"
open-pull-requests-limit: 10
reviewers:
- paul58914080
- devs-from-matrix/app-generator-team
61 changes: 61 additions & 0 deletions .github/workflows/ci-from-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Continuous Integration From Template
on:
pull_request:
branches:
- main
paths:
- '{{cookiecutter.app_name}}/**'
workflow_dispatch:
jobs:
generate-from-template:
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
# checkout the pull request head ref when available, otherwise fallback to the workflow ref
ref: ${{ github.head_ref || github.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install cookiecutter
run: |
pip install --upgrade pip cookiecutter
- name: Generate from default context (cookiecutter.json)
run: |
# Generate using the config file test-config.yml from the repo root.
# Use the repo root as the template directory (.) and overwrite any existing generated output.
cookiecutter --no-input --config-file test-config.yml --overwrite-if-exists --output-dir . .
- name: Upload generated cart-service as artifact
uses: actions/upload-artifact@v4
with:
name: cart-service
path: ./cart-service
cart-service-ci:
needs: generate-from-template
defaults:
run:
working-directory: ./cart-service
runs-on: ubuntu-latest
Comment on lines +36 to +41

Copilot AI Oct 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The job name and working-directory are hard-coded to cart-service; if the generated app_name changes, the job will fail or become misleading. Use a workflow env var (e.g., GENERATED_DIR) for both the job's working-directory and artifact name/path to keep them aligned with test-config.yml.

Copilot uses AI. Check for mistakes.
steps:
- name: Download generated cart-service artifact
uses: actions/download-artifact@v4
with:
name: cart-service
Comment on lines +31 to +46

Copilot AI Oct 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] "cart-service" is hard-coded; if the app_name in test-config.yml changes, this step will break. Consider centralizing the generated directory name in a single workflow env var (kept in sync with test-config.yml) and reference it here to avoid drift.

Suggested change
- name: Upload generated cart-service as artifact
uses: actions/upload-artifact@v4
with:
name: cart-service
path: ./cart-service
cart-service-ci:
needs: generate-from-template
defaults:
run:
working-directory: ./cart-service
runs-on: ubuntu-latest
steps:
- name: Download generated cart-service artifact
uses: actions/download-artifact@v4
with:
name: cart-service
- name: Extract generated app name from test-config.yml
id: extract_app_name
run: |
echo "GENERATED_APP_NAME=$(python -c "import yaml; print(yaml.safe_load(open('test-config.yml'))['app_name'])")" >> $GITHUB_ENV
env:
PYTHONPATH: ""
- name: Upload generated app as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.GENERATED_APP_NAME }}
path: ./${{ env.GENERATED_APP_NAME }}
cart-service-ci:
needs: generate-from-template
defaults:
run:
working-directory: ./${{ env.GENERATED_APP_NAME }}
runs-on: ubuntu-latest
steps:
- name: Download generated cart-service artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.GENERATED_APP_NAME }}

Copilot uses AI. Check for mistakes.
path: .
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build with Maven
run: mvn clean verify -ntp
26 changes: 1 addition & 25 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,4 @@ jobs:
restore-keys: |
${{ runner.os }}-maven-
- name: Build with Maven
run: mvn clean install -ntp
- name: Clean up
run: mvn clean
generate-template:
needs: example-ci
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.PAT_TOKEN }}
- 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-tryout/ ./{{cookiecutter.app_name}}/
- name: Commit & push generated changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git diff --cached --quiet || git commit -m "ci: update generated cookiecutter template from example"
git push origin ${{ github.head_ref }}
run: mvn clean verify -ntp

Copilot AI Oct 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding -B to Maven commands in CI (non-interactive/batch mode): mvn -B clean verify -ntp. This is a common CI convention that also reduces noise from interactive prompts.

Suggested change
run: mvn clean verify -ntp
run: mvn -B clean verify -ntp

Copilot uses AI. Check for mistakes.
54 changes: 54 additions & 0 deletions .github/workflows/generate-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Generate Template
on:
workflow_dispatch:

Copilot AI Oct 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workflow pushes a branch and creates a PR using GITHUB_TOKEN but does not declare explicit permissions. Add a top-level permissions block (contents: write and pull-requests: write) to ensure the token has sufficient rights across all repo/org settings.

Suggested change
workflow_dispatch:
workflow_dispatch:
permissions:
contents: write
pull-requests: write

Copilot uses AI. Check for mistakes.
jobs:
generate-template:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- name: Create new branch
id: create_branch
run: |
# create unique branch name starting with "generated-template"

Copilot AI Oct 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment and implementation are inconsistent: the comment says the prefix is generated-template, but the code uses template-. Update the comment or the branch prefix for consistency.

Suggested change
# create unique branch name starting with "generated-template"
# create unique branch name starting with "template-"

Copilot uses AI. Check for mistakes.
BRANCH="template-$(date +%Y%m%d%H%M%S)"
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git checkout -b "${BRANCH}"
git push --set-upstream origin "${BRANCH}"
- name: Ensure working on created branch
run: |
git fetch origin
git checkout "${{ steps.create_branch.outputs.branch }}"
- 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.create_branch.outputs.branch }}
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git diff --cached --quiet || git commit -m "ci: update generated cookiecutter template from example"
git push origin "${BRANCH}"
- name: Create Pull Request
id: create_pr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: main
branch: ${{ steps.create_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
Comment on lines +43 to +54

Copilot AI Oct 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The create-pull-request action will not open a PR if there are no uncommitted changes at this step (you already committed and pushed earlier), so this step can silently do nothing. Replace this with a PR-creation step that opens a PR for an already-pushed branch (for example, actions/github-script calling pulls.create, or gh pr create), or let peter-evans/create-pull-request handle both committing and PR creation by removing the prior manual git commit/push.

Copilot uses AI. Check for mistakes.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*.iml

## Generated projects
# The generated project from scaffold-code-from-example.sh
example-tryout
# The generated project from generate-cookiecutter-template-from-example-project.sh
example-template
# The generated project from cookiecutter
cart-service

Expand Down
14 changes: 7 additions & 7 deletions generate-cookiecutter-template-from-example-project.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

Copilot AI Oct 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Add strict mode to improve robustness and fail fast on errors. For example, place set -euo pipefail immediately after the shebang.

Suggested change
#!/bin/bash
#!/bin/bash
set -euo pipefail

Copilot uses AI. Check for mistakes.
# This script is used to rename files and directories in the example project to that of the cookiecutter template.

# Remove previous example-tryout directory if it exists
if [ -d "example-tryout" ]; then
rm -rf "example-tryout"
# Remove previous example-template directory if it exists
if [ -d "example-template" ]; then
rm -rf "example-template"
fi
# Create a new example-tryout directory and copy the example project into it
mkdir "example-tryout"
rsync -a ./example/ ./example-tryout/
cd ./example-tryout
# Create a new example-template directory and copy the example project into it
mkdir "example-template"
rsync -a ./example/ ./example-template/
cd ./example-template

# sets the locale for all commands run in the current shell session to the "C" locale, which is the default POSIX locale. This makes programs like sed and find treat files as raw bytes, ignoring any character encoding issues. It helps avoid errors like illegal byte sequence when processing files with mixed or unknown encodings.
export LC_ALL=C
Expand Down